Previous page

Next page

Locate page in Contents

Print this page

Configuring CPU Affinity for Virtual Machines and Containers

If your physical server has several processors 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 . Establishing CPU affinity between virtual machines and Containers and physical processors can help you increase your system performance up to 20%.

By default, any newly created virtual machine and 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 pctl set command. Assuming that your physical server has 8 CPUs, you can make the processes in the MyVM virtual machine and Container 101 run on CPUs 0, 1, 3, 4, 5, and 6 by running the following commands:

# pctl set MyVM --cpumask 0,1,3,4-6

The VM has been successfully configured.

# pctl set 101 --cpumask 0,1,3,4-6 --save

Saved parameters for Container 101

You can specify the CPU affinity mask—that is, the processors to bind to virtual machines and Containers—as separate numbers (0,1,3) or as 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 MyVM virtual machine and Container 101 and set their processes to run on all available CPUs on the server, run these commands:

# pctl set MyVM --cpumask all

The VM has been successfully configured.

# pctl set 101 --cpumask all --save

Saved parameters for Container 101