3.1.2. Configuring CPU Affinity for Virtual Machines and Containers

If your physical server has several CPUs installed, you can bind a virtual machine or container to specific CPUs so that only these CPUs are used to handle the processes running in the virtual machine or container. The feature of binding certain processes to certain CPUs is known as CPU affinity.

By default, any newly created virtual machine or container can consume the CPU time of all processors installed on the physical server. To bind a virtual machine or container to specific CPUs, you can use the --cpumask option of the prlctl set command. Assuming that your physical server has 8 CPUs, you can make the processes in the virtual machine MyVM and the container MyCT run on CPUs 0, 1, 3, 4, 5, and 6 by running the following commands:

# prlctl set MyVM --cpumask 0,1,3,4-6
# prlctl set MyCT --cpumask 0,1,3,4-6

You can specify the CPU affinity mask—that is, the processors to bind to virtual machines and containers—as separate CPU index numbers (0,1,3) or as CPU ranges (4-6). If you are setting the CPU affinity mask for a running virtual machine or container, the changes are applied on the fly.

To undo the changes made to the virtual machine MyVM and the container MyCT and set their processes to run on all available CPUs on the server, run these commands:

# prlctl set MyVM --cpumask all
# prlctl set MyCT --cpumask all