Bug 198344 - [virtio] virtio-balloon does not work
Summary: [virtio] virtio-balloon does not work
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.3-RELEASE
Hardware: amd64 Any
: --- Affects Some People
Assignee: Roger Pau Monné
Depends on:
Reported: 2015-03-06 09:38 UTC by Jan Henke
Modified: 2017-03-30 23:31 UTC (History)
6 users (show)

See Also:
koobs: mfc-stable10+

graph of memory usage of my VM (27.63 KB, image/png)
2016-05-05 16:17 UTC, Vick Khera
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Henke 2015-03-06 09:38:35 UTC
I am running FreeBSD in a Linux/KVM environment with the -balloon virtio flag passed to qemu.

The virtio-balloon kernel module gets loaded:
jan@vm03 ~ $ kldstat -v | grep virtio
		460 virtio_pci/virtio_scsi
		459 virtio_pci/virtio_balloon
		458 virtio_pci/virtio_blk
		457 virtio_pci/vtnet
		456 pci/virtio_pci
		455 virtio

But there is no ballooning at all. The VM allocates all the memory up to the specified maximum from the host, no matter how much memory is actually in use inside FreeBSD.

Expected result would be that the VM only allocates as much memory from the host as it actually uses right now. This works with Linux guests, but not FreeBSD ones.

For reference the complete qemu command line:
qemu-system-x86_64 -enable-kvm \
-cpu host \
-smp cores=4,threads=2 \-drive file=/var/kvm/disks/vm03.img,if=virtio \-net tap,ifname=tap_br1_3,script=no,downscript=no -net nic,model=virtio,macaddr=0e:77:77:0e:0e:03 \
-m 4G \
-balloon virtio \
-vga std \
-display vnc=:3 \
-monitor stdio \
-name "VM 03" \
-usbdevice tablet \
-k de
Comment 1 Bryan Venteicher freebsd_committer 2015-03-15 20:15:42 UTC
The guest balloon inflation and deflation is a manual process. IIRC, it can be controlled by either the qemu monitor or virsh setmem commands.
Comment 2 Jan Henke 2015-03-15 21:33:11 UTC
(In reply to Bryan Venteicher from comment #1)

As explained in the initial report that is not the case with Linux guest, there it is automatic and needs no user intervention.

If it is currently manual in FreeBSD, please add an automatic mode.
Comment 3 Vick Khera 2015-09-08 14:06:50 UTC
I observe this as well (FreeBSD 10.2), except the freebsd guest does not allocate all the allowed memory at start; it will grow up to the max memory then never shrink. Linux VM's shrink to allow better utilization of the host RAM.
Comment 4 Jan Henke 2015-09-12 21:13:49 UTC
With 10.2 I see the same behaviour as Vick. The FreeBSD no longer allocates up to the maximum at boot, but it does not release unused memory either.

Would be nice to implement full ballooning in FreeBSD.
Comment 5 Brad Davis freebsd_committer 2015-12-29 16:19:53 UTC
It looks like this might be at least partially addressed in r267858.  Trying to get it MFCed for 10.3.
Comment 6 Roger Pau Monné freebsd_committer 2015-12-29 16:25:48 UTC
I'm currently running a tinderbox with a backport of r267858, if everything goes fine I will commit it.
Comment 7 Brad Davis freebsd_committer 2016-04-12 20:19:41 UTC
It looks like this should be fixed in this MFC:


Can someone test 10.3 and let us know?
Comment 8 Vick Khera 2016-05-05 16:17:04 UTC
Created attachment 169998 [details]
graph of memory usage of my VM

I've been watching my 10.3 VM for a while now, and I finally found evidence that it did release some memory. The VM environment is Proxmox VE, which is basically a fancy pants GUI on top of Debian linux + KVM.

The memory usage graph is attached.
Comment 9 Kubilay Kocak freebsd_committer freebsd_triage 2017-03-30 23:31:56 UTC
Assign to committer that resolved (royger, r267858, MFC 10-STABLE: r292906)