Skip to content

Commit b292b51

Browse files
jstarksCopilot
andauthored
petri: enable THP for shared memory and on Windows (#4008)
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. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8d243e0c-9ec6-4169-acd6-37d6afc78c8a
1 parent 087ceea commit b292b51

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

petri/src/vm/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,13 +2345,15 @@ pub struct MemoryConfig {
23452345
///
23462346
/// Only applies to the OpenVMM backend; ignored by Hyper-V.
23472347
pub private_memory: Option<bool>,
2348-
/// Mark private guest RAM as eligible for Transparent Huge Pages (THP),
2348+
/// Mark guest RAM as eligible for Transparent Huge Pages (THP),
23492349
/// improving performance for large allocations.
23502350
///
2351-
/// Defaults to `true`. Only takes effect when the guest RAM is backed by
2352-
/// private anonymous memory (see [`Self::private_memory`]) and only on
2353-
/// Linux; it is silently ignored otherwise (shared memory, hugetlb/file
2354-
/// backing, OpenHCL, PCAT/Gen1, or non-Linux hosts).
2351+
/// Defaults to `true`. Applies to private anonymous guest RAM and to
2352+
/// shared memfd-backed RAM, on Linux (via `madvise`) and on Windows (via
2353+
/// soft large pages). It has no effect on explicit hugetlb/large-page
2354+
/// backings (see
2355+
/// [`with_hugepages`](crate::openvmm::PetriVmConfigOpenVmm::with_hugepages)),
2356+
/// which are already huge.
23552357
///
23562358
/// Only applies to the OpenVMM backend; ignored by Hyper-V.
23572359
pub transparent_hugepages: bool,

petri/src/vm/openvmm/construct.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,11 @@ impl PetriVmConfigOpenVmm {
488488
None => !private_incompatible,
489489
};
490490

491-
// THP is only valid for private anonymous memory and only on
492-
// Linux; disable it otherwise to avoid a memory build error.
493-
let transparent_hugepages =
494-
transparent_hugepages && private_memory && cfg!(target_os = "linux");
495-
491+
// THP applies to both private anonymous and shared (file/memfd)
492+
// guest RAM, and on both Linux (madvise-based) and Windows
493+
// (soft large pages). The membacking layer suppresses it where it
494+
// does not apply (e.g. explicit hugetlb backings), so pass the
495+
// requested value through unchanged.
496496
let make_mem = |size: u64| openvmm_defs::config::MemoryConfig {
497497
mem_size: size,
498498
prefetch_memory: false,

petri/src/vm/openvmm/modify.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ impl PetriVmConfigOpenVmm {
358358
for node in &mut self.config.numa.nodes {
359359
if let Some(mem) = &mut node.mem {
360360
mem.private_memory = false;
361-
mem.transparent_hugepages = false;
362361
}
363362
}
364363
self
@@ -383,7 +382,6 @@ impl PetriVmConfigOpenVmm {
383382
mem.hugepages = true;
384383
mem.hugepage_size = hugepage_size;
385384
mem.private_memory = false;
386-
mem.transparent_hugepages = false;
387385
}
388386
}
389387
self

0 commit comments

Comments
 (0)