How to increase the speed of a KVM/QEMU virtual machine

Hi, since 2 days I am using KVM/QEMU to virtualize other distros. I have always used Virtualbox but lately it didn’t work anymore, I had problem after problem. So, following a tip here on the forum I moved over to KVM.
At first I thought it works faster than VBox, but now that I am watching videos on Youtube or watching TV on the website of my provider I see that the system is not that fast. I know I don’t have a top of the line computer (I’m still looking for a new one with more capacity under the hood) but still when using host Tumbleweed the videos run faster and sound and picture are synchronized, something I don’t always see in the guest (Fedora 37 btw).

This is my hardware:

$ inxi -F
System:
  Host: localhost.localdomain Kernel: 6.2.6-1-default arch: x86_64 bits: 64
    Desktop: KDE Plasma v: 5.27.3 Distro: openSUSE Tumbleweed 20230318
Machine:
  Type: Laptop System: MEDION product: E15302 v: N/A
    serial: <superuser required>
  Mobo: MEDION model: NS15AP serial: <superuser required>
    UEFI: American Megatrends v: AP618_MED_V0.13.2_M00P1T0G0 date: 11/18/2020
Battery:
  ID-1: BAT0 charge: 44.1 Wh (98.0%) condition: 45.0/45.0 Wh (100.0%)
CPU:
  Info: quad core model: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
    bits: 64 type: MT MCP cache: L2: 2 MiB
  Speed (MHz): avg: 1395 min/max: 1400/2100 cores: 1: 1398 2: 1231 3: 1397
    4: 1400 5: 1397 6: 1259 7: 1681 8: 1400
Graphics:
  Device-1: AMD Picasso/Raven 2 [Radeon Vega Series / Radeon Mobile Series]
    driver: amdgpu v: kernel
  Display: x11 server: X.Org v: 21.1.7 with: Xwayland v: 22.1.8 driver: X:
    loaded: modesetting unloaded: fbdev,vesa dri: radeonsi gpu: amdgpu
    resolution: 1: 1920x1080~60Hz 2: 1920x1080~60Hz
  API: OpenGL v: 4.6 Mesa 23.0.0 renderer: AMD Radeon Vega 8 Graphics
    (raven LLVM 15.0.7 DRM 3.49 6.2.6-1-default)
Audio:
  Device-1: AMD Raven/Raven2/Fenghuang HDMI/DP Audio driver: snd_hda_intel
  Device-2: AMD ACP/ACP3X/ACP6x Audio Coprocessor driver: snd_pci_acp3x
  Device-3: AMD Family 17h/19h HD Audio driver: snd_hda_intel
  Sound API: ALSA v: k6.2.6-1-default running: yes
  Sound Server-1: PipeWire v: 0.3.67 running: yes
Network:
  Device-1: Intel Wireless 3165 driver: iwlwifi
  IF: wlp1s0 state: up mac: 34:cf:f6:40:ff:0b
  IF-ID-1: tun0 state: unknown speed: 10000 Mbps duplex: full mac: N/A
  IF-ID-2: virbr0 state: up speed: 10000 Mbps duplex: unknown
    mac: 52:54:00:0f:4e:dc
  IF-ID-3: vnet0 state: unknown speed: 10000 Mbps duplex: full
    mac: fe:54:00:58:48:03
Bluetooth:
  Device-1: Intel Bluetooth wireless interface type: USB driver: btusb
  Report: rfkill ID: hci0 state: up address: see --recommends
Drives:
  Local Storage: total: 476.94 GiB used: 354.12 GiB (74.2%)
  ID-1: /dev/sda vendor: Phison model: S11-512G-SSD-B27 size: 476.94 GiB
Partition:
  ID-1: / size: 23.46 GiB used: 13.67 GiB (58.3%) fs: ext4 dev: /dev/sda2
  ID-2: /boot/efi size: 63.8 MiB used: 4.9 MiB (7.7%) fs: vfat
    dev: /dev/sda1
  ID-3: /home size: 435.66 GiB used: 340.08 GiB (78.1%) fs: xfs
    dev: /dev/sda4
Swap:
  ID-1: swap-1 type: partition size: 17 GiB used: 371 MiB (2.1%)
    dev: /dev/sda3
