mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-06 10:34:41 +00:00
Merge pull request #10711 from teawater/balloon
Add reclaim_guest_freed_memory config to qemu and cloud-hypervisor
This commit is contained in:
commit
17d053f4bb
@ -499,7 +499,7 @@ pub struct DeviceInfo {
|
|||||||
///
|
///
|
||||||
/// Enabling this will result in the VM balloon device having f_reporting=on set
|
/// Enabling this will result in the VM balloon device having f_reporting=on set
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub enable_balloon_f_reporting: bool,
|
pub reclaim_guest_freed_memory: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceInfo {
|
impl DeviceInfo {
|
||||||
|
@ -158,6 +158,16 @@ virtio_fs_cache = "@DEFVIRTIOFSCACHE@"
|
|||||||
# > 5 --> will be set to 5
|
# > 5 --> will be set to 5
|
||||||
default_bridges = @DEFBRIDGES@
|
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
|
# Block storage driver to be used for the hypervisor in case the container
|
||||||
# rootfs is backed by a block device.
|
# rootfs is backed by a block device.
|
||||||
block_device_driver = "virtio-blk-pci"
|
block_device_driver = "virtio-blk-pci"
|
||||||
|
@ -98,11 +98,15 @@ default_maxvcpus = @DEFMAXVCPUS_DB@
|
|||||||
# > 5 --> will be set to 5
|
# > 5 --> will be set to 5
|
||||||
default_bridges = @DEFBRIDGES@
|
default_bridges = @DEFBRIDGES@
|
||||||
|
|
||||||
# Enable balloon f_reporting
|
# Reclaim guest freed memory.
|
||||||
# Enabling this will result in the VM balloon device having f_reporting=on set
|
# 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
|
# Default false
|
||||||
#enable_balloon_f_reporting = true
|
#reclaim_guest_freed_memory = true
|
||||||
|
|
||||||
# Default memory size in MiB for SB/VM.
|
# Default memory size in MiB for SB/VM.
|
||||||
# If unspecified then it will be set @DEFMEMSZ@ MiB.
|
# If unspecified then it will be set @DEFMEMSZ@ MiB.
|
||||||
|
@ -143,6 +143,16 @@ default_maxvcpus = @DEFMAXVCPUS_QEMU@
|
|||||||
# > 5 --> will be set to 5
|
# > 5 --> will be set to 5
|
||||||
default_bridges = @DEFBRIDGES@
|
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
|
||||||
|
|
||||||
# Default memory size in MiB for SB/VM.
|
# Default memory size in MiB for SB/VM.
|
||||||
# If unspecified then it will be set @DEFMEMSZ@ MiB.
|
# If unspecified then it will be set @DEFMEMSZ@ MiB.
|
||||||
default_memory = @DEFMEMSZ@
|
default_memory = @DEFMEMSZ@
|
||||||
|
@ -180,6 +180,15 @@ impl TryFrom<NamedHypervisorConfig> for VmConfig {
|
|||||||
|
|
||||||
let platform = get_platform_cfg(guest_protection_to_use);
|
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 {
|
let cfg = VmConfig {
|
||||||
cpus,
|
cpus,
|
||||||
memory,
|
memory,
|
||||||
@ -193,6 +202,7 @@ impl TryFrom<NamedHypervisorConfig> for VmConfig {
|
|||||||
vsock: Some(vsock),
|
vsock: Some(vsock),
|
||||||
rng,
|
rng,
|
||||||
platform,
|
platform,
|
||||||
|
balloon,
|
||||||
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -430,7 +430,7 @@ impl DragonballInner {
|
|||||||
use_shared_irq: None,
|
use_shared_irq: None,
|
||||||
use_generic_irq: None,
|
use_generic_irq: None,
|
||||||
f_deflate_on_oom: false,
|
f_deflate_on_oom: false,
|
||||||
f_reporting: self.config.device_info.enable_balloon_f_reporting,
|
f_reporting: self.config.device_info.reclaim_guest_freed_memory,
|
||||||
};
|
};
|
||||||
self.vmm_instance
|
self.vmm_instance
|
||||||
.insert_balloon_device(balloon_config)
|
.insert_balloon_device(balloon_config)
|
||||||
@ -462,7 +462,7 @@ impl DragonballInner {
|
|||||||
use_shared_irq: None,
|
use_shared_irq: None,
|
||||||
use_generic_irq: None,
|
use_generic_irq: None,
|
||||||
f_deflate_on_oom: false,
|
f_deflate_on_oom: false,
|
||||||
f_reporting: self.config.device_info.enable_balloon_f_reporting,
|
f_reporting: self.config.device_info.reclaim_guest_freed_memory,
|
||||||
};
|
};
|
||||||
self.balloon_size = had_mem_mb - new_mem_mb;
|
self.balloon_size = had_mem_mb - new_mem_mb;
|
||||||
self.vmm_instance
|
self.vmm_instance
|
||||||
|
@ -85,7 +85,7 @@ impl Hypervisor for Dragonball {
|
|||||||
let mut inner = self.inner.write().await;
|
let mut inner = self.inner.write().await;
|
||||||
let ret = inner.start_vm(timeout).await;
|
let ret = inner.start_vm(timeout).await;
|
||||||
|
|
||||||
if ret.is_ok() && inner.config.device_info.enable_balloon_f_reporting {
|
if ret.is_ok() && inner.config.device_info.reclaim_guest_freed_memory {
|
||||||
// The virtio-balloon device must be inserted into dragonball and
|
// The virtio-balloon device must be inserted into dragonball and
|
||||||
// recognized by the guest kernel only after the dragonball upcall is ready.
|
// recognized by the guest kernel only after the dragonball upcall is ready.
|
||||||
// The dragonball upcall is not ready immediately after the VM starts,
|
// The dragonball upcall is not ready immediately after the VM starts,
|
||||||
|
@ -1793,6 +1793,10 @@ impl<'a> QemuCmdLine<'a> {
|
|||||||
qemu_cmd_line.add_scsi_controller();
|
qemu_cmd_line.add_scsi_controller();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.device_info.reclaim_guest_freed_memory {
|
||||||
|
qemu_cmd_line.add_virtio_balloon();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(qemu_cmd_line)
|
Ok(qemu_cmd_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2007,6 +2011,11 @@ impl<'a> QemuCmdLine<'a> {
|
|||||||
self.devices.push(Box::new(console_socket_chardev));
|
self.devices.push(Box::new(console_socket_chardev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_virtio_balloon(&mut self) {
|
||||||
|
let balloon_device = DeviceVirtioBalloon::new();
|
||||||
|
self.devices.push(Box::new(balloon_device));
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn build(&self) -> Result<Vec<String>> {
|
pub async fn build(&self) -> Result<Vec<String>> {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
|
||||||
@ -2071,3 +2080,22 @@ fn get_devno_ccw(ccw_subchannel: &mut Option<CcwSubChannel>, device_name: &str)
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct DeviceVirtioBalloon {}
|
||||||
|
|
||||||
|
impl DeviceVirtioBalloon {
|
||||||
|
fn new() -> Self {
|
||||||
|
DeviceVirtioBalloon {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ToQemuParams for DeviceVirtioBalloon {
|
||||||
|
async fn qemu_params(&self) -> Result<Vec<String>> {
|
||||||
|
Ok(vec![
|
||||||
|
"-device".to_owned(),
|
||||||
|
"virtio-balloon,free-page-reporting=on".to_owned(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,3 +23,5 @@ CONFIG_VIRTIO_BLK=y
|
|||||||
CONFIG_TTY=y
|
CONFIG_TTY=y
|
||||||
CONFIG_VIRTIO_CONSOLE=y
|
CONFIG_VIRTIO_CONSOLE=y
|
||||||
CONFIG_VIRTIO_NET=y
|
CONFIG_VIRTIO_NET=y
|
||||||
|
|
||||||
|
CONFIG_VIRTIO_BALLOON=y
|
||||||
|
@ -1 +1 @@
|
|||||||
142
|
143
|
||||||
|
Loading…
Reference in New Issue
Block a user