-
Notifications
You must be signed in to change notification settings - Fork 76
Refactor bulk metadata visiting #1180
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
Conversation
It might interest you to see how Android implements this: https://cs.android.com/android/platform/superproject/main/+/main:art/runtime/gc/accounting/space_bitmap-inl.h;l=103-229?q=visitMarkedRange They have two functions |
Here are some benchmark results for bulk zeroing/setting a one-bit-per-word metadata (VO bit) for a 256-byte region (an Immix line). It can be obtained by executing
The result shows that
From the results, the bottleneck of setting/zeroing a small range of metadata is the preparation work, such as figuring out the bit range and byte ranges, and ensure the range is grain-aligned. The actual bit-zeroing and bit-setting is very cheap. Also because we often bit/set and bit/clear aligned ranges (such as Immix lines), it is important that such use cases are covered by fast paths because otherwise redundant checks will dominate. Normalizing is necessary because the input is byte address and in-byte offset obtained from |
If you would like to push further with this PR, you would need to show that the refactoring will result in improvement in favorable cases and will not slow down in other cases. Otherwise it is not worth to introduce the complexity. |
Since this is too complicated and doesn't perform well, I am closing this PR in favor for #1181 I'll continue to do refactoring when needed in the future, bit by bit. |
DRAFT:
This PR refactors the mechanism for visiting (reading and/or updating) side metadata in bulk. Comparing with the existing approach, the new approach
Using one callback allows an arbitrary
FnMut
callback (instead twoFn
s) to be used to visit things (such as valid object references via VO bits) in a metadata range. This also removes the use ofCell
when finding the last VO bit from an internal pointer.Now the side metadata can be visited at any granularity, such as
usize
. We no longer have to do it in two steps, from bits to bytes (iterate_meta_bits
) and from bytes to words (find_last_non_zero_bit_in_metadata_bytes
). Now anything smaller than a grain (ausize
for example) are treated as a "sub-grain range" and visited bit by bit (e.g. for each bit in ausize
...).(TODO) Make a generic mechanism to break a contiguous data address range into a single or multiple contiguous metadata ranges, so that concrete meta bit traversal mechanism can be expressed in several levels of nested
for
loops (or nested callbacks).