mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: always try THP for VM RAM
The kernel allows madvise on shared memory if /sys/kernel/mm/transparent_hugepage/shmem_enabled is set. Always try and configure THP via madvise when the user requests THP be enabled. If this fails, only a warning log is emitted and THP won't be enabled. Signed-off-by: Champ-Goblem <cameron@northflank.com>
This commit is contained in:
committed by
Rob Bradford
parent
2c2f5d2431
commit
1e0eba60af
@@ -25,9 +25,7 @@ use devices::ioapic;
|
|||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
use hypervisor::HypervisorVmError;
|
use hypervisor::HypervisorVmError;
|
||||||
use libc::_SC_NPROCESSORS_ONLN;
|
use libc::_SC_NPROCESSORS_ONLN;
|
||||||
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
|
use log::{debug, error, info, warn};
|
||||||
use log::debug;
|
|
||||||
use log::{error, info, warn};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracer::trace_scoped;
|
use tracer::trace_scoped;
|
||||||
@@ -1490,17 +1488,20 @@ impl MemoryManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if region.file_offset().is_none() && thp {
|
info!(
|
||||||
info!(
|
"RAM region mapping at 0x{:x} (size = 0x{:x})",
|
||||||
"Anonymous mapping at 0x{:x} (size = 0x{:x})",
|
region.as_ptr() as u64,
|
||||||
region.as_ptr() as u64,
|
size
|
||||||
size
|
);
|
||||||
);
|
|
||||||
|
if thp && !hugepages {
|
||||||
// SAFETY: FFI call with correct arguments
|
// SAFETY: FFI call with correct arguments
|
||||||
let ret = unsafe { libc::madvise(region.as_ptr() as _, size, libc::MADV_HUGEPAGE) };
|
let ret = unsafe { libc::madvise(region.as_ptr() as _, size, libc::MADV_HUGEPAGE) };
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
let e = io::Error::last_os_error();
|
let e = io::Error::last_os_error();
|
||||||
warn!("Failed to mark pages as THP eligible: {e}");
|
warn!("Failed to mark pages as THP eligible: {e}");
|
||||||
|
} else {
|
||||||
|
debug!("Successfully marked pages as THP eligible");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user