Sensors:
  System Temperatures: cpu: 65.2 C mobo: N/A gpu: amdgpu temp: 65.0 C
  Fan Speeds (RPM): N/A
Info:
  Processes: 280 Uptime: 12h 52m Memory: 13.59 GiB used: 9.49 GiB (69.8%)
  Shell: Bash inxi: 3.3.23

I am using 6 out of 8 CPU cores and 8GB of ram. Should be enough I guess.

What I am looking for are the optimized settings I need to use for my KVM guest on the above hardware to make the guest look as fast as the host.
Which website is great for getting the right info about ow to setup the system?

@JanMussche are you using the qxl driver?

Hello again Malcom, I wasn’t. It was set to VirtIO. I now changed it to qxl. The picture moves better than before, although sound and picture are not completely synchronized. I will use this a while to see if it is really better.
I notice that the CPU is using 75% of its capacity. This is all caused by watching TV. When I freeze the program, CPU drops to around 10%.

I will have to do a lot of reading about KVM to get the most out of it. Thank you again for your help.

@JanMussche can you post the output from cat /proc/cmdline as there are some iommu options to try

Hi Malcolm,

The /proc/cmdline file in the host (Tumbleweed) looks like this:

cat /proc/cmdline 
BOOT_IMAGE=/boot/vmlinuz-6.2.6-1-default root=UUID=ce4c6aa7-3fd8-420f-840b-e400fc754b21 splash=silent resume=/dev/disk/by-uuid/5a81e1a6-2839-4685-83a8-25f4844539eb quiet security=apparmor usbcore.autosuspend=-1 mitigations=auto

The one in the guest (Fedora 37) looks like this:

cat /proc/cmdline 
BOOT_IMAGE=(hd0,gpt2)/vmlinuz-6.1.18-200.fc37.x86_64 root=UUID=566cf263-d5df-4729-90af-b84c80fcdafb ro rootflags=subvol=root rhgb quiet

I don’t know which one you want to see so I send both.
Thanks.

@JanMussche Have a read here: https://www.linux-kvm.org/page/Tuning_Kernel#Useful_options_for_the_kernel_of_the_host

Is IOMMU enabled on you host system?

journalctl -b | grep iommu

This is what I get:

sudo journalctl -b | grep iommu
[sudo] password for root: 
Mar 22 06:13:17 localhost kernel: iommu: Default domain type: Passthrough 
Mar 22 06:13:17 localhost kernel: pci 0000:00:01.0: Adding to iommu group 0
Mar 22 06:13:17 localhost kernel: pci 0000:00:01.2: Adding to iommu group 1
Mar 22 06:13:17 localhost kernel: pci 0000:00:08.0: Adding to iommu group 2
Mar 22 06:13:17 localhost kernel: pci 0000:00:08.1: Adding to iommu group 3
Mar 22 06:13:17 localhost kernel: pci 0000:00:08.2: Adding to iommu group 4
Mar 22 06:13:17 localhost kernel: pci 0000:00:14.0: Adding to iommu group 5
Mar 22 06:13:17 localhost kernel: pci 0000:00:14.3: Adding to iommu group 5
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.0: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.1: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.2: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.3: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.4: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.5: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.6: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:00:18.7: Adding to iommu group 6
Mar 22 06:13:17 localhost kernel: pci 0000:01:00.0: Adding to iommu group 7
Mar 22 06:13:17 localhost kernel: pci 0000:02:00.0: Adding to iommu group 8
Mar 22 06:13:17 localhost kernel: pci 0000:02:00.1: Adding to iommu group 9
Mar 22 06:13:17 localhost kernel: pci 0000:02:00.2: Adding to iommu group 9
Mar 22 06:13:17 localhost kernel: pci 0000:02:00.3: Adding to iommu group 9
Mar 22 06:13:17 localhost kernel: pci 0000:02:00.4: Adding to iommu group 9
Mar 22 06:13:17 localhost kernel: pci 0000:02:00.5: Adding to iommu group 9
Mar 22 06:13:17 localhost kernel: pci 0000:02:00.6: Adding to iommu group 9
Mar 22 06:13:17 localhost kernel: pci 0000:03:00.0: Adding to iommu group 10
Mar 22 06:13:17 localhost kernel: perf/amd_iommu: Detected AMD IOMMU #0 (2 banks, 4 counters/bank).
I will start reading the page you mentioned. Thanks.