@@ -64,40 +64,63 @@ struct BalloonStat {
64
64
// SAFETY: Safe because BalloonStat only contains plain data.
65
65
unsafe impl ByteValued for BalloonStat { }
66
66
67
- // BalloonStats holds statistics returned from the stats_queue .
67
+ /// Holds configuration details for the balloon device .
68
68
#[ derive( Clone , Default , Debug , PartialEq , Eq , Serialize ) ]
69
69
pub struct BalloonConfig {
70
+ /// Target size.
70
71
pub amount_mib : u32 ,
72
+ /// Whether or not to ask for pages back.
71
73
pub deflate_on_oom : bool ,
74
+ /// Interval of time in seconds at which the balloon statistics are updated.
72
75
pub stats_polling_interval_s : u16 ,
73
76
}
74
77
75
- // BalloonStats holds statistics returned from the stats_queue.
78
+ /// BalloonStats holds statistics returned from the stats_queue.
76
79
#[ derive( Clone , Default , Debug , PartialEq , Eq , Serialize ) ]
77
80
#[ serde( deny_unknown_fields) ]
78
81
pub struct BalloonStats {
82
+ /// The target size of the balloon, in 4K pages.
79
83
pub target_pages : u32 ,
84
+ /// The number of 4K pages the device is currently holding.
80
85
pub actual_pages : u32 ,
86
+ /// The target size of the balloon, in MiB.
81
87
pub target_mib : u32 ,
88
+ /// The number of MiB the device is currently holding.
82
89
pub actual_mib : u32 ,
90
+ /// Amount of memory swapped in.
83
91
#[ serde( skip_serializing_if = "Option::is_none" ) ]
84
92
pub swap_in : Option < u64 > ,
93
+ /// Amount of memory swapped out.
85
94
#[ serde( skip_serializing_if = "Option::is_none" ) ]
86
95
pub swap_out : Option < u64 > ,
96
+ /// Number of major faults.
87
97
#[ serde( skip_serializing_if = "Option::is_none" ) ]
88
98
pub major_faults : Option < u64 > ,
99
+ /// Number of minor faults.
89
100
#[ serde( skip_serializing_if = "Option::is_none" ) ]
90
101
pub minor_faults : Option < u64 > ,
102
+ /// The amount of memory not being used for any
103
+ /// purpose (in bytes).
91
104
#[ serde( skip_serializing_if = "Option::is_none" ) ]
92
105
pub free_memory : Option < u64 > ,
106
+ /// Total amount of memory available (in bytes).
93
107
#[ serde( skip_serializing_if = "Option::is_none" ) ]
94
108
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.
95
111
#[ serde( skip_serializing_if = "Option::is_none" ) ]
96
112
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.
97
116
#[ serde( skip_serializing_if = "Option::is_none" ) ]
98
117
pub disk_caches : Option < u64 > ,
118
+ /// The number of successful hugetlb page
119
+ /// allocations in the guest.
99
120
#[ serde( skip_serializing_if = "Option::is_none" ) ]
100
121
pub hugetlb_allocations : Option < u64 > ,
122
+ /// The number of failed hugetlb page allocations
123
+ /// in the guest.
101
124
#[ serde( skip_serializing_if = "Option::is_none" ) ]
102
125
pub hugetlb_failures : Option < u64 > ,
103
126
}
@@ -125,7 +148,7 @@ impl BalloonStats {
125
148
}
126
149
}
127
150
128
- // Virtio balloon device.
151
+ /// Virtio balloon device.
129
152
pub struct Balloon {
130
153
// Virtio fields.
131
154
pub ( crate ) avail_features : u64 ,
@@ -175,6 +198,7 @@ impl fmt::Debug for Balloon {
175
198
}
176
199
177
200
impl Balloon {
201
+ /// Instantiate a new balloon device.
178
202
pub fn new (
179
203
amount_mib : u32 ,
180
204
deflate_on_oom : bool ,
@@ -419,6 +443,7 @@ impl Balloon {
419
443
let _ = self . process_deflate_queue ( ) ;
420
444
}
421
445
446
+ /// Provides the ID of this balloon device.
422
447
pub fn id ( & self ) -> & str {
423
448
BALLOON_DEV_ID
424
449
}
@@ -440,6 +465,7 @@ impl Balloon {
440
465
}
441
466
}
442
467
468
+ /// Update the target size of the balloon.
443
469
pub fn update_size ( & mut self , amount_mib : u32 ) -> Result < ( ) , BalloonError > {
444
470
if self . is_activated ( ) {
445
471
self . config_space . num_pages = mib_to_pages ( amount_mib) ?;
@@ -451,6 +477,7 @@ impl Balloon {
451
477
}
452
478
}
453
479
480
+ /// Update the the statistics polling interval.
454
481
pub fn update_stats_polling_interval ( & mut self , interval_s : u16 ) -> Result < ( ) , BalloonError > {
455
482
if self . stats_polling_interval_s == interval_s {
456
483
return Ok ( ( ) ) ;
@@ -476,10 +503,12 @@ impl Balloon {
476
503
. set_state ( timer_state, SetTimeFlags :: Default ) ;
477
504
}
478
505
506
+ /// Obtain the number of 4K pages the device is currently holding.
479
507
pub fn num_pages ( & self ) -> u32 {
480
508
self . config_space . num_pages
481
509
}
482
510
511
+ /// Obtain the size of 4K pages the device is currently holding in MIB.
483
512
pub fn size_mb ( & self ) -> u32 {
484
513
pages_to_mib ( self . config_space . num_pages )
485
514
}
@@ -492,6 +521,7 @@ impl Balloon {
492
521
self . stats_polling_interval_s
493
522
}
494
523
524
+ /// Retrieve latest stats for the balloon device.
495
525
pub fn latest_stats ( & mut self ) -> Option < & BalloonStats > {
496
526
if self . stats_enabled ( ) {
497
527
self . latest_stats . target_pages = self . config_space . num_pages ;
@@ -504,6 +534,7 @@ impl Balloon {
504
534
}
505
535
}
506
536
537
+ /// Return the config of the balloon device.
507
538
pub fn config ( & self ) -> BalloonConfig {
508
539
BalloonConfig {
509
540
amount_mib : self . size_mb ( ) ,
0 commit comments