8.6 Dedicating CPU Resources

In Xen it is possible to specify how many and which CPU cores the Domain0 or VM Guest should use to retain its performance. The performance of Domain0 is important for the overall system as the disk and network drivers are running on it. Also I/O intensive guests' workloads may consume lots of Domain0′s CPU cycles. On the other hand, the performance of VM Guests is also important to be able to accomplish the task they were set up for.

8.6.1 Domain0

Dedicating CPU resources to Domain0 results in a better overall performance of the virtualized environment because Domain0 has free CPU time to process I/O requests from VM Guests. Failing to dedicate exclusive CPU resources to Domain0 usually results in a poor performance and can cause the VM Guests to function incorrectly.

Dedicating CPU resources involves three basic steps: modifying Xen boot line, binding Domain0's VCPUs to a physical processor, and configuring CPU related options on VM Guests:

First you need to append the dom0_max_vcpus=X to the Xen boot line in /boot/grub/menu.lst, where X is the number of VCPUs dedicated to Domain0. An example Kernel boot entry follows:

title Xen -- SUSE Linux Enterprise Server 11 SP2 - 3.0.4-0.11
root (hd0,1)
kernel /boot/xen.gz dom0_max_vcpus=2
module /boot/vmlinuz-3.0.4-0.11-xen
module /boot/initrd-3.0.4-0.11-xen

Restart the Xen Kernel for the change to take effect.

The next step is to bind (or pin) each Domain0's VCPU to a physical processor.

xm vcpu-pin Domain-0 0 0
xm vcpu-pin Domain-0 1 1

The first line binds Domain0's VCPU number 0 to the physical processor number 0, while the second line binds Domain0's VCPU number 1 to the physical processor number 1.

Lastly, you need to make sure no VM Guest uses the physical processors dedicated to VCPUs of Domain0. Assuming you are running a 8-CPU system, you need to add


to the configuration file of the relevant VM Guest.

8.6.2 VM Guests

It is often needed to dedicate specific CPU resources to a virtual machine. By default, a virtual machine uses any available CPU core. Its performance can be improved by assigning a reasonable number of physical processors to it as other VM Guests are not allowed to make use of them after that. Assuming a machine with 8 CPU cores while a virtual machine needs to use 2 of them, change its configuration file as follows:


The above example dedicates 2 processors to the VM Guest, and it is exactly the 3rd and 4rd one (2 and 3 counted from zero). If you need to assign more physical processors, use the cpus="2-8" syntax.

If you need to change the CPU assignment for a guest named alice in a hotplug manner, do the following on the related Domain0:

xm vcpu-set alice 2
xm vcpu-pin alice 0 2
xm vcpu-pin alice 1 3

The example will dedicate 2 physical processors to the guest, and bind its VCPU 0 to physical processor 2 and VCPU 1 to physical processor 3. Now check the assignment:

xm vcpu-list alice
Name                              ID VCPUs   CPU State   Time(s) CPU Affinity
alice                             4     0     2   -b-       1.9 2-3
alice                             4     1     3   -b-       2.8 2-3