Skip to content

Refactor both Mmapper impls into ChunkStateMmapper #1369

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
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

wks
Copy link
Collaborator

@wks wks commented Aug 14, 2025

The two existing Mmapper implementations, namely ByteMapMmapper and TwoLevelMmapper have much duplicated code.

We introduce ChunkStateMmapper which implements a chunk-grained Mmapper backed by a logical array of MapState elements, one for each chunk. It is responsible for actually calling mmap on memory regions. The ByteMapMmapper and TwoLevelMmapper become ByteMapStateStorate and TwoLevelStateStorage, respectively, and they are only responsible for holding the per-chunk states and iterating over ranges of memory to help ChunkStateMmapper. We retains the trait Mmapper so that we can still implement other memory mappers that work at different granularities.

MapState is now a pure data type, and state-transitioning methods previously implemented in impl MapState are inlined into methods of ChunkStateMmapper.

We also removed the constant MMAP_CHUNK_BYTES. It was defined as BYTES_IN_CHUNK, but it seemed to convey the message that the "mmap chunk" is special and can have a size that is different from "chunk". We instead added a function Mmapper::granularity() which returns the actual granularity of the mmapper.

wks added 5 commits July 20, 2025 01:53
We make Mmapper a struct instead of trait.  It will be solely
responsible for transitioning the map states.

Existing implementations, including `ByteMapMmapper` and
`TwoLevelMmapper`, become the storage backends of `Mmapper`.  They are
only responsible for maintaining the (one-level or two-level) array of
`Atomic<MapState>`, and provide high-level functions for bulk-setting
and bulk-transitioning map states.

Methods of `MapState` are moved to `Mmapper`.
They are now only responsible for the storage, not mmapping.
We keep the Mmapper trait, and create a ChunkStateMmapper that work at
chunk granularity.
@wks
Copy link
Collaborator Author

wks commented Aug 14, 2025

Unlike #1345, this PR retains the trait Mmapper so that we can implement other memory mappers that work at different granularities.

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.

1 participant