2

I am using libvirt version 6.0.0 on Ubuntu 20.04.4 LTS to manage my KVM VMs. I want to change a number of cores of the VM lively using virsh CLI. I have seen that by using virsh setvcpus VM_name number_of_core --live I can do this. Here is my output about it from the host OS.

Step 1. I spun up my VM with 1 core. Here is vcpu info of the VM.

host$ virsh vcpuinfo ubuntu_18_04_guest4
VCPU:           0
CPU:            14
State:          running
CPU time:       25.8s
CPU Affinity:   yyyyyyyyyyyyyyyy
  1. I change a number of cores of the VM from 1 core to 2 cores.
host$ virsh setvcpus ubuntu_18_04_guest4 2 --live
  1. I check the number of cores of the VM
host$ virsh vcpuinfo ubuntu_18_04_guest4
VCPU:           0
CPU:            2
State:          running
CPU time:       65.5s
CPU Affinity:   yyyyyyyyyyyyyyyy

VCPU: 1 CPU: 0 State: running CPU Affinity: yyyyyyyyyyyyyyyy

On the host side, it looks like it works. Now, I am moving to the guest OS side. Here is the output when the VM is first spun up with 1 core. enter image description here

As we see, there is 1 core because we started the VM with 1 core. Now, I attach the screenshot after I increased the number of cores to 2. enter image description here

As we see, I do not see this increase on the guest side although I see it on the host side. I now reboot the VM.

guest$ sudo reboot

I attach htop output after rebooting the VM. enter image description here

Now previously allocated 2 cores are effective in the guest machine.

To conclude, even if I do live core allocation to VM on the host side, I needed to reboot the VM to make it effective. In this case, what is the reason for the live core allocation?

Thank you,

Mehmet
  • 107
  • 1
  • 1
  • 7

1 Answers1

3

x86 does not auto-detect for new CPUs, you'd need to tell the guest to set it online. That could be done via: echo 1 > /sys/devices/system/cpu/cpuX/online.

Some use a udev rule like ACTION=="add", SUBSYSTEM=="cpu", ATTR{online}="1" to do this automatically.

There are also limits via the kernel parameter maxcpus (at boot time) and smp which could disable it alltogether. If in doubt have a look at all entries marked [SMP] in that document.

After answering I realized that it was discussed in other questions already, using other terms there, but the same answers.

Christian Ehrhardt
  • 2,195
  • 16
  • 22