CPU optimization between two VMs

When I understand this correctly you use all of the available 12 Cores for either the emulation or computation of the gaming VM. Simultaneously your other VM as well as all the threads of you host operating system will have to be scheduled on some of these cores as well. That means both the host OS as well as any other VMs may interfere with your games while they compete for resources. Pinning only means that your gaming VM will run on the cores specified, but it is no isolation. Other threads can be scheduled on these cores as well.

What I would do is limit the gaming VM to 6 cores, plus an additional 1 or 2 cores for emulation and IO. Then install vfio-isolate to shield the gaming VM from the rest of the system. vfio-isolate can reserve the specified cores for the gaming VM and keep the host as well as any other VMs from accessing them.

You can initiate vfio-isolate via a qemu hook like the following example for a 16 Core processor with a VM called gaming on the last 8 cores ,in /etc/libvirt/hooks/qemu:

#!/bin/bash

if [ "$1" != "gaming" ]; then
	exit 0
fi

RSET=/

HSET=/host.slice
HNODE=C0-6,16-22

MNODE=C8-15,24-31

UNDOFILE=/var/run/libvirt/qemu/vfio-isolate-undo.bin

disable_isolation () {
	vfio-isolate \
		restore $UNDOFILE

	taskset -pc 0-31 2
}

enable_isolation () {
	vfio-isolate cpuset-delete $HSET

	vfio-isolate \
		-u $UNDOFILE \
		drop-caches \
		cpuset-create --cpus $HNODE $HSET \
		compact-memory \
		move-tasks $RSET $HSET \
		cpu-governor performance $MNODE \
		irq-affinity mask $MNODE

	taskset -pc 0-6,16-22 2
}



case "$2" in
"prepare")
	enable_isolation
	;;
"started")
	;;
"release")
	disable_isolation
	;;
esac

Edit: vfio-isolate is available in the AUR

Edit: If you need further help setting this up, ping me!

4 Likes