Hi. I am writing a custom memory metering for my Qubes desktop – I want a gauge meter that would provide me the answer to a simple question: how much free memory is available for new VMs? Any hints how to deduce this from dom0/xenpm data? Clearly adding up all VM %'s from xentop does not help much, need a better formula.
The command xl info
displays some information like
total_memory : 32694
free_memory : 146
But it’s not entirely correct because free_memory doesn’t account the memory that could be freed using ballooning. With the output above, it seems I only have 146 MB of free memory, but I was able to boot a 3GB qube.
Doing the sum of all qubes consumed memory didn’t help either xl list | awk 'NR > 1 { sum=$3+sum } END { print sum }'
because it was the same result as total_memory - free_memory, at least the numbers are consistent.
If you don’t use ballooning at all, this should be accurate though.
(I hope someone can come up with a better solution :D)
Exactly, tried all that and desperately looking for a better option
This should be pretty accurate to give you the memory used in MB
( for i in $(virsh list | awk 'NR>3 { print $1 }') ; do virsh dommemstat $i | grep ^available ; done ; virsh dommemstat 0 | grep ^actual ) | awk 'NR > 1 { sum=sum+$2 } END { print sum/1024 }'
This is accounting the “start” memory of each VM, so it’s not accounting memory used in ballooning (that doesn’t mean you can always reclaim it though), and the “actual” memory of dom0 because it’s the opposite for dom0 which started with all the memory but then had less over time.
This is slow, I don’t recommend running it too often, and it requires root
Hm. It gives me 76Gb on my 64Gb box. There is some CoW or whatever that calculates incorrectly.