From 51d0615f113dd528970041855a1bfda3c23b620b Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Mon, 15 Jan 2024 15:21:29 +0800 Subject: [PATCH] Fix un-cleared VO bits for contiguous monotone PR Fixed a bug that when using a generational plan, if mutators allocated less than one chunk of memory into the nursery between GCs, some VO bits will not be cleared. This PR also ensures the field `MonotonePageResourceSync::current_chunk` grows monotonically during GC when the space is contiguous. --- src/policy/copyspace.rs | 17 ++--------------- src/util/heap/monotonepageresource.rs | 7 +++++++ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/policy/copyspace.rs b/src/policy/copyspace.rs index 8193c7c63c..82a4ee94a6 100644 --- a/src/policy/copyspace.rs +++ b/src/policy/copyspace.rs @@ -7,8 +7,6 @@ use crate::policy::space::{CommonSpace, Space}; use crate::scheduler::GCWorker; use crate::util::alloc::allocator::AllocatorContext; use crate::util::copy::*; -#[cfg(feature = "vo_bit")] -use crate::util::heap::layout::vm_layout::BYTES_IN_CHUNK; use crate::util::heap::{MonotonePageResource, PageResource}; use crate::util::metadata::{extract_side_metadata, MetadataSpec}; use crate::util::object_forwarding; @@ -189,19 +187,8 @@ impl CopySpace { #[cfg(feature = "vo_bit")] unsafe fn reset_vo_bit(&self) { - let current_chunk = self.pr.get_current_chunk(); - if self.common.contiguous { - // If we have allocated something into this space, we need to clear its VO bit. - if current_chunk != self.common.start { - crate::util::metadata::vo_bit::bzero_vo_bit( - self.common.start, - current_chunk + BYTES_IN_CHUNK - self.common.start, - ); - } - } else { - for (start, size) in self.pr.iterate_allocated_regions() { - crate::util::metadata::vo_bit::bzero_vo_bit(start, size); - } + for (start, size) in self.pr.iterate_allocated_regions() { + crate::util::metadata::vo_bit::bzero_vo_bit(start, size); } } diff --git a/src/util/heap/monotonepageresource.rs b/src/util/heap/monotonepageresource.rs index 04568e1bd6..b05cfbdcba 100644 --- a/src/util/heap/monotonepageresource.rs +++ b/src/util/heap/monotonepageresource.rs @@ -140,6 +140,12 @@ impl PageResource for MonotonePageResource { /* In a contiguous space we can bump along into the next chunk, so preserve the currentChunk invariant */ if self.common().contiguous && chunk_align_down(sync.cursor) != sync.current_chunk { + debug_assert!( + chunk_align_down(sync.cursor) > sync.current_chunk, + "Not monotonic. chunk_align_down(sync.cursor): {}, sync.current_chunk: {}", + chunk_align_down(sync.cursor), + sync.current_chunk, + ); sync.current_chunk = chunk_align_down(sync.cursor); } self.commit_pages(reserved_pages, required_pages, tls); @@ -310,6 +316,7 @@ impl MonotonePageResource { MonotonePageResourceConditional::Contiguous { start: _start, .. } => _start, _ => unreachable!(), }; + guard.current_chunk = guard.cursor; } else if !guard.cursor.is_zero() { let bytes = guard.cursor - guard.current_chunk; self.release_pages_extent(guard.current_chunk, bytes);