Skip to main content

CPU Pinning

How to do CPU pinning (work in progress)

Create a file under /etc/pve/qemu-server/$vmid.cpuset for the VM which you want to set the CPU pinning for.

Examples:

0-1
0-1,6-7

 

Depending on your CPU topology assign the proper cores to your VM. You can find the topology out by running lscpu -e

Next create a file called taskset-hook.sh and save it under /var/lib/vz/snippets/, create the snippets folder if it's not there already and make the script executable.

Content:

#!/bin/bash

vmid="$1"
phase="$2"

if [[ "$phase" == "post-start" ]]; then
    main_pid="$(< /run/qemu-server/$vmid.pid)"

    #cpuset="0-11"
    cpuset="$(< /etc/pve/qemu-server/$vmid.cpuset)"

    taskset --cpu-list  --all-tasks --pid "$cpuset" "$main_pid"
fi