Date: Thu, 9 Apr 2026 13:26:26 +0800 From: xiangzhe <xiangzhedev@gmail.com> To: virtualization@FreeBSD.org Cc: jhb@FreeBSD.org Subject: [PATCH] virtio_balloon: implement STATS_VQ, DEFLATE_ON_OOM, and fix OOM re-inflation Message-ID: <cc5f7a4f-a92a-423d-8de5-073f4164f63b@gmail.com>
index | next in thread | raw e-mail
[-- Attachment #1 --] Hi, I've submitted a patch series to enhance the FreeBSD virtio_balloon driver with features that have been in Linux for years but are missing in FreeBSD. The patches are available for review as a GitHub PR: https://github.com/freebsd/freebsd-src/pull/2116 The series contains 5 commits: 1. virtio_balloon: implement VIRTIO_BALLOON_F_STATS_VQ support Add memory statistics reporting via the stats virtqueue, enabling hypervisors (QEMU/Proxmox/libvirt) to monitor guest memory and make informed ballooning decisions. 2. virtio_balloon: implement VIRTIO_BALLOON_F_DEFLATE_ON_OOM support Register a vm_lowmem event handler so the balloon automatically deflates under memory pressure before the OOM killer is invoked. 3. virtio_balloon: fix OOM deflation immediately re-inflated by balloon thread After OOM deflation, the balloon thread would immediately re-inflate because it re-read the unchanged host target. Add a WANTSIZE flag so inflate/deflate only runs on explicit host config change interrupts. 4. virtio_balloon: replace unconditional OOM log with proper observability Replace noisy per-event device_printf with sysctl counters and a per-instance debug toggle. 5. virtio_balloon: improve S_AVAIL to match virtio spec available memory semantics Replace (free + inactive) with a FreeBSD analogue of Linux's si_mem_available() for more accurate reporting. Motivation: Without STATS_VQ, hypervisors have no visibility into guest memory usage and cannot make informed ballooning decisions. Without DEFLATE_ON_OOM, guests under memory pressure have no way to automatically reclaim balloon pages before processes are killed. These are standard virtio features supported by Linux and NetBSD guests, and their absence in FreeBSD has been reported multiple times. Related Bugzilla PR: - PR 292570: [virtio] virtio-balloon does not balloon correctly <https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292570> Tested on FreeBSD 15-CURRENT and OPNsense (backport to FreeBSD 14 kernel) under QEMU/KVM with libvirt, confirming stats reporting works in Proxmox and OOM deflation prevents unnecessary process kills. Review and feedback welcome. Thanks, Xiangzhe [-- Attachment #2 --] <!DOCTYPE html> <html data-lt-installed="true"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body style="padding-bottom: 1px;"> <p>Hi,<br> I've submitted a patch series to enhance the FreeBSD virtio_balloon driver with features that have been in Linux for years but are missing in FreeBSD. The patches are available for review as a GitHub PR:<br> <a moz-do-not-send="true" href="https://github.com/freebsd/freebsd-src/pull/2116" class="moz-txt-link-freetext">https://github.com/freebsd/freebsd-src/pull/2116</a><br> The series contains 5 commits:<br> 1. virtio_balloon: implement VIRTIO_BALLOON_F_STATS_VQ support<br> Add memory statistics reporting via the stats virtqueue, enabling hypervisors (QEMU/Proxmox/libvirt) to monitor guest memory and make informed ballooning decisions.<br> 2. virtio_balloon: implement VIRTIO_BALLOON_F_DEFLATE_ON_OOM support<br> Register a vm_lowmem event handler so the balloon automatically deflates under memory pressure before the OOM killer is invoked.<br> 3. virtio_balloon: fix OOM deflation immediately re-inflated by balloon thread<br> After OOM deflation, the balloon thread would immediately re-inflate because it re-read the unchanged host target. Add a WANTSIZE flag so inflate/deflate only runs on explicit host config change interrupts.<br> 4. virtio_balloon: replace unconditional OOM log with proper observability<br> Replace noisy per-event device_printf with sysctl counters and a per-instance debug toggle.<br> 5. virtio_balloon: improve S_AVAIL to match virtio spec available memory semantics<br> Replace (free + inactive) with a FreeBSD analogue of Linux's si_mem_available() for more accurate reporting.<br> Motivation:<br> Without STATS_VQ, hypervisors have no visibility into guest memory usage and cannot make informed ballooning decisions. Without DEFLATE_ON_OOM, guests under memory pressure have no way to automatically reclaim balloon pages before processes are killed. These are standard virtio features supported by Linux and NetBSD guests, and their absence in FreeBSD has been reported multiple times.<br> Related Bugzilla PR:<br> - <a moz-do-not-send="true" href="https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292570">PR 292570: [virtio] virtio-balloon does not balloon correctly</a><br> Tested on FreeBSD 15-CURRENT and OPNsense (backport to FreeBSD 14 kernel) under QEMU/KVM with libvirt, confirming stats reporting works in Proxmox and OOM deflation prevents unnecessary process kills.<br> Review and feedback welcome.<br> Thanks,<br> Xiangzhe</p> </body> <lt-container></lt-container> </html>home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?cc5f7a4f-a92a-423d-8de5-073f4164f63b>
