Is there anything else I can do to optimize Windows VM with GPU passthrough?

Arm1nas

Member
Feb 12, 2022
17
0
6
19
Hello, I have made a "Gaming" Windows VM with GPU passthrough and wanted to ask if there's anything I can do to make the VM more optimized?

Proxmox host specs:
CPU: AMD Ryzen 5 1600 (6 cores, 12 threads)
RAM: DDR4 64GB 3200MHz (2x 32GB) dual channel
SSD: 1TB NVMe SSD (all VM storage on this SSD)
Motherboard: Gigabyte B450 Gaming X (rev. 1.x)
GPU: RTX 3060 ti (passed through to Windows VM)

Windows 10 VM.
My Windows VM config:
Code:
root@proxmox:~# cat /etc/pve/qemu-server/102.conf
## CPU PIN
#cpu_taskset 2-11
#assign_interrupts 2-11 --all
##Set halt_poll_ns
#set_halt_poll 0
agent: 1
args: hv_vendor_id=GIGABYTE,+pdpe1gb' -smbios type=0,version=UX305UA.201 -smbios type=1,manufacturer=GIGABYTE,product=UX305UA,version=2021.1 -smbios type=2,manufacturer=AMD,version=2021.5,product='AMD Ryzen 5 1600' -smbios type=3,manufacturer=XBZJ -smbios type=17,manufacturer=KINGSTON,loc_pfx=DDR4,speed=3200,serial=114514,part=FF63 -smbios type=4,manufacturer=AMD,max-speed=4800,current-speed=3200
audio0: device=ich9-intel-hda,driver=none
balloon: 0
bios: ovmf
boot: order=virtio0;net0;ide2
cores: 10
cpu: host,hidden=1
cpuunits: 10000
efidisk0: local:102/vm-102-disk-0.raw,efitype=4m,pre-enrolled-keys=1,size=528K
hookscript: local:snippets/exec-cmds
hostpci0: 0000:07:00,pcie=1,x-vga=1
hotplug: usb
hugepages: 1024
ide2: local:iso/virtio-win-0.1.229.iso,media=cdrom,size=522284K
machine: pc-q35-8.1
memory: 24576
meta: creation-qemu=8.1.2,ctime=1704182629
name: wintest
net0: virtio=E8:2A:EA:9F:8A:1A,bridge=vmbr0,firewall=1
numa: 1
ostype: win10
scsihw: virtio-scsi-single
smbios1: uuid=24c326dd-3cec-48fc-bb9f-87aa3984e2c9,manufacturer=QVNVUw==,product=VVgzMDVVQQ==,version=MjAyMS4x,serial=MTI0NjY3,sku=MTM0NDY4,family=Ng==,base64=1
sockets: 1
tablet: 0
tpmstate0: local:102/vm-102-disk-1.raw,size=4M,version=v2.0
vcpus: 10
vga: none
virtio0: local:102/vm-102-disk-2.raw,cache=unsafe,iothread=1,size=400G
virtio1: /dev/disk/by-id/ata-WDC_WD10EZEX-00BBHA0_WD-WCC6Y7FUZN3L,size=976762584K,serial=4421
vmgenid: 12ff2d20-3979-404b-91b0-90bdb31cf66f

Proxmox GRUB config:
Code:
root@proxmox:~# cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on iommu=pt pcie_acs_override=downstream,multifunction default_hugepagesz=1G hugepagesz=1G"
GRUB_CMDLINE_LINUX=""

# If your computer has multiple operating systems installed, then you
# probably want to run os-prober. However, if your computer is a host
# for guest OSes installed via LVM or raw disk devices, running
# os-prober can cause damage to those guest OSes as it mounts
# filesystems to look for things.
#GRUB_DISABLE_OS_PROBER=false

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

Output of /etc/modprobe.d/kvm.conf:
Code:
options kvm ignore_msrs=1 report_ignored_msrs=0
 
I'm already using VirtIO SCSI
Your controller is "virtio SCSI single" but your disks are still using "virtio block" instead of "SCSI":
virtio0: local:102/vm-102-disk-2.raw,cache=unsafe,iothread=1,size=400G virtio1: /dev/disk/by-id/ata-WDC_WD10EZEX-00BBHA0_WD-WCC6Y7FUZN3L,size=976762584K,serial=4421


