Skip to content

Commit

Permalink
runtime-rs: Add reclaim_guest_freed_memory cloud-hypervisor support
Browse files Browse the repository at this point in the history
Add reclaim_guest_freed_memory config to cloud-hypervisor in runtime-rs.

Fixes: kata-containers#10710

Signed-off-by: Hui Zhu <[email protected]>
  • Loading branch information
teawater committed Jan 21, 2025
1 parent 487171d commit 185b94b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/runtime-rs/config/configuration-cloud-hypervisor.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions src/runtime-rs/crates/hypervisor/ch-config/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ impl TryFrom<NamedHypervisorConfig> 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,
Expand All @@ -193,6 +202,7 @@ impl TryFrom<NamedHypervisorConfig> for VmConfig {
vsock: Some(vsock),
rng,
platform,
balloon,

..Default::default()
};
Expand Down

0 comments on commit 185b94b

Please sign in to comment.