Configure CPU Pinning (Nova)

Problem

Configure dedicated CPU cores pinned to instances for improved performance.

Environment

  • Platform9 Managed OpenStack - v3.4.0 and Higher

  • Nova

Procedure

  1. On each Compute node, edit /opt/pf9/etc/nova/conf.d/nova.conf and add vcpu_pin_set under the DEFAULT section. Set the vcpu_pin_set value to a list or range of physical CPU cores to reserve for virtual machine processes. If the number of cores is 8 then set aside cores 0 and 1 for the host, and assign cores 2 through 7 for instances.

vcpu_pin_set=2-7
  1. Set the reserved_host_memory_mb to reserve RAM for host processes.

reserved_host_memory_mb=2048

Note: By default, this value is set to 512 MB.

  1. To restrict the host process from using the vcpu, add the isolcpus kernel argument to the GRUB configuration so that the kernel is aware of the pinning. Append isolcpus=2,3,4,5,6,7 to GRUB_CMDLINE_LINUX in /etc/default/grub, without modifying any existing arguments.

  2. Rebuild grub.

# grub-mkconfig -o /boot/grub2/grub.cfg
  1. Reboot the node.

  2. From the UI, create a host aggregate and add all the nodes with pinning configured. Along with that, add the metadata with key as pinned and value as true.

  3. Within the UI, create a new flavor and add the following metadata/specifications to it.

hw:cpu_policy -> dedicated
aggregate_instance_extra_specs:pinned -> true
  1. Launch an instance using the newly created flavor.

  2. To verify the CPU(s) pinned to the instance, first identify the instance from the virsh list output.

# virsh list Id
Name State
----------------------------------------------------
7 773fcf47-07e4-4e07-b681-ee2c39727666 running
8 5a80a581-7259-4c6e-82c4-8cbb48100186 running
After identifying the instance, pass its ID to the virsh vcpupin command:
# virsh vcpupin 8
VCPU: CPU Affinity
----------------------------------
0: 3

Note: In the example above, the instance only has 1 CPU; and it's assigned to NUMA node 0 and core 3.