Also keep in mind that maximum optimization for performance comes at the cost of sacrificing stability and reliability. I for example wouldn't use "unsafe" cache mode. Have a power outage and you might lose the whole VM as all important secure sync writes will be handled as volatile async writes.
 
The best way to improve gaming performance would be to not virtualize the gaming.

I'm serious. You've given the VM 10 of 12 threads, almost half the RAM (which will be pinned because of the PCI pass-through), half your SSD (plus apparently an entire separate disk partition) and the GPU. So a majority of your machine's resources are given to this one VM. What exactly is the point of virtualization here?

It would make much more sense to run Windows directly on the hardware and use Hyper-V, which comes free with Windows, and actually works pretty well, to run whatever small VM's you've got on there doing whatever besides the gaming. Then when you need maximum performance you can easily shut those down and have the whole machine available. No muss, no fuss, no spending your life pinning CPU's and other nonsense.
 
  • Like
Reactions: UdoB
The best way to improve gaming performance would be to not virtualize the gaming.

I'm serious. You've given the VM 10 of 12 threads, almost half the RAM (which will be pinned because of the PCI pass-through), half your SSD (plus apparently an entire separate disk partition) and the GPU. So a majority of your machine's resources are given to this one VM. What exactly is the point of virtualization here?

It would make much more sense to run Windows directly on the hardware and use Hyper-V, which comes free with Windows, and actually works pretty well, to run whatever small VM's you've got on there doing whatever besides the gaming. Then when you need maximum performance you can easily shut those down and have the whole machine available. No muss, no fuss, no spending your life pinning CPU's and other nonsense.
I haven't given the windows VM a lot of resources because other VM's need it...
And I'm virtualizing Windows because I'm daily driving a linux laptop which is also not powerful enough to play games.

Also what was your point of telling me I didn't assign all available 12 threads? You would still need some left over for the host, same with other resources.
 
Last edited:
Your controller is "virtio SCSI single" but your disks are still using "virtio block" instead of "SCSI":



Also keep in mind that maximum optimization for performance comes at the cost of sacrificing stability and reliability. I for example wouldn't use "unsafe" cache mode. Have a power outage and you might lose the whole VM as all important secure sync writes will be handled as volatile async writes.
Oh right, I changed it to SCSI now, was a bit tricky with Windows not booting up, but I fixed it. Right now I'm just trying to gain max performance from the VM because it's quite laggy sometimes, the CPU spikes to 100% a lot, and I don't have any important data that I would lose, so the unsafe cache mode doesn't reallyy matter but maybe I will change it in the future.
 
I haven't given the windows VM a lot of resources because other VM's need it...
And I'm virtualizing Windows because I'm daily driving a linux laptop which is also not powerful enough to play games.

Also what was your point of telling me I didn't assign all available 12 threads? You would still need some left over for the host, same with other resources.
I think you completely missed my point. I am not suggesting how to make gaming perform better under Proxmox, I'm suggesting that Proxmox might be the wrong tool for the job.

If you play games that require high-performance real-time graphics, doesn't it make a lot more sense to configure the machine for the games you want to play first, and then virtualize other workloads that are not so performance-critical?

I get that a lot of people do what you're trying to do, you can tell from all the threads about games lagging and micro-stuttering and sound being out of sync and all kinds of other stuff that basically come down to KVM not being especially good at real-time things. I honestly can't figure out what the benefit is compared to doing it the other way around. Hyper-V runs Linux VM's just fine, and it will run them even if you aren't logged in just like Proxmox.

That way you get games that play like they are supposed to with minimal messing around, your home assistant or whatever can hide in the background, and you don't have to spend a bunch of time trying to optimize your way back to where you started in terms of gaming performance.

I mean, I dislike Microsoft as much as anyone but sometimes you have to be practical.
 
I think you completely missed my point. I am not suggesting how to make gaming perform better under Proxmox, I'm suggesting that Proxmox might be the wrong tool for the job.

If you play games that require high-performance real-time graphics, doesn't it make a lot more sense to configure the machine for the games you want to play first, and then virtualize other workloads that are not so performance-critical?

I get that a lot of people do what you're trying to do, you can tell from all the threads about games lagging and micro-stuttering and sound being out of sync and all kinds of other stuff that basically come down to KVM not being especially good at real-time things. I honestly can't figure out what the benefit is compared to doing it the other way around. Hyper-V runs Linux VM's just fine, and it will run them even if you aren't logged in just like Proxmox.

