Skip to content

Commit db58dce

Browse files
committed
balloon: update device field names
Signed-off-by: George Pisaltu <[email protected]>
1 parent f345213 commit db58dce

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/devices/src/virtio/balloon/device.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ macro_rules! mem_of_active_device {
4141
};
4242
}
4343

44-
fn mb_to_pages(amount_mb: u32) -> Result<u32, BalloonError> {
45-
amount_mb
46-
.checked_mul(MB_TO_4K_PAGES)
44+
fn mib_to_pages(amount_mib: u32) -> Result<u32, BalloonError> {
45+
amount_mib
46+
.checked_mul(MIB_TO_4K_PAGES)
4747
.ok_or(BalloonError::TooManyPagesRequested)
4848
}
4949

50-
fn pages_to_mb(amount_pages: u32) -> u32 {
51-
amount_pages / MB_TO_4K_PAGES
50+
fn pages_to_mib(amount_pages: u32) -> u32 {
51+
amount_pages / MIB_TO_4K_PAGES
5252
}
5353

5454
#[repr(C)]
@@ -76,7 +76,7 @@ unsafe impl ByteValued for BalloonStat {}
7676
// BalloonStats holds statistics returned from the stats_queue.
7777
#[derive(Clone, Default, Debug, PartialEq, Serialize)]
7878
pub struct BalloonConfig {
79-
pub amount_mb: u32,
79+
pub amount_mib: u32,
8080
pub deflate_on_oom: bool,
8181
pub stats_polling_interval_s: u16,
8282
}
@@ -87,8 +87,8 @@ pub struct BalloonConfig {
8787
pub struct BalloonStats {
8888
pub target_pages: u32,
8989
pub actual_pages: u32,
90-
pub target_mb: u32,
91-
pub actual_mb: u32,
90+
pub target_mib: u32,
91+
pub actual_mib: u32,
9292
#[serde(skip_serializing_if = "Option::is_none")]
9393
pub swap_in: Option<u64>,
9494
#[serde(skip_serializing_if = "Option::is_none")]
@@ -163,7 +163,7 @@ pub struct Balloon {
163163

164164
impl Balloon {
165165
pub fn new(
166-
amount_mb: u32,
166+
amount_mib: u32,
167167
deflate_on_oom: bool,
168168
stats_polling_interval_s: u16,
169169
restored: bool,
@@ -199,7 +199,7 @@ impl Balloon {
199199
avail_features,
200200
acked_features: 0u64,
201201
config_space: ConfigSpace {
202-
num_pages: mb_to_pages(amount_mb)?,
202+
num_pages: mib_to_pages(amount_mib)?,
203203
actual_pages: 0,
204204
},
205205
interrupt_status: Arc::new(AtomicUsize::new(0)),
@@ -423,9 +423,9 @@ impl Balloon {
423423
BALLOON_DEV_ID
424424
}
425425

426-
pub fn update_size(&mut self, amount_mb: u32) -> Result<(), BalloonError> {
426+
pub fn update_size(&mut self, amount_mib: u32) -> Result<(), BalloonError> {
427427
if self.is_activated() {
428-
self.config_space.num_pages = mb_to_pages(amount_mb)?;
428+
self.config_space.num_pages = mib_to_pages(amount_mib)?;
429429
Ok(())
430430
} else {
431431
Err(BalloonError::DeviceNotActive)
@@ -460,7 +460,7 @@ impl Balloon {
460460
}
461461

462462
pub fn size_mb(&self) -> u32 {
463-
pages_to_mb(self.config_space.num_pages)
463+
pages_to_mib(self.config_space.num_pages)
464464
}
465465

466466
pub fn deflate_on_oom(&self) -> bool {
@@ -475,8 +475,8 @@ impl Balloon {
475475
if self.stats_enabled() {
476476
self.latest_stats.target_pages = self.config_space.num_pages;
477477
self.latest_stats.actual_pages = self.config_space.actual_pages;
478-
self.latest_stats.target_mb = pages_to_mb(self.latest_stats.target_pages);
479-
self.latest_stats.actual_mb = pages_to_mb(self.latest_stats.actual_pages);
478+
self.latest_stats.target_mib = pages_to_mib(self.latest_stats.target_pages);
479+
self.latest_stats.actual_mib = pages_to_mib(self.latest_stats.actual_pages);
480480
Some(&self.latest_stats)
481481
} else {
482482
None
@@ -485,7 +485,7 @@ impl Balloon {
485485

486486
pub fn config(&self) -> BalloonConfig {
487487
BalloonConfig {
488-
amount_mb: self.size_mb(),
488+
amount_mib: self.size_mb(),
489489
deflate_on_oom: self.deflate_on_oom(),
490490
stats_polling_interval_s: self.stats_polling_interval_s(),
491491
}
@@ -631,8 +631,8 @@ pub(crate) mod tests {
631631
let mut stats = BalloonStats {
632632
target_pages: 5120,
633633
actual_pages: 2560,
634-
target_mb: 20,
635-
actual_mb: 10,
634+
target_mib: 20,
635+
actual_mib: 10,
636636
swap_in: Some(0),
637637
swap_out: Some(0),
638638
major_faults: Some(0),
@@ -713,7 +713,7 @@ pub(crate) mod tests {
713713
let balloon = Balloon::new(0x10, true, 0, false).unwrap();
714714

715715
let cfg = BalloonConfig {
716-
amount_mb: 16,
716+
amount_mib: 16,
717717
deflate_on_oom: true,
718718
stats_polling_interval_s: 0,
719719
};

src/devices/src/virtio/balloon/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub const CONFIG_SPACE_SIZE: usize = 8;
2121
pub const QUEUE_SIZE: u16 = 256;
2222
pub const NUM_QUEUES: usize = 3;
2323
pub const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE, QUEUE_SIZE, QUEUE_SIZE];
24-
// Number of 4K pages in a MB.
25-
pub const MB_TO_4K_PAGES: u32 = 256;
24+
// Number of 4K pages in a MiB.
25+
pub const MIB_TO_4K_PAGES: u32 = 256;
2626
// The maximum number of pages that can be received in a single descriptor.
2727
pub const MAX_PAGES_IN_DESC: usize = 256;
2828
// The maximum number of pages that can be compacted into ranges during process_inflate().

0 commit comments

Comments
 (0)