-
Notifications
You must be signed in to change notification settings - Fork 79
Adding feature to query the fragmentation of immixspace #1089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
udesou
wants to merge
19
commits into
mmtk:master
Choose a base branch
from
udesou:feature/check-fragmentation-immixspace
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+295
−16
Draft
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c2a79ad
Adding feature to query the fragmentation of immixspace
udesou f081e4f
Removing duplicated method
udesou 530051b
Refactor range check
udesou ee21a9c
Moving stats from global state to immixspace
udesou bd3305f
Zeroing the live bytes right before GC starts
udesou 1f39198
Trying to count live blocks and live lines
udesou 06284e1
Adding feature to dump memory stats (from los and immixspace)
udesou 1547428
Print stats for sticky immix as well
udesou 184822c
Removing dependency on chrono
udesou f294948
Adding assertion for live lines in immixspace; properly counting live…
udesou 6f1c924
Change printing info
udesou aeb3aeb
Adding statistics about number of objects scanned and objects moved i…
udesou 4cfac97
Refactor code; turn on logs; set block size to 16K
udesou d56c3b9
Merge remote-tracking branch 'mmtk/master' into feature/check-fragmen…
udesou e787b2d
Merge branch 'master' into check-fragmentation-immixspace
qinsoon d5f993c
Check if objects are pinned in post_scan.
qinsoon 986ceb0
Merge branch 'master' into feature/check-fragmentation-immixspace
udesou cbbcfd8
Fix a few issues with measuring fragmentation: do count_live_bytes
qinsoon 7039d5d
Check if an object is in our heap before using VM map during counting
qinsoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,80 @@ use std::sync::{atomic::AtomicU8, atomic::AtomicUsize, Arc}; | |
pub(crate) const TRACE_KIND_FAST: TraceKind = 0; | ||
pub(crate) const TRACE_KIND_DEFRAG: TraceKind = 1; | ||
|
||
#[cfg(feature = "dump_memory_stats")] | ||
#[derive(Default)] | ||
/// Keeping track of the number of traced/copied/tpinned objects and live bytes | ||
struct ImmixSpaceStats { | ||
live_bytes: AtomicUsize, | ||
traced_objects: AtomicUsize, | ||
pinned_objects: AtomicUsize, | ||
tpinned_objects: AtomicUsize, | ||
copied_objects: AtomicUsize, | ||
} | ||
|
||
#[cfg(feature = "dump_memory_stats")] | ||
impl ImmixSpaceStats { | ||
pub fn get_live_bytes(&self) -> usize { | ||
self.live_bytes.load(Ordering::SeqCst) | ||
} | ||
|
||
pub fn set_live_bytes(&self, size: usize) { | ||
self.live_bytes.store(size, Ordering::SeqCst) | ||
} | ||
|
||
pub fn increase_live_bytes(&self, size: usize) { | ||
self.live_bytes.fetch_add(size, Ordering::SeqCst); | ||
} | ||
|
||
pub fn get_traced_objects(&self) -> usize { | ||
self.traced_objects.load(Ordering::SeqCst) | ||
} | ||
|
||
pub fn set_traced_objects(&self, size: usize) { | ||
self.traced_objects.store(size, Ordering::SeqCst) | ||
} | ||
|
||
pub fn increase_traced_objects(&self, size: usize) { | ||
self.traced_objects.fetch_add(size, Ordering::SeqCst); | ||
} | ||
|
||
pub fn get_copied_objects(&self) -> usize { | ||
self.copied_objects.load(Ordering::SeqCst) | ||
} | ||
|
||
pub fn set_copied_objects(&self, size: usize) { | ||
self.copied_objects.store(size, Ordering::SeqCst) | ||
} | ||
|
||
pub fn increase_copied_objects(&self, size: usize) { | ||
self.copied_objects.fetch_add(size, Ordering::SeqCst); | ||
} | ||
|
||
pub fn get_pinned_objects(&self) -> usize { | ||
self.pinned_objects.load(Ordering::SeqCst) | ||
} | ||
|
||
pub fn set_pinned_objects(&self, size: usize) { | ||
self.pinned_objects.store(size, Ordering::SeqCst) | ||
} | ||
|
||
pub fn increase_pinned_objects(&self, size: usize) { | ||
self.pinned_objects.fetch_add(size, Ordering::SeqCst); | ||
} | ||
|
||
pub fn get_tpinned_objects(&self) -> usize { | ||
self.tpinned_objects.load(Ordering::SeqCst) | ||
} | ||
|
||
pub fn set_tpinned_objects(&self, size: usize) { | ||
self.tpinned_objects.store(size, Ordering::SeqCst) | ||
} | ||
|
||
pub fn increase_tpinned_objects(&self, size: usize) { | ||
self.tpinned_objects.fetch_add(size, Ordering::SeqCst); | ||
} | ||
} | ||
|
||
pub struct ImmixSpace<VM: VMBinding> { | ||
common: CommonSpace<VM>, | ||
pr: BlockPageResource<VM, Block>, | ||
|
@@ -55,6 +129,9 @@ pub struct ImmixSpace<VM: VMBinding> { | |
scheduler: Arc<GCWorkScheduler<VM>>, | ||
/// Some settings for this space | ||
space_args: ImmixSpaceArgs, | ||
/// Keeping track of immix stats | ||
#[cfg(feature = "dump_memory_stats")] | ||
immix_stats: ImmixSpaceStats, | ||
} | ||
|
||
/// Some arguments for Immix Space. | ||
|
@@ -205,7 +282,7 @@ impl<VM: VMBinding> crate::policy::gc_work::PolicyTraceObject<VM> for ImmixSpace | |
worker: &mut GCWorker<VM>, | ||
) -> ObjectReference { | ||
if KIND == TRACE_KIND_TRANSITIVE_PIN { | ||
self.trace_object_without_moving(queue, object) | ||
self.trace_object_without_moving(queue, object, true) | ||
} else if KIND == TRACE_KIND_DEFRAG { | ||
if Block::containing(object).is_defrag_source() { | ||
debug_assert!(self.in_defrag()); | ||
|
@@ -222,10 +299,10 @@ impl<VM: VMBinding> crate::policy::gc_work::PolicyTraceObject<VM> for ImmixSpace | |
false, | ||
) | ||
} else { | ||
self.trace_object_without_moving(queue, object) | ||
self.trace_object_without_moving(queue, object, false) | ||
} | ||
} else if KIND == TRACE_KIND_FAST { | ||
self.trace_object_without_moving(queue, object) | ||
self.trace_object_without_moving(queue, object, false) | ||
} else { | ||
unreachable!() | ||
} | ||
|
@@ -236,6 +313,20 @@ impl<VM: VMBinding> crate::policy::gc_work::PolicyTraceObject<VM> for ImmixSpace | |
debug_assert!(self.in_space(object)); | ||
self.mark_lines(object); | ||
} | ||
|
||
// count the bytes for each object | ||
#[cfg(feature = "dump_memory_stats")] | ||
self.immix_stats | ||
.increase_live_bytes(VM::VMObjectModel::get_current_size(object)); | ||
|
||
// increase the number of objects scanned | ||
#[cfg(feature = "dump_memory_stats")] | ||
{ | ||
if self.is_pinned(object) { | ||
self.immix_stats.increase_pinned_objects(1); | ||
} | ||
self.immix_stats.increase_traced_objects(1); | ||
} | ||
} | ||
|
||
fn may_move_objects<const KIND: TraceKind>() -> bool { | ||
|
@@ -334,6 +425,8 @@ impl<VM: VMBinding> ImmixSpace<VM> { | |
mark_state: Self::MARKED_STATE, | ||
scheduler: scheduler.clone(), | ||
space_args, | ||
#[cfg(feature = "dump_memory_stats")] | ||
immix_stats: Default::default(), | ||
} | ||
} | ||
|
||
|
@@ -455,6 +548,15 @@ impl<VM: VMBinding> ImmixSpace<VM> { | |
self.scheduler.work_buckets[WorkBucketStage::ClearVOBits].bulk_add(work_packets); | ||
} | ||
} | ||
|
||
#[cfg(feature = "dump_memory_stats")] | ||
{ | ||
self.immix_stats.set_live_bytes(0); | ||
self.immix_stats.set_traced_objects(0); | ||
self.immix_stats.set_copied_objects(0); | ||
self.immix_stats.set_tpinned_objects(0); | ||
self.immix_stats.set_pinned_objects(0); | ||
} | ||
} | ||
|
||
/// Release for the immix space. | ||
|
@@ -489,6 +591,98 @@ impl<VM: VMBinding> ImmixSpace<VM> { | |
did_defrag | ||
} | ||
|
||
#[cfg(feature = "dump_memory_stats")] | ||
pub(crate) fn dump_memory_stats(&self) { | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
||
#[derive(Default)] | ||
struct Dist { | ||
live_blocks: usize, | ||
live_lines: usize, | ||
} | ||
let mut dist = Dist::default(); | ||
|
||
for chunk in self.chunk_map.all_chunks() { | ||
if !self.address_in_space(chunk.start()) { | ||
continue; | ||
} | ||
|
||
for block in chunk | ||
.iter_region::<Block>() | ||
.filter(|b| b.get_state() != BlockState::Unallocated) | ||
{ | ||
dist.live_blocks += 1; | ||
|
||
let line_mark_state = self.line_mark_state.load(Ordering::Acquire); | ||
let mut live_lines_in_table = 0; | ||
let mut live_lines_from_block_state = 0; | ||
|
||
for line in block.lines() { | ||
if line.is_marked(line_mark_state) { | ||
live_lines_in_table += 1; | ||
} | ||
} | ||
|
||
match block.get_state() { | ||
BlockState::Marked => { | ||
panic!("At this point the block should have been swept already"); | ||
} | ||
BlockState::Unmarked => { | ||
// Block is unmarked and cannot be reused (has no holes) | ||
dist.live_lines += Block::LINES; | ||
live_lines_from_block_state += Block::LINES; | ||
} | ||
BlockState::Reusable { unavailable_lines } => { | ||
dist.live_lines += unavailable_lines as usize; | ||
live_lines_from_block_state += unavailable_lines as usize; | ||
} | ||
BlockState::Unallocated => {} | ||
} | ||
|
||
assert_eq!(live_lines_in_table, live_lines_from_block_state); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I observed this assertion failed with left = 25 and right = 128. |
||
} | ||
} | ||
|
||
let start = SystemTime::now(); | ||
let since_the_epoch = start | ||
.duration_since(UNIX_EPOCH) | ||
.expect("Time went backwards"); | ||
|
||
println!("{:?} mmtk_immixspace", since_the_epoch.as_millis()); | ||
println!( | ||
"\t#Live objects = {}", | ||
self.immix_stats.get_traced_objects() | ||
); | ||
println!( | ||
"\t#Copied objects = {}", | ||
self.immix_stats.get_copied_objects() | ||
); | ||
println!( | ||
"\t#Pinned objects = {}", | ||
self.immix_stats.get_pinned_objects() | ||
); | ||
println!( | ||
"\t#Transitively pinned objects = {}", | ||
self.immix_stats.get_tpinned_objects() | ||
); | ||
println!("\tLive bytes = {}", self.immix_stats.get_live_bytes()); | ||
println!("\tReserved pages = {}", self.reserved_pages()); | ||
println!( | ||
"\tReserved pages (bytes) = {}", | ||
self.reserved_pages() << LOG_BYTES_IN_PAGE | ||
); | ||
println!("\tLive blocks = {}", dist.live_blocks); | ||
println!( | ||
"\tLive blocks (bytes) = {}", | ||
dist.live_blocks << Block::LOG_BYTES | ||
); | ||
println!("\tLive lines = {}", dist.live_lines); | ||
println!( | ||
"\tLive lines (bytes) = {}", | ||
dist.live_lines << Line::LOG_BYTES | ||
); | ||
} | ||
|
||
/// Generate chunk sweep tasks | ||
fn generate_sweep_tasks(&self) -> Vec<Box<dyn GCWork<VM>>> { | ||
self.defrag.mark_histograms.lock().clear(); | ||
|
@@ -565,6 +759,7 @@ impl<VM: VMBinding> ImmixSpace<VM> { | |
&self, | ||
queue: &mut impl ObjectQueue, | ||
object: ObjectReference, | ||
_is_tpinned: bool, | ||
) -> ObjectReference { | ||
#[cfg(feature = "vo_bit")] | ||
vo_bit::helper::on_trace_object::<VM>(object); | ||
|
@@ -585,6 +780,14 @@ impl<VM: VMBinding> ImmixSpace<VM> { | |
// Visit node | ||
queue.enqueue(object); | ||
self.unlog_object_if_needed(object); | ||
|
||
#[cfg(feature = "dump_memory_stats")] | ||
if _is_tpinned { | ||
// increase the number of objects being tpinned | ||
#[cfg(feature = "dump_memory_stats")] | ||
self.immix_stats.increase_tpinned_objects(1); | ||
} | ||
|
||
return object; | ||
} | ||
object | ||
|
@@ -665,6 +868,9 @@ impl<VM: VMBinding> ImmixSpace<VM> { | |
semantics, | ||
copy_context, | ||
|_new_object| { | ||
// increase the number of objects being moved | ||
#[cfg(feature = "dump_memory_stats")] | ||
self.immix_stats.increase_copied_objects(1); | ||
#[cfg(feature = "vo_bit")] | ||
vo_bit::helper::on_object_forwarded::<VM>(_new_object); | ||
}, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this number equivalent to linearly scan the line mark table and manually check the line mark bytes? Probably better to add an assertion to double check. Same as L506.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an assertion in the latest commit that compares the number of live lines by just iterating the lines in the block and checking the mark table with the number from the block state. Is that what you meant?