Skip to content

Commit ddc5517

Browse files
authored
Fix contiguous chunk iterator in monotonic PR (#1299)
Fixed a bug where the iterator defined in `MonotonicPageResource::iterate_allocated_regions` erronious thinks the cursor is within the current contiguous region, while the cursor is actually at the end of the previous chunk. This bug will cause side metadata (such as VO-bits) to be left over after releasing a CopySpace.
1 parent 4e06434 commit ddc5517

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/util/heap/monotonepageresource.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,18 @@ impl<VM: VMBinding> MonotonePageResource<VM> {
350350
} else {
351351
let start = self.discontiguous_start;
352352
self.discontiguous_start = self.pr.vm_map().get_next_contiguous_region(start);
353-
// If the current cursor is within the current discontiguous region (i.e. chunk),
354-
// then return the size till the cursor
355-
let size = if self.pr.cursor().chunk_index() == start.chunk_index() {
356-
self.pr.cursor() - start
353+
354+
let contiguous_region_size = self.pr.vm_map().get_contiguous_region_size(start);
355+
let cursor = self.pr.cursor();
356+
let size = if start < cursor && cursor < start + contiguous_region_size {
357+
// If the current cursor is within the current discontiguous region,
358+
// then return the size till the cursor.
359+
// This is sufficient for sweeping the memory and clearing side metadata.
360+
// Note that if cursor == start,
361+
// it means the cursor is at the end of the previous chunk.
362+
cursor - start
357363
} else {
358-
self.pr.vm_map().get_contiguous_region_size(start)
364+
contiguous_region_size
359365
};
360366
Some((start, size))
361367
}

0 commit comments

Comments
 (0)