That way you get games that play like they are supposed to with minimal messing around, your home assistant or whatever can hide in the background, and you don't have to spend a bunch of time trying to optimize your way back to where you started in terms of gaming performance.

I mean, I dislike Microsoft as much as anyone but sometimes you have to be practical.
I understand what you're trying to say and I know that the performance won't be the same as bare metal. It's just interesting to mess around and also learn from things, and yes, I like to make my life hard by doing all of this, because it's just interesting, but my original post was how to optimize a Windows VM for better performance.
 
I understand what you're trying to say and I know that the performance won't be the same as bare metal. It's just interesting to mess around and also learn from things, and yes, I like to make my life hard by doing all of this, because it's just interesting, but my original post was how to optimize a Windows VM for better performance.
Ok, I get it. No offense intended.
 
Some hints from me also I'll try to keep it short...

To the "why" (@BobhWasatch):
  • Because windows is a moloch with which you don't want to share anything more serious you do personally (be it work or private) but you need it for gaming
  • Because it is fun
  • Because!
Over the past decades I found nearly every post/discussion that tries to shift away from the OPs actual topic by long arguments about the use case pointless. A short hint is more than enough if at all. Only because you cannot image a use case does not mean there is none. Typically people in tech are not stupid. OP asked so he will have a use case.

The https://forum.proxmox.com/threads/hey-proxmox-community-lets-talk-about-resources-isolation.124256/ post indeed looks great though!

I did not know that and still am currently running a Proxmox bare metal installation with a Windows Gaming VM in it's third generation. I started with the Nvidia 20x GPU family. And I can reassure I always got to the point that I only had around 5% performance overhead and an additional ~1-3ms input lag. So gaming on a Proxmox Windows Guest is absolutely possible. And at least for me my cap is my player skill and not the additional 1-3ms input lag (and I do play competitive shooters in the upper leagues).

However, input lag was my biggest struggle from my Gen 1 on and the only way get to these decent values was to pass through USB controllers directly as well. So @Arm1nas since I don't see USB controller passthrough in you're config yet, this would be my 'constructive' tip here ;-) Also once you have one or 2 controllers passed through, connect a DAC to it and safe you all the hassle that comes with near latency free sound otherwise.

It's still not an absolute perfect solution. Here are some problems I live with and other disclaimers:
  1. I always use Hardware on the upper end of the current generation so it's quite expensive (currently Ryzen 9 7950X, RTX 4090, X670E AORUS Master with maxed out RAM) but this might be the reason why it works quite well even without the suggestion from the previous mentioned thread.
  2. Getting a Mainboard were you really can pass through enough USB controllers is not easy. Get ready to replace some and build anew. Because even if the IOMMU groups look good (which you can somewhat google beforehand) there are USB controller which still will crash your system when passed through. Idk why but with trail and error I always found enough working ones. I wouldn't recommend my current mainboard though because even if it has 3 controllers I can pass through (the rest crashes) it is annoying af for RAM overclocking. I need to use very conservative RAM tackts only very little over the default to have a stable system, even with the latest BIOS :/
  3. Even with USB controller pass through there is a very small additional input lag but the before mentioned 1-3ms are usually really not a problem for competitive gaming. However, very demanding USB devices might not like it. For example I only had one system where the DAC worked flawless. Currently I have a small sound "crack" every around 15 min. You even can see it if you measure the USB data stream as small drop. This doesn't bother me at all but if you are audiophile it might bother you ;-)
 
Some hints from me also I'll try to keep it short...

To the "why" (@BobhWasatch):
  • Because windows is a moloch with which you don't want to share anything more serious you do personally (be it work or private) but you need it for gaming
  • Because it is fun
  • Because!
Over the past decades I found nearly every post/discussion that tries to shift away from the OPs actual topic by long arguments about the use case pointless. A short hint is more than enough if at all. Only because you cannot image a use case does not mean there is none. Typically people in tech are not stupid. OP asked so he will have a use case.

The https://forum.proxmox.com/threads/hey-proxmox-community-lets-talk-about-resources-isolation.124256/ post indeed looks great though!

