Imagine an enterprise having to correctly add dimension to all their systems right from the start. In my experience, this is very difficult. You will either underdimension it, and your customers will complain about performance at some point, or you will overdimension it, and then the machine will sit there, idling about, which is not optimal either. This is the reason hardware vendors have come up with hot-add
resources. This allows a system to have its CPUs, memory, and/or disks to be upgraded/increased without the need for a shutdown. A KVM implements a similar functionality for its guests. It allows you to increase the CPUs, memory, and disks on the fly.
The actual recipe is very simple to execute, but there are some prerequisites to be met.
In order to be able to add CPUs on the fly to a guest, the guest's configuration must support them.
There are two ways to achieve this:
--vcpus 2,maxvcpus=4
virsh
(which will be applied at the next boot) through the following command:~]# virsh setvcpus --domain <guestname> --count <max cpu count> --config --maximum
~]# virsh edit <guestname>
The last two options will require you to shut down and boot (not reboot) your guest as these commands cannot change the "live" configuration.
The guest's XML file must contain the following element with the subsequent attributes:
<domain type='kvm'> ... <vcpu current='2'>4</vcpu> ... </domain>
Here, current
indicates the number of CPUs in use, and the number within the node indicates the maximum number of vCPUs that can be assigned. This number can be increased but should never exceed the number of cores or threads in your host.
Let's add some CPUs to the guest.