diff --git a/src/util/heap/monotonepageresource.rs b/src/util/heap/monotonepageresource.rs index d22e7fa8d8..39bb076b24 100644 --- a/src/util/heap/monotonepageresource.rs +++ b/src/util/heap/monotonepageresource.rs @@ -350,7 +350,13 @@ impl MonotonePageResource { } else { let start = self.discontiguous_start; self.discontiguous_start = self.pr.vm_map().get_next_contiguous_region(start); - let size = self.pr.vm_map().get_contiguous_region_size(start); + // If the current cursor is within the current discontiguous region (i.e. chunk), + // then return the size till the cursor + let size = if self.pr.cursor().chunk_index() == start.chunk_index() { + self.pr.cursor() - start + } else { + self.pr.vm_map().get_contiguous_region_size(start) + }; Some((start, size)) } }