diff --git a/src/runtime-rs/config/configuration-cloud-hypervisor.toml.in b/src/runtime-rs/config/configuration-cloud-hypervisor.toml.in index 0cb17abb2f..726a2b33ad 100644 --- a/src/runtime-rs/config/configuration-cloud-hypervisor.toml.in +++ b/src/runtime-rs/config/configuration-cloud-hypervisor.toml.in @@ -158,6 +158,16 @@ virtio_fs_cache = "@DEFVIRTIOFSCACHE@" # > 5 --> will be set to 5 default_bridges = @DEFBRIDGES@ +# Reclaim guest freed memory. +# Enabling this will result in the VM balloon device having f_reporting=on set. +# Then the hypervisor will use it to reclaim guest freed memory. +# This is useful for reducing the amount of memory used by a VM. +# Enabling this feature may sometimes reduce the speed of memory access in +# the VM. +# +# Default false +#reclaim_guest_freed_memory = true + # Block storage driver to be used for the hypervisor in case the container # rootfs is backed by a block device. block_device_driver = "virtio-blk-pci" diff --git a/src/runtime-rs/crates/hypervisor/ch-config/src/convert.rs b/src/runtime-rs/crates/hypervisor/ch-config/src/convert.rs index cdc1eef09c..fa8dfded49 100644 --- a/src/runtime-rs/crates/hypervisor/ch-config/src/convert.rs +++ b/src/runtime-rs/crates/hypervisor/ch-config/src/convert.rs @@ -180,6 +180,15 @@ impl TryFrom for VmConfig { let platform = get_platform_cfg(guest_protection_to_use); + let balloon = if cfg.device_info.reclaim_guest_freed_memory { + Some(crate::BalloonConfig { + free_page_reporting: true, + ..Default::default() + }) + } else { + None + }; + let cfg = VmConfig { cpus, memory, @@ -193,6 +202,7 @@ impl TryFrom for VmConfig { vsock: Some(vsock), rng, platform, + balloon, ..Default::default() };