Skip to content

petri: enable THP for shared memory and on Windows#4008

Open
jstarks wants to merge 4 commits into
microsoft:mainfrom
jstarks:thp-windows-shared
Open

petri: enable THP for shared memory and on Windows#4008
jstarks wants to merge 4 commits into
microsoft:mainfrom
jstarks:thp-windows-shared

Conversation

@jstarks

@jstarks jstarks commented Jul 23, 2026

Copy link
Copy Markdown
Member

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.

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.
@jstarks
jstarks requested a review from a team as a code owner July 23, 2026 08:31
Copilot AI review requested due to automatic review settings July 23, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_hugepages off unless the VM used private anonymous memory on Linux.
  • Update Petri MemoryConfig::transparent_hugepages documentation 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 thread petri/src/vm/mod.rs Outdated
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.
jstarks and others added 2 commits July 23, 2026 11:50
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
Copilot AI review requested due to automatic review settings July 23, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 23, 2026 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread petri/src/vm/openvmm/construct.rs
Copilot AI review requested due to automatic review settings July 23, 2026 21:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

Copy link
Copy Markdown

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.

3 participants