vmm: Enable THP when using anonymous memory

If the memory is not backed by a file then it is possible to enable
Transparent Huge Pages on the memory and take advantage of the benefits
of huge pages without requiring the specific allocation of an appropriate
number of huge pages.

TEST=Boot and see that in /proc/`pidof cloud-hypervisor`/smaps that the
region is now THPeligible (and that also pages are being used.)

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-11-02 16:02:57 +00:00
parent 0f44db5da4
commit b68add2d0d

View File

@ -1336,6 +1336,19 @@ impl MemoryManager {
)
.map_err(Error::GuestMemory)?;
if region.file_offset().is_none() {
info!(
"Anonymous mapping at 0x{:x} (size = 0x{:x})",
region.as_ptr() as u64,
size
);
let ret = unsafe { libc::madvise(region.as_ptr() as _, size, libc::MADV_HUGEPAGE) };
if ret != 0 {
let e = io::Error::last_os_error();
warn!("Failed to mark pages as THP eligible: {}", e);
}
}
// Apply NUMA policy if needed.
if let Some(node) = host_numa_node {
let addr = region.deref().as_ptr();