1 // Copyright 2022 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use serde::{Deserialize, Serialize}; 6 7 // Balloon commands that are send on the balloon command tube. 8 #[derive(Serialize, Deserialize, Debug)] 9 pub enum BalloonTubeCommand { 10 // Set the size of the VM's balloon. 11 Adjust { 12 num_bytes: u64, 13 // When this flag is set, adjust attempts can fail. After adjustment, the final 14 // 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 driver 17 // will indefinitely retry if it fails to allocate pages when inflating the 18 // balloon. However, when this flag is set, the balloon device responds to page 19 // allocation failures in the guest by stopping inflation at the balloon's current 20 // size. 21 allow_failure: bool, 22 }, 23 // Fetch balloon stats. The ID can be used to discard stale states 24 // if any previous stats requests failed or timed out. 25 Stats { 26 id: u64, 27 }, 28 } 29 30 // BalloonStats holds stats returned from the stats_queue. 31 #[derive(Default, Serialize, Deserialize, Debug)] 32 pub struct BalloonStats { 33 pub swap_in: Option<u64>, 34 pub swap_out: Option<u64>, 35 pub major_faults: Option<u64>, 36 pub minor_faults: Option<u64>, 37 pub free_memory: Option<u64>, 38 pub total_memory: Option<u64>, 39 pub available_memory: Option<u64>, 40 pub disk_caches: Option<u64>, 41 pub hugetlb_allocations: Option<u64>, 42 pub hugetlb_failures: Option<u64>, 43 pub shared_memory: Option<u64>, 44 pub unevictable_memory: Option<u64>, 45 } 46 47 // BalloonTubeResult are results to BalloonTubeCommand defined above. 48 #[derive(Serialize, Deserialize, Debug)] 49 pub enum BalloonTubeResult { 50 Stats { 51 stats: BalloonStats, 52 balloon_actual: u64, 53 id: u64, 54 }, 55 Adjusted { 56 num_bytes: u64, 57 }, 58 } 59