I have a hypervisor which uses kvm and virt-manager to handle the virtual machines.

The hypervisor has 6GByte of memory.

If I add a new virtual machine I don't know how much memory is still free.

At least the virt-manager dialog does not show it:

enter image description here

Is there a tool which helps me to find a matching maximum value?


  • 6 GB total host memory
  • 2 GB given to host "host-one"
  • ? GB for host "host-two".

Above is only a simple example. On our real servers we have much more virtual-hosts.

I am afraid to give too much memory to the virtual-hosts. This results in heavy performance impact if the hypervisor has too few. If I would give "host-two" 4GB, then the hypervisor would be "on fire", since it has "no air to breath".

Is there a tool which can help me to decide how much memory is available?


As the Redhat documentation you linked about overcommitting memory says,

"Guest virtual machines running on a KVM hypervisor do not have dedicated blocks of physical RAM assigned to them. Instead, each guest virtual machine functions as a Linux process where the host physical machine's Linux kernel allocates memory only when requested."

This makes the whole situation of determining how much RAM you can/should allocate to each host a little fuzzy, unfortunately. One tool you can use to view allocated memory among VMs is virsh and its freecell command.

The man page for virsh states that freecell, "Prints the available amount of memory on the machine or within a NUMA cell. The freecell command can provide one of three different displays of available memory on the machine, depending on the options specified...."

For KVM-based hypervisors, you can use the virtual machine shell command (virsh) in a terminal to enter the virtual shell -- your prompt should change from its default to virsh #. Then, you can use the list command to display a list of virtual machines on the hypervisor.

To display the amount of memory per VM (by its number shown by the list command), use:

virsh # freecell <cell_number> 

You can also pass the --all flag instead of a cell number to show the amount of memory allocated for each of the VMs and for the entire machine.

This should give you a good idea of the total memory you're working with and how much is allocated to each VM. If you decide that you'd like to change the amount of memory allocated, virsh also provides the setmem command to change the memory allocation for a guest domain. It's similar to the interface provided by virt-manager, but provides more options and flexibility. You can find all of the command options and descriptions with man virsh.

  • You write that the number of the VM can be passed to the freecell command, half of your answer is based on this premise. However, this is false. freecell only takes NUMA cells as an argument and shows free memory on the host - not the VM. – vic May 1 '18 at 11:25

If you want to be really safe and not overcommit memory, an alternative is to enable huge pages on your host and make your virtual machines use them. The downside is that you really need to have all the memory you need - host memory and VM memory will be basically separated.

You can have better control over how huge pages are used if you disable anonymous hugepages (boot with transparent_hugepages=never) and then you can assign as big a pool of hugepages as you like (boot with default_hugepagesz=2M hugepagesz=2M hugepages=2560 for 5GB of memory and leaving 1GB to the host OS).

You'll also need to also add this to your VM definition.


And to answer your question, if you use hugepages, the "how much memory" will be answered by grep ^Huge /proc/meminfo. Here is an example with 60G reserved for VMs, and about 600MB still available.

> grep ^Huge /proc/meminfo
HugePages_Total:   30000
HugePages_Free:      304
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

Here is my hacky version. Ideas how to improve it, are welcome:

List the amount of RAM in kiB every VM needs:

hypervisor5:~ # for dom in $(virsh list --all --name); do echo $(virsh dumpxml $dom | sed -nre 's/^.*>([0-9]*)<.currentMemory.*$/\1/p') $dom ; done| sort -n
524288 testfoo
2146304 x131
3121152 y114
3121152 foo
4096000 y123
4194304 mac-test
6144000 x123

Sum of RAM used by VMs

hypervisor5:~ # for dom in $(virsh list --all --name); do virsh dumpxml $dom | sed -nre 's/^.*>([0-9]*)<.currentMemory.*$/\1/p' ; done| awk '{s+=$1} END {print s}'

Available physical VM:

hypervisor5:~ # cat /proc/meminfo | grep MemTotal
MemTotal:       24797436 kB

How much is left for the operating running the VM:

hypervisor5:~ # python -c 'print 24797436-23347200'
1450236 (kiB)

... not much left for the hypervisor.

Again: Ideas how to improve it, are welcome!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.