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 <jianyong.wu@arm.com>
This commit is contained in:
Jianyong Wu 2023-08-09 08:41:59 +00:00 committed by Rob Bradford
parent 9dd1698556
commit 16e1449f1e

View File

@ -276,18 +276,18 @@ impl BalloonEpollHandler {
.map_err(Error::GuestMemory)?; .map_err(Error::GuestMemory)?;
offset += data_chunk_size as u64; 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 { match queue_index {
0 => { 0 => {
Self::release_memory_range_4k(&mut self.pbp, desc_chain.memory(), pfn)?; Self::release_memory_range_4k(&mut self.pbp, desc_chain.memory(), pfn)?;
} }
1 => { 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( Self::advise_memory_range(
desc_chain.memory(), desc_chain.memory(),
range_base, vm_memory::GuestAddress(rbase),
range_len, page_size,
libc::MADV_WILLNEED, libc::MADV_WILLNEED,
)?; )?;
} }