petri: enable THP for shared memory and on Windows#4008
Open
jstarks wants to merge 4 commits into
Open
Conversation
Petri gated transparent huge pages behind private anonymous memory and a Linux host, since that was the only backing where THP had any effect. The membacking layer now marks shared (file/memfd) guest RAM as THP-eligible and implements Windows soft large pages, so those restrictions are stale and needlessly suppress THP for VMs backed by shared memory or running on Windows hosts. Drop the private-memory and Linux-host conditions and pass the requested THP setting straight through; membacking already suppresses it where it genuinely does not apply, such as explicit hugetlb backings. Update the MemoryConfig docs to match. This should improve test performance on Windows hosts.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Petri’s OpenVMM VM construction to stop artificially disabling Transparent Huge Pages (THP) based on “private memory only” and “Linux only” assumptions, and refreshes the Petri MemoryConfig docs to reflect the broader THP support now provided by the membacking layer (including Windows soft large pages).
Changes:
- Remove Petri-side gating that previously forced
transparent_hugepagesoff unless the VM used private anonymous memory on Linux. - Update Petri
MemoryConfig::transparent_hugepagesdocumentation to describe applicability on shared memory and Windows.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
petri/src/vm/openvmm/construct.rs |
Stops overriding the requested THP setting; passes it through to OpenVMM memory config. |
petri/src/vm/mod.rs |
Updates MemoryConfig docs to describe THP applicability beyond private/Linux-only assumptions. |
Comment on lines
+2351
to
+2355
| /// Defaults to `true`. Applies to both private anonymous and shared | ||
| /// (file/memfd) guest RAM, on Linux (via `madvise`) and on Windows (via | ||
| /// soft large pages). It is silently ignored where it does not apply, such | ||
| /// as explicit hugetlb/large-page (`with_hugepages`) backings, which are | ||
| /// already huge. |
Address review feedback that the THP doc over-promised for shared backings. Spell out that `with_hugepages` (already-huge hugetlb pages) and `with_memory_backing_file` (file-backed for save/restore, not an anonymous memfd) force THP off, so callers that set transparent_hugepages and then enable those options don't expect it to take effect. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8d243e0c-9ec6-4169-acd6-37d6afc78c8a
The two shared-memory helpers set transparent_hugepages = false by hand. For with_hugepages that is dead code: membacking already suppresses THP for any hugetlb backing (transparent_hugepages && !hugepages), so the setting never reaches the mapping. For with_memory_backing_file it was hiding behavior rather than reflecting a real constraint — on Linux the madvise is a harmless no-op on a real file, and on Windows it simply lets soft large pages apply. If soft large pages are wrong for a file-backed mapping we want that to surface, not be silently masked. Let the requested THP value flow through in both helpers and trust membacking as the single source of truth for where THP applies. Revert the MemoryConfig doc to the simpler wording now that no helper contradicts it; membacking still transparently ignores THP for hugetlb backings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8d243e0c-9ec6-4169-acd6-37d6afc78c8a
smalis-msft
approved these changes
Jul 23, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
petri/src/vm/mod.rs:2353
- Doc mismatch: this says THP applies to “shared memfd-backed RAM”, but petri can also use a file-backed RAM section via
with_memory_backing_file, and the membacking layer’s file-mapping path still treats file-backed shared RAM as THP-eligible (best-effort). The docs here should mention shared file/memfd backings for consistency with the implementation and PR description.
/// Defaults to `true`. Applies to private anonymous guest RAM and to
/// shared memfd-backed RAM, on Linux (via `madvise`) and on Windows (via
/// soft large pages). It has no effect on explicit hugetlb/large-page
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.
Petri gated transparent huge pages behind private anonymous memory and a Linux host, since that was the only backing where THP had any effect. The membacking layer now marks shared (file/memfd) guest RAM as THP-eligible and implements Windows soft large pages, so those restrictions are stale and needlessly suppress THP for VMs backed by shared memory or running on Windows hosts.
Drop the private-memory and Linux-host conditions and pass the requested THP setting straight through; membacking already suppresses it where it genuinely does not apply, such as explicit hugetlb backings. Update the MemoryConfig docs to match.
This should improve test performance on Windows hosts.