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:
Is there a tool which helps me to find a matching maximum value?
Example:
- 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 tovirsh #
. Then, you can use thelist
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: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 withman virsh
.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 withdefault_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.Here is my hacky version. Ideas how to improve it, are welcome:
List the amount of RAM in kiB every VM needs:
Sum of RAM used by VMs
Available physical VM:
How much is left for the operating running the VM:
... not much left for the hypervisor.
Again: Ideas how to improve it, are welcome!