mmap/unix.rs: Add with_minimum_alignment to MmapRegionBuilder#375
Open
jaredwhitedev wants to merge 2 commits intorust-vmm:mainfrom
Open
mmap/unix.rs: Add with_minimum_alignment to MmapRegionBuilder#375jaredwhitedev wants to merge 2 commits intorust-vmm:mainfrom
mmap/unix.rs: Add with_minimum_alignment to MmapRegionBuilder#375jaredwhitedev wants to merge 2 commits intorust-vmm:mainfrom
Conversation
68f50c8 to
edb910a
Compare
edb910a to
c8904b3
Compare
Author
|
Seems that we can't allocate with more than a 512 MiB alignment when using Miri. Would you rather we: |
liuw
reviewed
Apr 6, 2026
src/mmap/unix.rs
Outdated
|
|
||
| /// Create the `MmapRegion` object with the specified minimum alignment. | ||
| /// `min_align` must be a power of two and at least the system page size. | ||
| pub fn with_minimum_alignment(mut self, min_align: usize) -> Self { |
Member
There was a problem hiding this comment.
Non-conformant values are rejected in the build function, but I think it will be better to reject them here. This function can return a Result<Self>. In the error case you return InvalidAlignment.
This is a cleaner approach. Users of the alignment value don't need to validate it again.
c8904b3 to
235023c
Compare
Add an option to specify a minimal alignment for the mmap'd region. This is useful to ensure VM memory backings get huge EPT entries. Signed-off-by: Jared White <git@jaredwhite.dev>
19deda4 to
a6229cb
Compare
Signed-off-by: Jared White <git@jaredwhite.dev>
a6229cb to
e42e47b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an option to specify a minimal alignment for the mmap'd region. This is useful to ensure VM memory backings get huge EPT entries.
Summary of the PR
Please summarize here why the changes in this PR are needed.
To get huge EPT entries callers must be able to align their memory to larger page sizes, such as 2 MiB or 1 GiB.
Using huge EPT entries increases the memory performance by decreasing the TLB pressure.
Expose a
with_minimum_alignmentoption toMmapRegionBuilderto allow callers to do so.To support this, we first allocate
size+alignment_sizeof virtual address space, then useMAP_FIXEDto place the actual mapping at an aligned address within the reserved VA space. We then free the excessRequirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s), and the commit message has max 60 characters for thesummary and max 75 characters for each description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafecode is properly documented.