KVM: maximum number of cores and amount of memory for VMs

I have a new 8 core machine with 16GB of RAM. I want to run VMs on it using Ubuntu and KVM. Nothing else but SSH will be running on the host.

My question is what is the maximum amount of cores and of RAM which I can use for the VMs. Can I create 4 VMs and assign 2 cores and 4GB RAM each? Will the host OS have problems with such setup?

Stated in other way, what is the minimum amount of cores and RAM which is needed for the host to run the VMs? Will 1 core and 1GB of RAM be enough to run the VMs.


Solution 1:

there is no maximum as such, same as there is no real maximum for memory. You need to keep in mind the following:

  • A KVM v-CPU to a host is just a thread in the KVM process. If you run more threads than you have physical cores, they will be competing for those cores, and the host scheduler will have to take care of giving them CPU time
  • Avoid allocating more v-CPUs to a single VM that you have physical cores in a host.
  • Do not count HT cores as real cores.
  • If possible, do not allocate more v-CPUs to all of the VMs you are running than you have physical cores, if CPU time on the VMs is critical. However, on less busy systems, you can easily overallocate up to some really insane ratios (I've seen a system with 8 cores running 150 mostly idle VMs with 2 cores each with no problems)

As for the RAM allocation, this is basically the same line of thought:

  • a VM is just another process to the host, and the process will have a memory limit it can use
  • If you try to use more RAM that you actually have, you will end up in swap, which is dead slow compared to RAM
  • KVM provides ways to overallocate memory - there's balooning and KSM for that.

So, having said that, you need to consider what your VMs will absolutely require (don't just give a VM 4 cores because you can, give it the minimum it needs to run, and add more later if you see performance issues).
Be careful with memory allocation - you never want to end up in swap.