Skip to content

Commit 97d40e1

Browse files
committed
balloon: fix max voluntary size in bytes not pages
The maximum voluntary inflation size was previously specified in bytes, but used as if it were a number of pages. Fix this by directly specifying the maximum voluntary inflation size as a number of 4K pages.
1 parent 123f095 commit 97d40e1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/drivers/balloon/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ pub mod oom;
3333
#[cfg(feature = "pci")]
3434
mod pci;
3535

36-
const BALLOON_PAGE_SIZE: usize = 4096;
36+
const KIBI: u32 = 1024;
37+
const MEBI: u32 = 1024 * KIBI;
38+
const GIBI: u32 = 1024 * MEBI;
39+
40+
const BALLOON_PAGE_SIZE: usize = 4 * KIBI as usize;
3741

3842
const VOLUNTARY_INFLATE_INTERVAL_MICROS: u64 = 1_000_000;
39-
const VOLUNTARY_INFLATE_MAX_SIZE_BYTES: u32 = 1 << 31; // 2 GiB
43+
const VOLUNTARY_INFLATE_MAX_NUM_PAGES: u32 = 2 * GIBI / BALLOON_PAGE_SIZE as u32;
4044

4145
// TODO: prevent possible deflate of not yet acknowledged inflated pages. See VIRTIO v1.2 5.5.6.1
4246

@@ -362,7 +366,7 @@ impl VirtioBalloonDriver {
362366
debug!("<balloon> Voluntarily inflating balloon as much as we can");
363367
let num_inflated = self.inflate(
364368
&mut ALLOCATOR.inner().lock(),
365-
VOLUNTARY_INFLATE_MAX_SIZE_BYTES,
369+
VOLUNTARY_INFLATE_MAX_NUM_PAGES,
366370
true,
367371
);
368372
debug!(

0 commit comments

Comments
 (0)