Skip to content

Commit 1dc6815

Browse files
authored
LOS: Reduce is_mapped calls during VO bit scan (#1341)
Like in `find_last_non_zero_bit_in_metadata_bytes`, we should only call `is_mapped` when we reached a new chunk because the granularity of `MapState` is per chunk.
1 parent 6ac4f73 commit 1dc6815

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/policy/largeobjectspace.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,26 @@ impl<VM: VMBinding> SFT for LargeObjectSpace<VM> {
105105
ptr: Address,
106106
max_search_bytes: usize,
107107
) -> Option<ObjectReference> {
108+
use crate::util::heap::vm_layout::MMAP_CHUNK_BYTES;
108109
use crate::util::metadata::vo_bit;
110+
111+
// We need to check if metadata address is mapped or not. But we only check at chunk granularity.
112+
// This records the start of a chunk that is tested to be mapped.
113+
let mut mapped_chunk = Address::MAX;
114+
109115
// For large object space, it is a bit special. We only need to check VO bit for each page.
110116
let mut cur_page = ptr.align_down(BYTES_IN_PAGE);
111117
let low_page = ptr
112118
.saturating_sub(max_search_bytes)
113119
.align_down(BYTES_IN_PAGE);
114120
while cur_page >= low_page {
115-
// If the page start is not mapped, there can't be an object in it.
116-
if !cur_page.is_mapped() {
117-
return None;
121+
if cur_page < mapped_chunk {
122+
if !cur_page.is_mapped() {
123+
// If the page start is not mapped, there can't be an object in it.
124+
return None;
125+
}
126+
// This is mapped. No need to check for this chunk.
127+
mapped_chunk = cur_page.align_down(MMAP_CHUNK_BYTES);
118128
}
119129
// For performance, we only check the first word which maps to the first 512 bytes in the page.
120130
// In almost all the cases, it should be sufficient.

0 commit comments

Comments
 (0)