1use serde::Deserialize;
6use serde::Serialize;
7
8#[derive(Serialize, Deserialize, Debug)]
10pub enum BalloonTubeCommand {
11 Adjust {
13 num_bytes: u64,
14 allow_failure: bool,
23 },
24 Stats,
26 WorkingSet,
28 WorkingSetConfig {
30 bins: Vec<u32>,
31 refresh_threshold: u32,
32 report_threshold: u32,
33 },
34}
35
36#[derive(Default, Serialize, Deserialize, Debug, Clone)]
38pub struct BalloonStats {
39 pub swap_in: Option<u64>,
40 pub swap_out: Option<u64>,
41 pub major_faults: Option<u64>,
42 pub minor_faults: Option<u64>,
43 pub free_memory: Option<u64>,
44 pub total_memory: Option<u64>,
45 pub available_memory: Option<u64>,
46 pub disk_caches: Option<u64>,
47 pub hugetlb_allocations: Option<u64>,
48 pub hugetlb_failures: Option<u64>,
49 pub shared_memory: Option<u64>,
50 pub unevictable_memory: Option<u64>,
51}
52
53pub const VIRTIO_BALLOON_WS_MIN_NUM_BINS: usize = 2;
54pub const VIRTIO_BALLOON_WS_MAX_NUM_BINS: usize = 16;
55
56#[derive(Default, Serialize, Deserialize, Debug, Clone, Copy)]
58pub struct WSBucket {
59 pub age: u64,
60 pub bytes: [u64; 2],
61}
62
63#[derive(Default, Serialize, Deserialize, Debug, Clone)]
65pub struct BalloonWS {
66 pub ws: Vec<WSBucket>,
68}
69
70impl BalloonWS {
71 pub fn new() -> Self {
72 BalloonWS { ws: vec![] }
73 }
74}
75
76#[derive(Serialize, Deserialize, Debug)]
78pub enum BalloonTubeResult {
79 Stats {
80 stats: BalloonStats,
81 balloon_actual: u64,
82 },
83 Adjusted {
84 num_bytes: u64,
85 },
86 WorkingSet {
87 ws: BalloonWS,
88 balloon_actual: u64,
90 },
91}