Skip to content

Commit 3831eae

Browse files
committed
Enqueue to BlockQueue backwards
Due to the LIFO nature of BlockQueue, if we enqueue multiple blocks into BlockQueue forwards, allocation fast paths will get blocks from BlockQueue in the opposite direction. This commit fixes this anomaly by enqueuing consecutive blocks backwards.
1 parent 8640ab8 commit 3831eae

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/util/heap/blockpageresource.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ impl<VM: VMBinding, B: Region> PageResource<VM> for BlockPageResource<VM, B> {
4949
required_pages: usize,
5050
tls: VMThread,
5151
) -> Result<PRAllocResult, PRAllocFail> {
52-
self.alloc_pages_fast(space_descriptor, reserved_pages, required_pages, tls)
52+
let result = self.alloc_pages_fast(space_descriptor, reserved_pages, required_pages, tls);
53+
if let Ok(ref r) = result {
54+
info!("alloc_pages: {}", r.start);
55+
} else {
56+
info!("alloc_pages: failed");
57+
}
58+
result
5359
}
5460

5561
fn get_available_physical_pages(&self) -> usize {
@@ -118,18 +124,16 @@ impl<VM: VMBinding, B: Region> BlockPageResource<VM, B> {
118124
// 2. Take the first block int the chunk as the allocation result
119125
let first_block = start;
120126
// 3. Push all remaining blocks to one or more block lists
121-
let last_block = start + BYTES_IN_CHUNK;
122127
let mut array = BlockQueue::new();
123-
let mut cursor = start + B::BYTES;
124-
while cursor < last_block {
128+
for offset in (B::BYTES..BYTES_IN_CHUNK).step_by(B::BYTES).rev() {
129+
let cursor = start + offset;
125130
let result = unsafe { array.push_relaxed(B::from_aligned_address(cursor)) };
126131
if let Err(block) = result {
127132
self.block_queue.add_global_array(array);
128133
array = BlockQueue::new();
129134
let result2 = unsafe { array.push_relaxed(block) };
130135
debug_assert!(result2.is_ok());
131136
}
132-
cursor += B::BYTES;
133137
}
134138
debug_assert!(!array.is_empty());
135139
// 4. Push the block list to the global pool

0 commit comments

Comments
 (0)