FILE 2024-07-24-freebsd-qemu-ballooning.log
DATE
TAGS FreeBSD QEMU Proxmox Virtualization
A pragmatic workaround for a FreeBSD guest that would not return ballooned memory to its Proxmox host.
I recently encountered a strange problem with memory ballooning in a FreeBSD (pfSense) VM running on Proxmox.
The problem
The VM was not returning unused memory to the host. FreeBSD's VirtIO ballooning driver appeared to be loaded, but the host still saw the full assigned memory as occupied.
Initial findings
Running the following inside the guest showed both balloon values at zero:
sysctl -a | grep balloon
vtballoon0: <VirtIO Balloon Adapter> on virtio_pci0
dev.vtballoon.0.current: 0
dev.vtballoon.0.desired: 0
The QEMU monitor reported the maximum memory, but did not reflect the configured balloon size:
info balloon
balloon: actual=24384 max_mem=24384
Setting it manually released the unused memory immediately:
balloon 4096
info balloon
balloon: actual=4096 max_mem=24384
Automated workaround
Because the QEMU monitor is interactive, I used expect to send the command:
#!/usr/bin/expect -f
spawn qm monitor 108
expect "qm>"
send "balloon 4096\r"
expect "qm>"
send "quit\r"
expect eof
The script can be run hourly with cron:
0 * * * * /path/to/balloonfix.sh
Conclusion
QEMU may fail to communicate an updated balloon target to some FreeBSD 14 guests. A small monitor automation restored predictable host memory usage in this setup.