diff --git a/src/runtime-rs/config/configuration-dragonball.toml.in b/src/runtime-rs/config/configuration-dragonball.toml.in index cb8d7aeee1..ca1db2681a 100644 --- a/src/runtime-rs/config/configuration-dragonball.toml.in +++ b/src/runtime-rs/config/configuration-dragonball.toml.in @@ -136,6 +136,14 @@ block_device_driver = "@DEFBLOCKSTORAGEDRIVER_DB@" # of shim, does not need an external virtiofsd process. shared_fs = "@DBSHAREDFS@" +# Enable huge pages for VM RAM, default false +# Enabling this will result in the VM memory +# being allocated using huge pages. +# This is useful when you want to use vhost-user network +# stacks within the container. This will automatically +# result in memory pre allocation +#enable_hugepages = true + [agent.@PROJECT_TYPE@] container_pipe_size=@PIPESIZE@ # If enabled, make the agent display debug-level messages. diff --git a/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs b/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs index 7db3f3278c..17934a62b3 100644 --- a/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/dragonball/inner.rs @@ -7,7 +7,7 @@ use super::vmm_instance::VmmInstance; use crate::{ device::Device, hypervisor_persist::HypervisorState, kernel_param::KernelParams, VmmState, - HYPERVISOR_DRAGONBALL, VM_ROOTFS_DRIVER_BLK, + DEV_HUGEPAGES, HUGETLBFS, HYPERVISOR_DRAGONBALL, SHMEM, VM_ROOTFS_DRIVER_BLK, }; use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; @@ -186,11 +186,18 @@ impl DragonballInner { fn set_vm_base_config(&mut self) -> Result<()> { let serial_path = [&self.run_dir, "console.sock"].join("/"); + let (mem_type, mem_file_path) = if self.config.memory_info.enable_hugepages { + (String::from(HUGETLBFS), String::from(DEV_HUGEPAGES)) + } else { + (String::from(SHMEM), String::from("")) + }; let vm_config = VmConfigInfo { serial_path: Some(serial_path), mem_size_mib: self.config.memory_info.default_memory as usize, vcpu_count: self.config.cpu_info.default_vcpus as u8, max_vcpu_count: self.config.cpu_info.default_maxvcpus as u8, + mem_type, + mem_file_path, ..Default::default() }; info!(sl!(), "vm config: {:?}", vm_config); diff --git a/src/runtime-rs/crates/hypervisor/src/dragonball/vmm_instance.rs b/src/runtime-rs/crates/hypervisor/src/dragonball/vmm_instance.rs index 70172c73a9..00829ad4c9 100644 --- a/src/runtime-rs/crates/hypervisor/src/dragonball/vmm_instance.rs +++ b/src/runtime-rs/crates/hypervisor/src/dragonball/vmm_instance.rs @@ -327,9 +327,9 @@ impl VmmInstance { } } } - return Err(anyhow::anyhow!( + Err(anyhow::anyhow!( "After {} attempts, it still doesn't work.", REQUEST_RETRY - )); + )) } } diff --git a/src/runtime-rs/crates/hypervisor/src/lib.rs b/src/runtime-rs/crates/hypervisor/src/lib.rs index 6b499d0bac..2aea25d107 100644 --- a/src/runtime-rs/crates/hypervisor/src/lib.rs +++ b/src/runtime-rs/crates/hypervisor/src/lib.rs @@ -26,6 +26,13 @@ use kata_types::config::hypervisor::Hypervisor as HypervisorConfig; // Config which driver to use as vm root dev const VM_ROOTFS_DRIVER_BLK: &str = "virtio-blk"; const VM_ROOTFS_DRIVER_PMEM: &str = "virtio-pmem"; +// before using hugepages for VM, we need to mount hugetlbfs +// /dev/hugepages will be the mount point +// mkdir -p /dev/hugepages +// mount -t hugetlbfs none /dev/hugepages +const DEV_HUGEPAGES: &str = "/dev/hugepages"; +pub const HUGETLBFS: &str = "hugetlbfs"; +const SHMEM: &str = "shmem"; pub const HYPERVISOR_DRAGONBALL: &str = "dragonball"; #[derive(PartialEq)] diff --git a/src/runtime-rs/crates/persist/src/lib.rs b/src/runtime-rs/crates/persist/src/lib.rs index ff61a2d4be..4ea0731410 100644 --- a/src/runtime-rs/crates/persist/src/lib.rs +++ b/src/runtime-rs/crates/persist/src/lib.rs @@ -26,7 +26,7 @@ pub fn to_disk(value: &T, sid: &str) -> Result<()> { serde_json::to_writer_pretty(f, &j)?; return Ok(()); } - return Err(anyhow!("invalid sid {}", sid)); + Err(anyhow!("invalid sid {}", sid)) } pub fn from_disk(sid: &str) -> Result @@ -41,7 +41,7 @@ where let reader = BufReader::new(file); return serde_json::from_reader(reader).map_err(|e| anyhow!(e.to_string())); } - return Err(anyhow!("invalid sid {}", sid)); + Err(anyhow!("invalid sid {}", sid)) } #[cfg(test)]