Tuning VM disk performance for a passthrough setup (host on zfs)

The entirety of this post is thanks to /u/mercenary_sysadmin on reddit (post 1) (post 2, with benchmarks). Plenty of beers on me if you see this and are ever in Singapore.

Cliffnotes version for me to remember:

Gaming VM

1
2
3
4
zfs set recordsize=16K
qemu-img create -f qcow2 games.qcow2 500G -o cluster_size=16K
# zfs set compression=lz4 # already inherited
zfs set atime=off tank/vm

Here’s a benchmark from CrystalDiskMark with the above created image:

Disk is attached to the VM as:

1
2
3
-device virtio-scsi-pci,id=scsi0 \
-device scsi-hd,bus=scsi0.0,drive=rootfs \
-drive id=rootfs,file=/tank/vm/games.qcow2,id=disk,format=qcow2,if=none

Photography

1
2
3
zfs set recordsize=1M
zfs set atime=off tank/photos
zfs set xattr=sa tank/photos