I did not know that and still am currently running a Proxmox bare metal installation with a Windows Gaming VM in it's third generation. I started with the Nvidia 20x GPU family. And I can reassure I always got to the point that I only had around 5% performance overhead and an additional ~1-3ms input lag. So gaming on a Proxmox Windows Guest is absolutely possible. And at least for me my cap is my player skill and not the additional 1-3ms input lag (and I do play competitive shooters in the upper leagues).

However, input lag was my biggest struggle from my Gen 1 on and the only way get to these decent values was to pass through USB controllers directly as well. So @Arm1nas since I don't see USB controller passthrough in you're config yet, this would be my 'constructive' tip here ;-) Also once you have one or 2 controllers passed through, connect a DAC to it and safe you all the hassle that comes with near latency free sound otherwise.

It's still not an absolute perfect solution. Here are some problems I live with and other disclaimers:
  1. I always use Hardware on the upper end of the current generation so it's quite expensive (currently Ryzen 9 7950X, RTX 4090, X670E AORUS Master with maxed out RAM) but this might be the reason why it works quite well even without the suggestion from the previous mentioned thread.
  2. Getting a Mainboard were you really can pass through enough USB controllers is not easy. Get ready to replace some and build anew. Because even if the IOMMU groups look good (which you can somewhat google beforehand) there are USB controller which still will crash your system when passed through. Idk why but with trail and error I always found enough working ones. I wouldn't recommend my current mainboard though because even if it has 3 controllers I can pass through (the rest crashes) it is annoying af for RAM overclocking. I need to use very conservative RAM tackts only very little over the default to have a stable system, even with the latest BIOS :/
  3. Even with USB controller pass through there is a very small additional input lag but the before mentioned 1-3ms are usually really not a problem for competitive gaming. However, very demanding USB devices might not like it. For example I only had one system where the DAC worked flawless. Currently I have a small sound "crack" every around 15 min. You even can see it if you measure the USB data stream as small drop. This doesn't bother me at all but if you are audiophile it might bother you ;-)
Thanks for your input.
For clarification, my Proxmox host is running headless in another room and I'm accessing the VM remotely (Moonlight/Parsec), so USB passthrough is useless for me :)

Currently the Windows VM has a lot of CPU spikes and if I open an app that's more task-heavy, even the mouse cursor start lagging. However my Proxmox node also runs 2 other linux VM's and my CPU isn't that great, it's a bit of a bottleneck for an RTX 3060 ti but still, it shouldn't lag like this, so I think the issue lies in the Proxmox / VM configuration.
 
You probably also heavily modified that VM Config to hide that the Windows is running in a VM so Anti Cheat Software won't block you when playing multiplayer games? Because in that case I wouldn't wonder if those obfuscation strategies also might cost you some performance.
 
Over the past decades I found nearly every post/discussion that tries to shift away from the OPs actual topic by long arguments about the use case pointless. A short hint is more than enough if at all. Only because you cannot image a use case does not mean there is none. Typically people in tech are not stupid. OP asked so he will have a use case.
I have seen over and over that people get stuck on a particular approach and fail to look at alternatives that are significantly better by whatever metric might apply. Gaming in a VM is a use case where you can basically never win. it might be "good enough" for a lot of people, depending on the specific game. But it is never going to be optimal for games that require high-performance graphics and real-time control. It is always going to require more hardware resources than running on the bare metal.

Hence my suggestion to the OP. I don't think he's dumb, I just wanted to make sure he had thought about other options that would be less fragile and easier to get working.

If you're out for other goals like the learning experience then that's fine. Have at it.
 
Last edited:
Currently the Windows VM has a lot of CPU spikes and if I open an app that's more task-heavy, even the mouse cursor start lagging.
That sounds unbearable :d

But I remember this was pretty much the experience I also had with my first try and the RTX 2080 Ti system. And though it seemed like CPU related it just disappeared the moment I stopped USB and sound emulation and passed the controller to the VM. I also remember that as soon as there got "more sound" or faster music the VM started lagging and sometimes even freezed :c I understand though, that you want to keep the PC in a separate location. This would be my dream as well, just to have less noise and an even cleaner room :D I also always look at devices like https://www.kvm-concepts.de/produkt...ayport-1-2-4k-usb-2-0-fiber-kvm-extender-set/ when I build a new system but unfortunately they always are a little bit behind what I want to do (currently at least 4k gaming with 120 Hz upwards while this fiber DP extender only supports up to 60 Hz @ 4k). So I'm not quite there yet at the dream of having a gaming system located out of sight...

