virtmgr: Pass hugepages to crosvm
Now crosvm applies block alignment ("arm64: Align RAM region with the
block size") when mmaping the RAM region for a VM, it is possible to
back this memory with THP (transparent-hugepages). This is controlled by
either the VM config option "hugepages" or the "bin/vm" option
"--hugepages"
Enabling --hugepages makes crosvm "madvise(MADV_HUGEPAGE)" that region.
This will have at the moment no effect on Android as the default value
for /sys/kernel/mm/transparent_hugepages/shmem_enabled is [never].
However, it'll enable OEMs to turn on the feature by tweaking the latter
knob.
Using THP brings a significant performance improvement by reducing the
number of fault necessary when using a VM (/512 for a 4K pages Arm
machine) and reducing the pressure on the TLB (for both stage-1 and
stage-2). However, finding huge pages might be a difficult task when the
system has been running for a long time and the memory is quite
fragmented. khugepaged helps promoting pages to huge-pages but running
it has a cost and might delay the memory allocation depending on the
chosen defrag policy.
Bug: 278011447
Change-Id: I954f93df4f08ad015958d36d115d9f9e0c3547b5
diff --git a/virtualizationmanager/src/aidl.rs b/virtualizationmanager/src/aidl.rs
index f1509e2..a245e11 100644
--- a/virtualizationmanager/src/aidl.rs
+++ b/virtualizationmanager/src/aidl.rs
@@ -633,6 +633,7 @@
device_tree_overlay,
display_config,
input_device_options,
+ hugepages: config.hugePages,
};
let instance = Arc::new(
VmInstance::new(
@@ -918,6 +919,7 @@
vm_config.name.clone_from(&config.name);
vm_config.protectedVm = config.protectedVm;
vm_config.cpuTopology = config.cpuTopology;
+ vm_config.hugePages = config.hugePages || vm_payload_config.hugepages;
// Microdroid takes additional init ramdisk & (optionally) storage image
add_microdroid_system_images(config, instance_file, storage_image, os_name, &mut vm_config)?;