mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-balloon: add deflate_on_oom support
Sometimes we need balloon deflate automatically to give memory back to guest, especially for some low priority guest processes under memory pressure. Enable deflate_on_oom to support this. Usage: --balloon "size=0,deflate_on_oom=on" \ Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
This commit is contained in:
@@ -745,6 +745,10 @@ components:
|
||||
size:
|
||||
type: integer
|
||||
format: int64
|
||||
deflate_on_oom:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Whether the balloon should deflate when the guest is under memory pressure.
|
||||
|
||||
FsConfig:
|
||||
required:
|
||||
|
||||
+16
-2
@@ -1201,14 +1201,19 @@ impl Default for RngConfig {
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||
pub struct BalloonConfig {
|
||||
pub size: u64,
|
||||
/// Option to deflate the balloon in case the guest is out of memory.
|
||||
#[serde(default)]
|
||||
pub deflate_on_oom: bool,
|
||||
}
|
||||
|
||||
impl BalloonConfig {
|
||||
pub const SYNTAX: &'static str = "Balloon parameters \"size=<balloon_size>\"";
|
||||
pub const SYNTAX: &'static str =
|
||||
"Balloon parameters \"size=<balloon_size>,deflate_on_oom=on|off\"";
|
||||
|
||||
pub fn parse(balloon: &str) -> Result<Self> {
|
||||
let mut parser = OptionParser::new();
|
||||
parser.add("size");
|
||||
parser.add("deflate_on_oom");
|
||||
parser.parse(balloon).map_err(Error::ParseBalloon)?;
|
||||
|
||||
let size = parser
|
||||
@@ -1217,7 +1222,16 @@ impl BalloonConfig {
|
||||
.map(|v| v.0)
|
||||
.unwrap_or(0);
|
||||
|
||||
Ok(BalloonConfig { size })
|
||||
let deflate_on_oom = parser
|
||||
.convert::<Toggle>("deflate_on_oom")
|
||||
.map_err(Error::ParseBalloon)?
|
||||
.unwrap_or(Toggle(false))
|
||||
.0;
|
||||
|
||||
Ok(BalloonConfig {
|
||||
size,
|
||||
deflate_on_oom,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2610,6 +2610,7 @@ impl DeviceManager {
|
||||
virtio_devices::Balloon::new(
|
||||
id.clone(),
|
||||
balloon_config.size,
|
||||
balloon_config.deflate_on_oom,
|
||||
self.seccomp_action.clone(),
|
||||
)
|
||||
.map_err(DeviceManagerError::CreateVirtioBalloon)?,
|
||||
|
||||
Reference in New Issue
Block a user