See also #198344 and #277473 I am running FreeBSD 14.3-RELEASE in a kvm on Linux 6.18 with libvirt 12.0.0 > virsh -V Virsh command line tool of libvirt 12.0.0 See web site at https://libvirt.org/ Compiled with support for: Hypervisors: QEMU/KVM LXC OpenVZ Cloud-Hypervisor VMware VirtualBox ESX Test Networking: Remote Network Bridging Interface udev Nwfilter Storage: Dir Disk Filesystem SCSI Multipath iSCSI iSCSI-direct LVM Gluster ZFS Miscellaneous: Daemon Nodedev Secrets Debug Readline VM is configured with a memory size of 25165824k, Q35 chipset, BIOS firmware, VirtIO disk of 20GB, a VirtIO nic of type bridge. info from ps aux on a freshly started VM: VSZ:27259904 RSS: 5005584 Seems to be consistent with what you see inside on the inside # sysctl vm.kmem_size vm.kmem_size: 25013338112 virtio_balloon seems to be loaded: # kldstat -v | grep virtio_balloon 301 virtio_pci/virtio_balloon 300 virtio_mmio/virtio_balloon Also seems to be working: # sysctl -a | grep balloon vtballoon0: <VirtIO Balloon Adapter> on virtio_pci2 vtballoon0: <VirtIO Balloon Adapter> on virtio_pci2 device virtio_balloon dev.vtballoon.0.current: 512 dev.vtballoon.0.desired: 1048576 dev.vtballoon.0.%iommu: dev.vtballoon.0.%parent: virtio_pci2 dev.vtballoon.0.%pnpinfo: vendor=0x00001af4 device=0x1045 subvendor=0x1af4 device_type=0x00000005 dev.vtballoon.0.%location: dev.vtballoon.0.%driver: vtballoon dev.vtballoon.0.%desc: VirtIO Balloon Adapter dev.vtballoon.%parent: dev.xen.balloon.high_mem: 0 dev.xen.balloon.low_mem: 0 dev.xen.balloon.hard_limit: 0 dev.xen.balloon.driver_pages: 0 dev.xen.balloon.target: 0 dev.xen.balloon.current: 0 However, if I want to adjust the amount of memory used by the VM: VM: # sysctl dev.vtballoon.0 | grep "current\|desired" dev.vtballoon.0.current: 512 dev.vtballoon.0.desired: 1048576 Host: ❯ virsh setmem "FreeBSD buildd" 20480m VM: # sysctl dev.vtballoon.0 | grep "current\|desired" dev.vtballoon.0.current: 768 dev.vtballoon.0.desired: 1048576 Rerunning the virsh command; Host: ❯ virsh setmem "FreeBSD buildd" 20480m VM: # sysctl dev.vtballoon.0 | grep "current\|desired" dev.vtballoon.0.current: 1024 dev.vtballoon.0.desired: 1048576 Host: VSZ: 27259904 RSS: 5010588 No matter how long (exaggeration; I just waited a few minutes), on an idle system, that "current" number does not change. Every time one uses virsh setmem, the value does indeed change (today the value seems to increase by 256 each time), but I can't recall seeing it change more than 2048 in one go. VSZ and RSS seems to be stuck on the same values. After running a quick poudriere bulk (no packages built, but it still seems to write to all the memory in the VM) VSZ: 27312164 RSS: 16032432 ❯ virsh setmem "FreeBSD buildd" 20480m # sysctl dev.vtballoon.0 | grep "current\|desired" dev.vtballoon.0.current: 1536 dev.vtballoon.0.desired: 1048576 ❯ virsh setmem "FreeBSD buildd" 20480m # sysctl dev.vtballoon.0 | grep "current\|desired" dev.vtballoon.0.current: 1792 dev.vtballoon.0.desired: 1048576 ❯ virsh setmem "FreeBSD buildd" 20480m # sysctl dev.vtballoon.0 | grep "current\|desired" dev.vtballoon.0.current: 2048 dev.vtballoon.0.desired: 1048576 VSZ: 27262988 RSS: 16036424 To my untrained eye, it seems like the balloon-code runs one loop of trying of adjusting memory, then stops, hence adjusting only with a small amount. It doesn't seem to affect the memory usage on the host. Not in this limited testing at least. Using virt-manager (https://virt-manager.org/), adjusting the memory allocation there, changes the number by 1MB each time. If I do the same thing on a Linux VM, the value changes by a very small amount first, then rapidly to the correct number. Working in both directions. Indicating that the libvirt on the host is not horribly broken, at least.
> See also #198344 and #277473 Clickable links to the two closed reports: bug 198344, bug 277473.
Hi, I had create a PR to improve virtio-balloon, can you test it to check if is it fix the error what you see? https://github.com/freebsd/freebsd-src/pull/2116 Thanks a lot
(In reply to Xiangzhe from comment #2) It *seems* to be a step in the right direction.. The allocation shrinks by 1MiB every apx. 5 seconds now, and it seems to be going until the target set. I guess dev.vtballoon.0.current and dev.vtballoon.0.desired are in some other unit than KiB.. it's moving in steps of 256 per time virt-manager say it has adjusted the current allocation with 1MiB, pointing me to it being in 4k pages? Since your code has #define VTBALLOON_PAGES_PER_REQUEST 256 I guess the reasoning is sound.. No idea why it only request changes once every 5 seconds, or thereabouts, but at least it tries to work now:)
Thank you for test. 256 is reference the Linux kernel source code. And I had push new chance to PR, can you test it if is it fix the slow shrinks?
This looks very good:) Can I now have it backported to 14.4, so I can use it on my poudriere-machine?:)
Created attachment 269744 [details] 14.4-backport-virtio-balloon-oom
(In reply to Xiangzhe from comment #6) Perfect:) Now, if only the code on the hypervisor-side could care to ask the VM to release memory when under pressure.. But that's not your fault.
The only weird thing, is that the module doesn't start reporting data until I look at the statistics in virt-manager (whatever it's sending when looking at the memory usage). Before that, it reports nothing.
(In reply to lysfjord.daniel from comment #8) Nevermind previous comment. Wrong VM..
Looking at it, there's something strange until I look at the vm in virt-manager. Usable seems to be very close to available for some reason, and the faults are not reported. This is on a 14.4 VM. # Before looking ❯ virsh dommemstat "FreeBSD buildd" actual 3140608 swap_in 0 swap_out 0 major_fault 0 minor_fault 0 unused 18224420 available 18296048 usable 18224420 last_update 1776893227 disk_caches 0 rss 2487048 # After Looking ❯ virsh dommemstat "FreeBSD buildd" actual 3140608 swap_in 0 swap_out 0 major_fault 503 minor_fault 107626 unused 2167724 available 18296048 usable 2153348 last_update 1776894685 disk_caches 19412 rss 2491400
Created attachment 270010 [details] Diff in sysctl -a Before is before starting virt-manager, after is, after..