// Copyright 2022 The ChromiumOS Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34use serde::Deserialize;5use serde::Serialize;67// Balloon commands that are send on the balloon command tube.8#[derive(Serialize, Deserialize, Debug)]9pub enum BalloonTubeCommand {10// Set the size of the VM's balloon.11Adjust {12num_bytes: u64,13// When this flag is set, adjust attempts can fail. After adjustment, the final14// size of the balloon is returned via a BalloonTubeResult::Adjust message.15//16// The flag changes the semantics of inflating the balloon. By default, the driver17// will indefinitely retry if it fails to allocate pages when inflating the18// balloon. However, when this flag is set, the balloon device responds to page19// allocation failures in the guest by stopping inflation at the balloon's current20// size.21allow_failure: bool,22},23// Fetch balloon stats.24Stats,25// Fetch balloon ws.26WorkingSet,27// Send balloon ws config to guest.28WorkingSetConfig {29bins: Vec<u32>,30refresh_threshold: u32,31report_threshold: u32,32},33}3435// BalloonStats holds stats returned from the stats_queue.36#[derive(Default, Serialize, Deserialize, Debug, Clone)]37pub struct BalloonStats {38pub swap_in: Option<u64>,39pub swap_out: Option<u64>,40pub major_faults: Option<u64>,41pub minor_faults: Option<u64>,42pub free_memory: Option<u64>,43pub total_memory: Option<u64>,44pub available_memory: Option<u64>,45pub disk_caches: Option<u64>,46pub hugetlb_allocations: Option<u64>,47pub hugetlb_failures: Option<u64>,48pub shared_memory: Option<u64>,49pub unevictable_memory: Option<u64>,50}5152pub const VIRTIO_BALLOON_WS_MIN_NUM_BINS: usize = 2;53pub const VIRTIO_BALLOON_WS_MAX_NUM_BINS: usize = 16;5455// WSBucket stores information about a bucket (or bin) of the working set.56#[derive(Default, Serialize, Deserialize, Debug, Clone, Copy)]57pub struct WSBucket {58pub age: u64,59pub bytes: [u64; 2],60}6162// BalloonWS holds WS returned from the ws_queue.63#[derive(Default, Serialize, Deserialize, Debug, Clone)]64pub struct BalloonWS {65/// working set, separated per histogram bucket.66pub ws: Vec<WSBucket>,67}6869impl BalloonWS {70pub fn new() -> Self {71BalloonWS { ws: vec![] }72}73}7475// BalloonTubeResult are results to BalloonTubeCommand defined above.76#[derive(Serialize, Deserialize, Debug)]77pub enum BalloonTubeResult {78Stats {79stats: BalloonStats,80balloon_actual: u64,81},82Adjusted {83num_bytes: u64,84},85WorkingSet {86ws: BalloonWS,87/// size of the balloon in bytes.88balloon_actual: u64,89},90}919293