When host_zeroes_pages is set, the host has zeroed the balloon
pages on reclaim.  Use put_page_zeroed() during deflation so
the freed pages are marked as zeroed in the buddy allocator,
allowing the next allocation to skip redundant zeroing.

put_page_zeroed() is best-effort: if the balloon is the sole
holder (the common case), the zeroed hint reaches the buddy
allocator via free_frozen_pages_zeroed().  If someone else
holds a reference, the hint is silently lost.

Once balloon pages are converted to frozen pages (no refcount),
this can switch to free_frozen_pages_zeroed() directly.

Signed-off-by: Michael S. Tsirkin <[email protected]>
Assisted-by: Claude:claude-opus-4-6
---
 drivers/virtio/virtio_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 8c15530b51b3..cdc3c960397d 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -304,7 +304,10 @@ static void release_pages_balloon(struct virtio_balloon 
*vb,
 
        list_for_each_entry_safe(page, next, pages, lru) {
                list_del(&page->lru);
-               put_page(page); /* balloon reference */
+               if (host_zeroes_pages && !page_poisoning_enabled_static())
+                       put_page_zeroed(page);
+               else
+                       put_page(page); /* balloon reference */
        }
 }
 
-- 
MST


Reply via email to