-
Notifications
You must be signed in to change notification settings - Fork 104
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
Add Configurable Page Size Policy to MmapRegion #127
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Michael Jarrett <[email protected]>
Signed-off-by: Michael Jarrett <[email protected]>
Signed-off-by: Michael Jarrett <[email protected]>
Thanks for the PR and sorry for the lack of replies so far. I'll start having a better look sometime this week and will return with more comments. |
Hi, after having a better look at this and thinking some more about it, it looks like a good opportunity to introduce a more forward looking and extensible It now becomes simpler to implement more configuration possibilities by adding more fields to |
I like the high level idea of a compact
|
This PR adds a
PageSizePolicy
enum which can be used to configure the behavior ofMmapRegion
instances upon creation. The current options are:BasePages
, which uses the defaultmmap
behaviorTransparentHugepages
, which uses THP viamadvise
ExplicitHugepages
, which passesMAP_HUGETLB
tommap
The page size policy is at a per-mapping granularity, so a given VM can have different policies for different mappings, if desired. A helper function,
from_ranges_with_policy
, allows the VMM to configure mapping policies when constructing mappings from address ranges.The behavior is stubbed out on the
mmap_windows.rs
implementation, but the arguments are received there to allow the file to compile.The intention of this PR is to implement the functionality required for hugepage support in vm-memory (for #118), but without invasively modifying the external API, pending further discussion. This is mostly accomplished by adding extra constructors/functions which take a PageSizePolicy as an argument, but leaving existing functions alone.
These changes were experimentally tested for Firecracker by modifying Firecracker's local fork of vm-memory to include similar changes. Empirically, we were able to boot an Alpine microvm up to ~37% faster, and an Ubuntu microvm up to ~30% faster, reduce on-boot page faults by ~70×, all with negligible extra memory overhead. We would like to implement these changes here, so that other VMMs derived from vm-memory can hopefully reap the same benefit.
A few design questions we're not too sure about:
What is the correct way to expose this configuration to VMMs? The way we've chosen is to add a special
from_ranges
function inmmap.rs
that accepts a policy per tuple. However, as of recently, Firecracker is using a slightly modified local fork of vm-memory to implement dirty bit tracking, in addition to this repo. The local fork complicates how (and where) classes are used/defined (for example, it overridesmmap.rs
), making it difficult to utilize these changes downstream. We're not sure how other downstreams of this repo use the APIs, either. Advice to improve the API is much appreciated.At which level of abstraction should this policy belong? We decided to place the enum in
mmap.rs
since paging policy is closely related to mmapped regions, and not so closely related to GuestMemory in general. However, by attaching a policy to all MmapRegions, we're requiring a Windows implementation (which, for now, is just a no-op). Would it make sense to implement anExplicitHugepages
policy for Windows, if the OS provides that kind of control?