Is it possible to change the number of VCPUs on a KVM virtual machine on Linux without stopping it first? The Linux kernel has calls for addition and removal of CPUs (CPU hotplug in the Kernel) for physical machines (on hardware that supports that) but I can't find anything on VMs and how to allocate more/fewer resources to running machines.


Yes, but only up to the maximum number of vCPUs in the virtual machine definition. Increasing the maximum number requires a shutdown.

For example, this VM has two vCPUs of a maximum 8. Increasing beyond 8 requires a shutdown.

  <vcpu placement='static' current='2'>8</vcpu>

In order to change the VCPU allocation, you do

sudo virsh setvcpus [vm_name] [num_vcpus] --current

From within the machine, running

sudo udevadm monitor -k

You'll see a series of messages similar to

KERNEL[836.518069] add      /devices/system/cpu/cpu4 (cpu)
KERNEL[836.518095] bind     /devices/system/cpu/cpu4 (cpu)
KERNEL[836.526936] add      /module/intel_rapl_perf (module)
KERNEL[836.534023] remove   /module/intel_rapl_perf (module)
KERNEL[836.561229] add      /module/intel_uncore (module)
KERNEL[836.568971] remove   /module/intel_uncore (module)
KERNEL[836.578821] add      /module/intel_cstate (module)
KERNEL[836.592990] remove   /module/intel_cstate (module)
KERNEL[836.603800] add      /module/intel_rapl (module)
KERNEL[836.604120] add      /devices/virtual/powercap/intel-rapl (powercap)
KERNEL[836.604967] remove   /devices/virtual/powercap/intel-rapl (powercap)
KERNEL[836.613034] remove   /module/intel_rapl (module)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.