r/VFIO • u/old-gregg • Feb 27 '18
Support High KVM/QEMU CPU utilization when Windows 10 guest is idle
I have a Windows 10 VM running under KVM on Linux. I'm using libvirt to manage it, if it matters. When the VM is idle (0-1% CPU utilization in Task Manager) the underlying qemu-system-x86_64 process is consuming 15-20% of a CPU core. this has been solved, scroll down
I also have a Windows 7 VM and it behaves as expected: 0.5-2% CPU on idle, and Linux VMs barely hit 1% when they do nothing.
This drives me nuts because it prevents me from running Windows 10 on the server 24/7. Here's what I've tried so far:
- Used clean, freshly installed Windows 10 with up to date drives and no additional software
- Disabled all kinds of Windows background services: superfetch, diagnostics, anti-virus, etc etc
- Used another server, this time AMD-based (Ryzen 7) to run the same VM there
- Tried different Linux kernels (4.11 and 4.15)
- Tried setting
options kvm halt_poll_ns=0to /etc/modprobe.d/kvm.conf - Tried installing guest KVM drivers. This actually made things slightly worse.
- Tried disabling every unused device inside a VM.
- Googled the hell out of the internet
Qemu/KVM is v2.8.1 and I haven't seen any bugfixes/improvements in their changelog to try to upgrade.... actually I just noticed that another machine uses Qemu/KVM 2.11 - same result.
Anything else I can try? Thanks.
P.S. Libvirt definition of the VM: https://pastebin.com/DW3P86PV
SOLVED!!
Kudos to /u/semool for providing a clue. The timers configuration which libvirt applies by default needs to be changed:
<!-- before: this config uses over 15% of a host CPU core -->
<clock offset='localtime'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
<timer name='hypervclock' present='yes'/>
</clock>
<!-- after: this config drops to about 3% of a host CPU core -->
<clock offset='localtime'>
<timer name='hpet' present='yes'/>
<timer name='hypervclock' present='yes'/>
</clock>
To apply this fix, run virsh edit <vm-name>
4
u/semool Jun 13 '18
Hi
I have the same Problem with a Win10 Guest Machine under Proxmox.
After remove this from config, my Win10 Machine drops from ~16% to ~3% idle Load:
-no-hpet
driftfix=slew
-global kvm-pit.lost_tick_policy=discard
2
u/[deleted] Feb 28 '18
What's your CPU topology/core-pinning situation like? Also what storage settings are you using? My Windows 10 VM is running on much, much weaker hardware than yours (I have an AMD FX-6300) and
qemu-system-x86_64doesn't break 2% when my VM is idle. If your storage and networking stuff isn't tuned/properly virtualized it can spike up CPU usage just trying to do basic tasks.2
u/[deleted] Feb 27 '18
My favorite way to destroy Windows 10 is using the Group Policy editor to disable Windows Defender.
Also, isn't it that Linux reports CPU usage per process as the sum of the percentages of the threads? Like, me on an 8700K get 1200% usage. But Windows has always been known to be a hog.
Another thing to screw around with: if you're using libvirt, try doing suspend and resume. It... Won't help, but it's just really cool to me 😂
4
u/grumpieroldman Feb 27 '18
Mine's the same way.
I suspect some of the enlightenments are not working correctly but haven't dug into it much.
There's a particular windows feature for multimeda timing, which allows it to increase the slice rate, and it seems if you run a program that sets it to a low value then the VM uses a lot of processing.
For me it's TeamSpeak however setting the MM timer low also resolves some audio issues.
3
u/tholin Feb 28 '18
Where does qemu-system-x86_64 spend it's cpu time? Is it in kernel space, user space or... guest space (if that's what it's called?)
Use perf to find out. Run this while the VM is running and using a lot of cpu while idle.
It will show how often qemu is executing various functions. If the function got a [k] in front of it it's in kernel space and [.] for user space. There is also one function used for making the switch to guest space and it accounts for all time spent there. On a 4.14 kernel with intel cpu that function is
vmx_vcpu_runbut it might differ.If the VM is doing VM_EXIT it would be interesting to know why and how often. To find out use.
If the VM is idle you shouldn't see values bigger than 1000 or something in that ballpark?
This command should show that most
Time%is spent doingHLT. If time is spend elsewhere the VM isn't really idle.All these commands assume you only have one qemu VM running.
1
u/spheenik Feb 28 '18
Same here but only if the Steam Client is running in the VM :/
1
u/kwhali Mar 01 '18
I think another alternative would be to suspend the process(STOP signal). In KDE with the System Monitor(KSysGuard), this is pretty easy to do, just lookup the process, right click it, send signal "Suspend(STOP)". Then you can send the "Continue(CONT)" signal when you want to let the process use CPU again.
1
u/cytrinox Feb 05 '26
I've found out that my win11 VM dropped from constant 50% CPU usage to below 10% CPU usage after disabling nested KVM:
options kvm-intel nested=NI found the hint by discovering lots of kvm_nested_vmexit calls:
1
u/Teacult Sep 20 '22
I am on 5.19.4-arch1-1 / qemu 7.0.0 using NVIDIA RTX 3060And my problem and my libvirt clock settings were exactly same.By reverting it to hpet I have only lost %2 single core performance compared to bare metal. Multicore performance stayed %99 bare metal.
I had 3 phases of configuring vm once for vfio pt , one for hiding hypervisor (kvm hidden stat on + smbios serials chasis num etc) one for optimizing single core performance. I dont remember when I introduced such clock settings.
I wonder if it will solve virtio hdd crashes. btw I changed my disk diver to cache=none io=native ... didnt effect anything.
I was donwloading clancies division and things got weird. %11 utilisation on guest %35 on host ...
One more thing: perf is good but mpstat of sysstat package is not bad since it outputs guest% and sys% too :
0
u/[deleted] Feb 28 '18
[deleted] — view deleted comment