Tuning VM Configurations
VM configuration tuning needs to be performed according to the mapping between GPUs and NUMA nodes.
Perform operations in this section on all the four VMs. vm0 corresponding to NUMA 1 is used as an example. For details about the mapping, refer to Querying PCIe Node Information of a GPU. You can download the VM tuning script according to Obtaining the Software Package.
- Open the VM XML file.
virsh edit vm0
- Press i to enter the insert mode and add the following content to </cputune> to configure the mapping between VM vCPUs and host CPUs.
The value of cpuset is the bound host CPU core ID. The value ranges from 0 to 79 for NUMA 0, from 80 to 159 for NUMA 1, from 160 to 239 for NUMA 2, and from 240 to 319 for NUMA 3.


You can also run the following command instead:
./setup_vm.sh vm0 --cputune 80,159
- Add the following content under </cputune> to bind the VM to the NUMA memory of the host. (In this example, NUMA 1 is bound to the VM.)
<numatune> <memory mode='strict' nodeset='1'/> </numatune>
You can also run the following command instead:./setup_vm.sh vm0 --numatune 1
- Add the following content above </cputune> to bind the QEMU emulator:
<emulatorpin cpuset='80-159' />

You can also run the following command instead:
./setup_vm.sh vm0 --emulatorpin 80-159
- Use huge pages. Add the content in the red box to the position shown in the following figure.
<memoryBacking> <hugepages/> </memoryBacking>
You can also run the following command instead:
./setup_vm.sh vm0 --enable_hugepages
- Enable CPU topology.
Find the content in the preceding figure and modify the text in the red box as follows:<cpu mode='host-passthrough' check='none'> <topology sockets='1' dies='1' clusters='10' cores='4' threads='2'/> </cpu>

- Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
- Start the VM.

- Run the following command on the VM. If 0-7 are displayed in the command output, CPU topology takes effect.
cat /sys/devices/system/cpu/cpu0/topology/cluster_cpus_list

- Run the following command to enable cluster scheduling optimization:
echo 1 > /proc/sys/kernel/sched_cluster
This step needs to be performed each time the VM is restarted. You are advised to write this step in a file such as ~/.bashrc for automatic execution after each restart.