QEMU Linux guest tweaks

As per my previous post, I prefer to split my activities across different virtual machines. In this I am definitely influenced by my stint at Nutanix in 2019-2020: the company sells enterprise virtualization solutions. As such, it comes as no surprise that I use the same underlying technology instead of ESXI or Hyper-V.

Like most open-source solutions, QEMU isn't particularly user-friendly, even if one uses the GUI (virt-manager) to configure VMs. Although it's trivial to create VMs, the default parameters are extremely conservative to ensure any host/guest combination will work, and there's no hand-holding when it comes to fine-tuning the configuration.

The best sources of advice I found are ArchWiki (as usual) and Mathias Hüber's blog. Naturally, the below might work or not work properly with your hardware, so good luck!

CPU

  • If there are enough physical cores, CPU pinning will improve CPU cache utilization.
  • I found that disabling HPET timer helped reduce host CPU usage when the VM is idle.

Networking

  • Create a bridge interface on the host (according to this SUSE man page in my case).
  • In virt-manager, select "Bridge device" network source and virtio device model.

Graphics

The following applies to Linux guests only, and there's also a catch: QEMU doesn't support saving such VMs, so you'll have to fully shutdown them if you want to reclaim memory for other purposes. In my setup, this change also increased power consumption by the integrated GPU (Vega 8) compared to the default QXL driver.

  • Enable OpenGL and set "Listen type" to None in the Display Spice section.
  • In the Video section, select virtio again and enable 3D acceleration.

Here's a more comprehensive guide along with some benchmarks:
https://ryan.himmelwright.net/post/virtio-3d-vms/

Sound

Follow this recipe to make the guest use the host PulseAudio process: https://mathiashueber.com/virtual-machine-audio-setup-get-pulse-audio-working/
Note: you needn't reboot after adding apparmor rules, just systemctl reload apparmor.