As for config I think I even use less options than you (for reference bellow my .conf of the VM). Obviously there are quite some other kernel command line options, module blacklistings etc. but they are not performance related and without those nothing would work at all. Since it's basically working for you, they shouldn't matter. The only other performance related thing I do is to ensure the CPUs are set to performance when the gaming VM starts since for some reason they aren't per default in my case:

Check the current mode: cat /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor
Maybe change it: echo "performance" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Regarding gaming, most publisher seem to come to agree that VMs are implicitly tolerated. I don't do much (all seen in my conf) and can play everything with that. And those values don't impact performance. What might impact performance would be if you couldn't use virtio drivers for example but no publisher seems to scan for something like that, since I use those.

But with that limitations the performance for me is as said like a bare metal experience since I cannot feel the difference between ~350 fps and ~370 fps :D But yes, these remaining somewhat 5% are always there. I always install a clean windows bare matel on a new system on which I do all benchmarks relevant for me and than compare that to my VM setup until I'm satisfied, so I have quite good idea of the performance I pay for the setup ;-)

args: -cpu 'host,+kvm_pv_unhalt,+kvm_pv_eoi,hv_vendor_id=proxmox,hv_spinlocks=0x1fff,hv_vapic,hv_time,hv_reset,hv_vpindex,hv_runtime,hv_relaxed,hv_synic,hv_stimer,hv_tlbflush,hv_ipi,kvm=off'
balloon: 0
bios: ovmf
boot: order=scsi0;ide2
cores: 30
cpu: host,hidden=1
cpuunits: 2048
efidisk0: local-zfs:vm-102-disk-4,efitype=4m,pre-enrolled-keys=1,size=528K
hostpci0: 0000:01:00,pcie=1,x-vga=1
hostpci1: 0000:10:00.0
ide2: none,media=cdrom
machine: pc-q35-8.0
memory: 65536
name: Gaming-VM
net0: e1000=[YOUR VALUE],bridge=vmbr0,firewall=1
numa: 0
ostype: win10
scsi0: local-zfs:vm-102-disk-2,cache=writeback,discard=on,iothread=1,size=1000G,ssd=1
scsi1: Synology-iSCSI:0.0.3.scsi-[YOUR VALUE],aio=native,backup=0,discard=on,iothread=1,replicate=0,size=25000G,ssd=1
scsi2: local-zfs:vm-102-disk-1,cache=writeback,discard=on,iothread=1,replicate=0,size=250G,ssd=1
scsihw: virtio-scsi-single
smbios1: uuid=[YOUR VALUE],manufacturer=[YOUR VALUE],product=[YOUR VALUE],version=[YOUR VALUE],serial=[YOUR VALUE],sku=[YOUR VALUE],family=[YOUR VALUE],base64=1
sockets: 1
tpmstate0: local-zfs:vm-102-disk-3,size=4M,version=v2.0
vga: none
vmgenid: [YOUR VALUE]
 
Last edited:
@Arm1nas you probably could debug quite easily to see if your problems also come from sound/USB emulation like it was for me: remove the hotplug: usb and audio0: device=ich9-intel-hda,driver=none from your config, reboot and connect with windows RDP. Now do something which normally lags, or even furmark or something like that and see if you have the same issues or not. RDP is no solution but with that you would at least know if you can rule out those factors as source of your problem or not.
 
You probably also heavily modified that VM Config to hide that the Windows is running in a VM so Anti Cheat Software won't block you when playing multiplayer games? Because in that case I wouldn't wonder if those obfuscation strategies also might cost you some performance.
Hmm, well I asked the patch creator how do do it and I'm pretty sure I removed it.
I think I'm gonna try to backup everything and reinstall Proxmox again if nothing works.
 
So I reinstalled proxmox and now the VM is actually running fast, before I had about 20-40FPS on CS:GO on low graphics, now with proxmox reinstalled, with default graphics I get stable 140FPS (possibly more, locked FPS by Moonlight stream). I installed a kvm patch before to not detect game anticheats on proxmox host, I thought I had uninstalled it but turns out no.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!