@@ -64,40 +64,63 @@ struct BalloonStat {
6464// SAFETY: Safe because BalloonStat only contains plain data.
6565unsafe impl ByteValued for BalloonStat { }
6666
67- // BalloonStats holds statistics returned from the stats_queue .
67+ /// Holds configuration details for the balloon device .
6868#[ derive( Clone , Default , Debug , PartialEq , Eq , Serialize ) ]
6969pub struct BalloonConfig {
70+ /// Target size.
7071 pub amount_mib : u32 ,
72+ /// Whether or not to ask for pages back.
7173 pub deflate_on_oom : bool ,
74+ /// Interval of time in seconds at which the balloon statistics are updated.
7275 pub stats_polling_interval_s : u16 ,
7376}
7477
75- // BalloonStats holds statistics returned from the stats_queue.
78+ /// BalloonStats holds statistics returned from the stats_queue.
7679#[ derive( Clone , Default , Debug , PartialEq , Eq , Serialize ) ]
7780#[ serde( deny_unknown_fields) ]
7881pub struct BalloonStats {
82+ /// The target size of the balloon, in 4K pages.
7983 pub target_pages : u32 ,
84+ /// The number of 4K pages the device is currently holding.
8085 pub actual_pages : u32 ,
86+ /// The target size of the balloon, in MiB.
8187 pub target_mib : u32 ,
88+ /// The number of MiB the device is currently holding.
8289 pub actual_mib : u32 ,
90+ /// Amount of memory swapped in.
8391 #[ serde( skip_serializing_if = "Option::is_none" ) ]
8492 pub swap_in : Option < u64 > ,
93+ /// Amount of memory swapped out.
8594 #[ serde( skip_serializing_if = "Option::is_none" ) ]
8695 pub swap_out : Option < u64 > ,
96+ /// Number of major faults.
8797 #[ serde( skip_serializing_if = "Option::is_none" ) ]
8898 pub major_faults : Option < u64 > ,
99+ /// Number of minor faults.
89100 #[ serde( skip_serializing_if = "Option::is_none" ) ]
90101 pub minor_faults : Option < u64 > ,
102+ /// The amount of memory not being used for any
103+ /// purpose (in bytes).
91104 #[ serde( skip_serializing_if = "Option::is_none" ) ]
92105 pub free_memory : Option < u64 > ,
106+ /// Total amount of memory available (in bytes).
93107 #[ serde( skip_serializing_if = "Option::is_none" ) ]
94108 pub total_memory : Option < u64 > ,
109+ /// An estimate of how much memory is available (in
110+ /// bytes) for starting new applications, without pushing the system to swap.
95111 #[ serde( skip_serializing_if = "Option::is_none" ) ]
96112 pub available_memory : Option < u64 > ,
113+ /// The amount of memory, in bytes, that can be
114+ /// quickly reclaimed without additional I/O. Typically these pages are used for
115+ /// caching files from disk.
97116 #[ serde( skip_serializing_if = "Option::is_none" ) ]
98117 pub disk_caches : Option < u64 > ,
118+ /// The number of successful hugetlb page
119+ /// allocations in the guest.
99120 #[ serde( skip_serializing_if = "Option::is_none" ) ]
100121 pub hugetlb_allocations : Option < u64 > ,
122+ /// The number of failed hugetlb page allocations
123+ /// in the guest.
101124 #[ serde( skip_serializing_if = "Option::is_none" ) ]
102125 pub hugetlb_failures : Option < u64 > ,
103126}
@@ -125,7 +148,7 @@ impl BalloonStats {
125148 }
126149}
127150
128- // Virtio balloon device.
151+ /// Virtio balloon device.
129152pub struct Balloon {
130153 // Virtio fields.
131154 pub ( crate ) avail_features : u64 ,
@@ -175,6 +198,7 @@ impl fmt::Debug for Balloon {
175198}
176199
177200impl Balloon {
201+ /// Instantiate a new balloon device.
178202 pub fn new (
179203 amount_mib : u32 ,
180204 deflate_on_oom : bool ,
@@ -419,6 +443,7 @@ impl Balloon {
419443 let _ = self . process_deflate_queue ( ) ;
420444 }
421445
446+ /// Provides the ID of this balloon device.
422447 pub fn id ( & self ) -> & str {
423448 BALLOON_DEV_ID
424449 }
@@ -440,6 +465,7 @@ impl Balloon {
440465 }
441466 }
442467
468+ /// Update the target size of the balloon.
443469 pub fn update_size ( & mut self , amount_mib : u32 ) -> Result < ( ) , BalloonError > {
444470 if self . is_activated ( ) {
445471 self . config_space . num_pages = mib_to_pages ( amount_mib) ?;
@@ -451,6 +477,7 @@ impl Balloon {
451477 }
452478 }
453479
480+ /// Update the the statistics polling interval.
454481 pub fn update_stats_polling_interval ( & mut self , interval_s : u16 ) -> Result < ( ) , BalloonError > {
455482 if self . stats_polling_interval_s == interval_s {
456483 return Ok ( ( ) ) ;
@@ -476,10 +503,12 @@ impl Balloon {
476503 . set_state ( timer_state, SetTimeFlags :: Default ) ;
477504 }
478505
506+ /// Obtain the number of 4K pages the device is currently holding.
479507 pub fn num_pages ( & self ) -> u32 {
480508 self . config_space . num_pages
481509 }
482510
511+ /// Obtain the size of 4K pages the device is currently holding in MIB.
483512 pub fn size_mb ( & self ) -> u32 {
484513 pages_to_mib ( self . config_space . num_pages )
485514 }
@@ -492,6 +521,7 @@ impl Balloon {
492521 self . stats_polling_interval_s
493522 }
494523
524+ /// Retrieve latest stats for the balloon device.
495525 pub fn latest_stats ( & mut self ) -> Option < & BalloonStats > {
496526 if self . stats_enabled ( ) {
497527 self . latest_stats . target_pages = self . config_space . num_pages ;
@@ -504,6 +534,7 @@ impl Balloon {
504534 }
505535 }
506536
537+ /// Return the config of the balloon device.
507538 pub fn config ( & self ) -> BalloonConfig {
508539 BalloonConfig {
509540 amount_mib : self . size_mb ( ) ,
0 commit comments