Skip to content

Optimize bulk metadata operations for Region #1407

@wks

Description

@wks

Currently, we have SideMetadataSpec::bset_metadata and SideMetadataSpec::bzero_metadata. They are general. They take care of corner cases such as the starting or ending bits are in the middle of a metadata byte. This complicated the issue and we developed complex algorithms (e.g. #1181) to deal with the general cases.

However, we often deal with side metadata for Region. A Region is power of two in size, and is aligned to its size. A corollary of this is that any side metadata of a Region must be aligned to its own size (in bits), provided that the granularity of the side metadata is finer than the Region.

For example, an Immix line is a 256-byte region, and the VO bit side metadata is one bit per 8 bytes. The VO bits for an Immix line is therefore 32 bits in size. We can prove that the side metadata range (in terms of the bits offset from the side metadata base address) must also be a multiple of 32 bits. As long as the side metadata base address is 4-byte aligned, the metadata for a Region must also be an aligned u32.

This gives us many interesting properties. For example, bulk-clearing the VO bit side metadata for an Immix line should be, in theory, just one 32-bit store instruction. There should be no loops or boundary checks involved.

Implementation

The key is to persuade Rust to consider both the side metadata spec and the Region size as constant. Things like VO_BITS.bzero_metadata::<Line>(line) should be expanded to one 32-bit assignment with some not-too-complicated address computation.

To avoid unnecessary address computation, if we are, for example, modifying multiple Immix lines in one Immix block, we know their VO bits metadata must be adjacent, too. We may iterate through all the 32-bit VO bit metadata words for an Immix block while we sweep all lines in a block. We only need to add 8 to the metadata address when we move to the next line, and there is no need to handle discontiguous metadata in this case because a Block must be within a Chunk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions