From 16e1449f1e0f142022ceceef7823a2b636bddbb7 Mon Sep 17 00:00:00 2001 From: Jianyong Wu Date: Wed, 9 Aug 2023 08:41:59 +0000 Subject: [PATCH] balloon: let balloon deflation works on page size other than 4k Similar to balloon inflation, memory allocation is also constrained to align with the page size. Therefore, memory is allocated in units of the host page size, one page at a time, until all host pages that the memory range requested by the guest are managed. If the requested size is smaller than the page size, the entire page will still be allocated because smaller allocations are not possible due to the page size limitation. Fixes: cloud-hypervisor#5369 Signed-off-by: Jianyong Wu --- virtio-devices/src/balloon.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/virtio-devices/src/balloon.rs b/virtio-devices/src/balloon.rs index c9f372c6f..a44f9f246 100644 --- a/virtio-devices/src/balloon.rs +++ b/virtio-devices/src/balloon.rs @@ -276,18 +276,18 @@ impl BalloonEpollHandler { .map_err(Error::GuestMemory)?; offset += data_chunk_size as u64; - let range_base = GuestAddress((pfn as u64) << VIRTIO_BALLOON_PFN_SHIFT); - let range_len = 1 << VIRTIO_BALLOON_PFN_SHIFT; - match queue_index { 0 => { Self::release_memory_range_4k(&mut self.pbp, desc_chain.memory(), pfn)?; } 1 => { + let page_size = get_page_size() as usize; + let rbase = align_page_size_down((pfn as u64) << VIRTIO_BALLOON_PFN_SHIFT); + Self::advise_memory_range( desc_chain.memory(), - range_base, - range_len, + vm_memory::GuestAddress(rbase), + page_size, libc::MADV_WILLNEED, )?; }