Skip to content
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

Collect live bytes per space, and report by space #1238

Merged
merged 12 commits into from
Dec 3, 2024

Conversation

qinsoon
Copy link
Member

@qinsoon qinsoon commented Nov 25, 2024

The current count_live_bytes_in_gc feature adds the size of all live objects and compare with the used pages reported by the plan. There are two issues with the feature:

  1. VM space is not included in the used pages reported by the plan, but the live objects include objects in the VM space. So the reported fragmentation/utilization is wrong when the VM space is in use.
  2. Spaces/policies have very different fragmentation ratio. Reporting the fragmentation for the entire heap is not useful.

This PR refactors the current count_live_bytes_in_gc feature so we collect live bytes per space, and report by space.

@qinsoon qinsoon force-pushed the live-bytes-per-space branch from 70960d1 to 50fd82a Compare November 27, 2024 00:53
@qinsoon qinsoon force-pushed the live-bytes-per-space branch from 97f0768 to b38b80c Compare November 27, 2024 02:58
@qinsoon qinsoon marked this pull request as ready for review November 27, 2024 03:42
@qinsoon qinsoon requested a review from wks November 27, 2024 03:43
@wks
Copy link
Collaborator

wks commented Nov 27, 2024

Using space name as the key may be inefficient. Can we use SpaceDescriptor::get_index() to get an integer ordinal for the space, and use it to index a Vec<LiveBytesStats> (or [LiveBytesStats; MAX_SPACES]) instead?

In MMTK::aggregate_live_bytes_in_last_gc, we can get the SpaceDescriptor using space.common().descriptor.

In increase_live_bytes, we can use VMMap::get_descriptor_for_address to get the SpaceDescriptor. The SFT should work, too, but we need to add a new method for getting the descriptor, or getting a reference to CommonSpace from SFT.

@qinsoon
Copy link
Member Author

qinsoon commented Nov 27, 2024

Using space name as the key may be inefficient. Can we use SpaceDescriptor::get_index() to get an integer ordinal for the space, and use it to index a Vec<LiveBytesStats> (or [LiveBytesStats; MAX_SPACES]) instead?

Sounds good. I have made the change.

We might be able to use a runtime option for collecting live bytes data, and might be able to leave it enabled by default. I will run benchmarks first to know the overhead. Probably let's postpone the review for this PR until I get the benchmark results.

MAX_SPACES
);
// Accumulate the live bytes for the index
let mut array = self.live_bytes_per_space.borrow_mut();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AtomicRefCell.borrow_mut() has a cost. If this ends up being the bottleneck, we can do the borrowing in ScanObjectWork::do_work_common just before the for loop, and pass the &mut [...] to increase_live_bytes.

@qinsoon
Copy link
Member Author

qinsoon commented Dec 1, 2024

The following graph shows 3 runs: 1. count_live_bytes_in_gc as a feature and the feature is disabled, 2. count_live_bytes_in_gc as a runtime option and it is turned off, and 3. count_live_bytes_in_gc as a runtime option and it is turned on. The overhead from runtime option is little (0.7% GC time when it is turned off, and 1% GC time when it is turned on). So I made it as a runtime option.

livebytes

plotty

src/scheduler/worker.rs Outdated Show resolved Hide resolved
src/scheduler/worker.rs Outdated Show resolved Hide resolved
src/scheduler/scheduler.rs Outdated Show resolved Hide resolved
src/mmtk.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@wks wks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qinsoon qinsoon enabled auto-merge December 3, 2024 03:58
@qinsoon qinsoon added this pull request to the merge queue Dec 3, 2024
Merged via the queue into mmtk:master with commit 8a398e0 Dec 3, 2024
32 of 33 checks passed
@qinsoon qinsoon deleted the live-bytes-per-space branch December 3, 2024 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants