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

Mask and zero bits in metadata bytes for bulk zeroing #707

Merged
merged 2 commits into from
Dec 2, 2022

Conversation

qinsoon
Copy link
Member

@qinsoon qinsoon commented Dec 1, 2022

This PR fixes a bug in bzero_metadata() discussed in #643 (comment). When the data address range to be bulk zeroed cannot be mapped into whole bytes in the side metadata, the other bits in the bytes which should not be updated will get zeroed unexpectedly.

@qinsoon qinsoon added the PR-testing Run binding tests for the pull request (deprecated: use PR-extended-testing instead) label Dec 1, 2022
@qinsoon qinsoon marked this pull request as ready for review December 1, 2022 07:37
@qinsoon qinsoon requested a review from wks December 1, 2022 07:37
@qinsoon qinsoon mentioned this pull request Dec 1, 2022
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.

One major problem is that if the metadata is discontiguous, the current way may overwrite unrelated metadata between chunks.

let zero = |data_start: Address, data_end: Address| {
let meta_start = address_to_meta_address(self, data_start);
let meta_start_shift = meta_byte_lshift(self, data_start);
let meta_end = address_to_meta_address(self, data_end);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is OK if the metadata is contiguous. But if it is discontiguous, then meta_start and meta_end may be in two unrelated chunks.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed zero to zero_contiguous which uses the same implementation as what you reviewed, and added zero_discontiguous which computes the total bits that need to be zeroed without computing the end address.

meta_start,
address_to_meta_address(self, second_data_chunk) - meta_start,
);
zero(start, second_data_chunk);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two problems:

  1. If start is already aligned to BYTES_IN_CHUNK, then start.align_up(BYTES_IN_CHUNK) will be equal to start, and it will end up calling zero(start, start).
  2. If the metadata is discontiguous, passing second_data_chunk to the zero function will result in meta_end being in a different metadata chunk, and unrelated metadata in between will be overwritten.

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. I added a check, if the size to be zeroed is 0, then the method simply returns.
  2. See my reply for the above comments.

address_to_meta_address(self, next_data_chunk),
metadata_bytes_per_chunk(self.log_bytes_in_region, self.log_num_of_bits),
);
zero(next_data_chunk, next_data_chunk + BYTES_IN_CHUNK);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same problem here. next_data_chunk + BYTES_IN_CHUNK will be mapped to the next metadata chunk.

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

Comment on lines +244 to +246
let meta_total_bits = (data_bytes >> self.log_bytes_in_region) << self.log_num_of_bits;
let meta_delta_bytes = meta_total_bits >> LOG_BITS_IN_BYTE;
let meta_delta_bits: u8 = (meta_total_bits % BITS_IN_BYTE) as u8;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nicely done. I think these lines of code are even clearer than those in address_to_contiguous_meta_address and meta_byte_lshift.

@qinsoon qinsoon merged commit ff3b450 into mmtk:master Dec 2, 2022
udesou pushed a commit to udesou/mmtk-core that referenced this pull request Dec 5, 2022
This PR fixes a bug in `bzero_metadata()` discussed in mmtk#643 (comment). When the data address range to be bulk zeroed cannot be mapped into whole bytes in the side metadata, the other bits in the bytes which should not be updated will get zeroed unexpectedly.
wenyuzhao pushed a commit to wenyuzhao/mmtk-core that referenced this pull request Mar 20, 2023
This PR fixes a bug in `bzero_metadata()` discussed in mmtk#643 (comment). When the data address range to be bulk zeroed cannot be mapped into whole bytes in the side metadata, the other bits in the bytes which should not be updated will get zeroed unexpectedly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-testing Run binding tests for the pull request (deprecated: use PR-extended-testing instead)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants