Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions petri/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,13 +2345,15 @@ pub struct MemoryConfig {
///
/// Only applies to the OpenVMM backend; ignored by Hyper-V.
pub private_memory: Option<bool>,
/// Mark private guest RAM as eligible for Transparent Huge Pages (THP),
/// Mark guest RAM as eligible for Transparent Huge Pages (THP),
/// improving performance for large allocations.
///
/// Defaults to `true`. Only takes effect when the guest RAM is backed by
/// private anonymous memory (see [`Self::private_memory`]) and only on
/// Linux; it is silently ignored otherwise (shared memory, hugetlb/file
/// backing, OpenHCL, PCAT/Gen1, or non-Linux hosts).
/// 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
/// backings (see
/// [`with_hugepages`](crate::openvmm::PetriVmConfigOpenVmm::with_hugepages)),
/// which are already huge.
///
/// Only applies to the OpenVMM backend; ignored by Hyper-V.
pub transparent_hugepages: bool,
Expand Down
10 changes: 5 additions & 5 deletions petri/src/vm/openvmm/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ impl PetriVmConfigOpenVmm {
None => !private_incompatible,
};

// THP is only valid for private anonymous memory and only on
// Linux; disable it otherwise to avoid a memory build error.
let transparent_hugepages =
transparent_hugepages && private_memory && cfg!(target_os = "linux");

// THP applies to both private anonymous and shared (file/memfd)
// guest RAM, and on both Linux (madvise-based) and Windows
// (soft large pages). The membacking layer suppresses it where it
// does not apply (e.g. explicit hugetlb backings), so pass the
// requested value through unchanged.
let make_mem = |size: u64| openvmm_defs::config::MemoryConfig {
mem_size: size,
prefetch_memory: false,
Expand Down
2 changes: 0 additions & 2 deletions petri/src/vm/openvmm/modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ impl PetriVmConfigOpenVmm {
for node in &mut self.config.numa.nodes {
if let Some(mem) = &mut node.mem {
mem.private_memory = false;
mem.transparent_hugepages = false;
}
}
self
Expand All @@ -383,7 +382,6 @@ impl PetriVmConfigOpenVmm {
mem.hugepages = true;
mem.hugepage_size = hugepage_size;
mem.private_memory = false;
mem.transparent_hugepages = false;
}
}
self
Expand Down
Loading