SapphicCode/balloond

Issue on Libvirt 6.5.0

Opened this issue · 6 comments

Hi, i'm trying it on a Unraid server 6.9.2, with Libvirt 6.5.0
On my first try, I got the message "Libvirt is returning garbage statistics. Protecting ourselves."
Checking the code I found in domain.go, that you check this: "if current < available "
Using "virsh dommemstat" I've checked that the available value it will be always greater than current value (actual on my virsh).
So I change the comparison sign and it start working.
Idk if something change in the past 2 years, this is the output of the virsh command of a 8Gb VM, allocating only half the memory.

actual 4194304
swap_in 0
swap_out 0
major_fault 61
minor_fault 87934
unused 8040536
available 8145192
usable 7921156
last_update 1628808819
disk_caches 28468
hugetlb_pgalloc 0
hugetlb_pgfail 0
rss 4274492

From what I'm reading based on the code and #3, available used to be the statistic reported by the guest VM on how much memory it had free.

Don't know what it's doing now, but in all likelihood it's breaking my algorithm badly. Hence the check.

Edit: Apparently what my code calls "available" libvirt calls "usable". Actual < usable which is breaking the algorithm.

Yeah, I dedicate the day on the code but my conclusion is that this code must be on the kernel, when it try to alloc something and have no more memory it must ask to libvirt for more memory. It's the only way to be fast enough. But it's out of my league. Thanks for all. Have a nice day!

For my own future debugging sanity, here's the libvirt docs on this madness.

Oh crud I see the error.

The enum I'm looking at is Usable, the one I comment on is Unused.

Guess my IDE autocompleted and I didn't bother to check again.

So I'd have to take the domain's maximum balloon size and invert unused to figure out how much the memory needs messing with. Is your VM really only using ~100MB?

this values are from the libvirt console and the free from the VM. hope it help you!
$ virsh dommemstat Gentoo
actual 1500000
swap_in 0
swap_out 0
major_fault 63
minor_fault 86992
unused 8030052
available 8145192
usable 7910796
last_update 1628870577
disk_caches 28440
hugetlb_pgalloc 0
hugetlb_pgfail 0
rss 685152

$ free
total used free shared buff/cache available
Mem: 1256584 66992 1000708 404 188884 954964
Swap: 0 0 0

another one, but I don't see any change on the virsh side about the memory usage of the VM, there is something I'm not seeing?

$ virsh dommemstat Gentoo
actual 1500000
swap_in 0
swap_out 0
major_fault 63
minor_fault 86992
unused 8030052
available 8145192
usable 7910796
last_update 1628870577
disk_caches 28440
hugetlb_pgalloc 0
hugetlb_pgfail 0
rss 1364812

$ free
total used free shared buff/cache available
Mem: 1256584 230132 348816 404 677636 758060
Swap: 0 0 0