This post illustrates the steps about how to increase KVM guest vCPU. There are two methods to increase KVM guest vCPUs: on the fly and offline. Let us see the steps for each of the method below.
Increase KVM guest vCPUs online
1. Check the current KVM guest vcpu/memory on KVM host:
[root@kvm-host]# virsh dumpxml kvm-guest | grep vcpu <vcpu placement='static'>1</vcpu>
[root@kvm-host]# virsh dominfo kvm-guest Id: - Name: kvm-guest UUID: 8f6fc48c-a6f4-429d-b77e-88a4b8d3d961 OS Type: hvm State: shut off CPU(s): 1 Max memory: 8392704 KiB Used memory: 8392704 KiB Persistent: yes Autostart: disable Managed save: no Security model: selinux Security DOI: 0
2. Set the maximum vCPUs for the KVM guest. In this example, we set the maximum of vCPU of the Guest VM as a value of 2:
[root@kvm-host]# virsh setvcpus kvm-guest 2 --config --maximum
3. Check if the maximum of vCPU setting takes effect. Here is the vCPU XML format:
<vcpu placement='static' current='N'>M</vcpu>
Where N is the currently enabled number of CPUs and M is the maximum number of CPUs.
[root@kvm-host]# virsh dumpxml kvm-guest | grep -i vcpu <vcpu placement='static' current='1'>2</vcpu>
4. Increase the vCPU from 1 to 2 using virsh command:
[root@kvm-host]# virsh setvcpus kvm-guest 2
5. Check if adding vCPU completes:
From KVM host:
[root@kvm-host]# virsh dominfo kvm-guest Id: 11 Name: kvm-guest UUID: 8f6fc48c-a6f4-429d-b77e-88a4b8d3d961 OS Type: hvm State: running CPU(s): 2 CPU time: 13.9s Max memory: 8392704 KiB Used memory: 8392704 KiB Persistent: yes Autostart: disable Managed save: no Security model: selinux Security DOI: 0 Security label: system_u:system_r:svirt_t:s0:c191,c578 (enforcing)
From KVM guest:
[root@localhost ~]# tail -f /var/log/messages checking TSC synchronization [CPU#0 -> CPU#1]: Measured 143005979072 cycles TSC warp between CPUs, turning off TSC clock. Please try to boot with tscsync Marking TSC unstable due to check_tsc_sync_source failed kvm-clock: cpu 1, msr 0:28314b81, secondary cpu clock
[root@localhost ~]# lscpu Architecture: x86_64 CPU op-mode(s): 64-bit CPU(s): 2 Thread(s) per core: 1 Core(s) per socket: 1 CPU socket(s): 2
6. Save the VM configuration if you want to make this changes persistent.
[root@kvm-host]# virsh setvcpus kvm-guest 2 --config
Increase KVM guest vCPUs offline
This method needs to arrange downtime for the Guest VM:
1. Shutdown the Guest VM:
[root@kvm-host]# virsh list Id Name State ---------------------------------------------------- 10 kvm-guest running
[root@kvm-host]# virsh destroy 10 Domain 10 destroyed
[root@kvm-host]# virsh list Id Name State ----------------------------------------------------
2. Update the required number of vCPU:
# virsh edit guest_vm
In this example, we increase vCPU from 2 to 4:
[root@j-kvm-host opc]# virsh edit kvm-guest
From:
<memory unit='KiB'>8392704</memory> <currentMemory unit='KiB'>8392704</currentMemory> <vcpu placement='static'>2</vcpu>
To:
<memory unit='KiB'>8392704</memory> <currentMemory unit='KiB'>8392704</currentMemory> <vcpu placement='static'>4</vcpu>
3. Boot the guest VM and check if the increasing vCPU takes effect:
[root@j-kvm-host opc]# virsh start kvm-guest
4. Verify the new CPU resources:
From KVM host:
[root@kvm-host]# virsh dominfo kvm-guest Id: 12 Name: kvm-guest UUID: 8f6fc48c-a6f4-429d-b77e-88a4b8d3d961 OS Type: hvm State: running CPU(s): 4 ...
From KVM guest:
[root@localhost ~]# lscpu Architecture: x86_64 CPU op-mode(s): 64-bit CPU(s): 4 Thread(s) per core: 1 Core(s) per socket: 1 CPU socket(s): 4 NUMA node(s): 1 Vendor ID: GenuineIntel ...