mojira.dev

Ashten Henderson

Assigned

No issues.

Reported

No issues.

Comments

If you have access to your KVM host machine, you can run the following command as root:

echo 0 > /sys/module/kvm/parameters/halt_poll_ns

**I put it in my root crontab to run at startup.

 

Michael Meier seems to have a better understanding than I do, but I'll give a quick explanation of what I believe is happening host-side:

When a vCPU halts, KVM will continuously poll the vCPU for a short while after in case there's a wakeup right after. This is good for responsiveness of the guest, but means that, in layman's terms, KVM is essentially running around in a while() loop. If there isn't a wakeup in a certain amount of time, KVM will pass it off to the scheduler, meaning it polls the vCPU a lot less often. 

Minecraft breaks this by having a ton of wakeups really close together. So, the vCPU sleeps, has a wakeup right after, Minecraft does a really teensy calculation, and then the vCPU halts again. Rinse and repeat. That means that the majority of the time, KVM is simply polling the vCPU for wakeups because Minecraft thinks it needs to wakeup really frequently for some reason, even when there's nobody online.

Since it's KVM running in circles, the host sees the high CPU. The guest doesn't see it, because as far as it knows, it spent most of the time with the vCPU halted. The command I pasted above disables this feature and forces KVM to only uses scheduling.

Now, as I said, this is what I think is happening based on the research and experimenting that I've done. There's probably some people who're more familiar with the Kernel and KVM on the development side that could better explain, and/or confirm/deny what I'm saying.

 

Why it's a concern for me, personally:

My server is hooked up to a UPS. With the vCPU doing this continually, it halves the time that the UPS can last.

Also, I have a Threadripper CPU, so I now have enough cores that I can afford to "waste", but that wasn't always the case. A few months ago, for several years prior, I was running KVM on a quad core CPU. I believe that the majority of people, especially as hobbyists, would be in a similar boat.

 

So, I would suggest that Mojang keep looking into this. A lot of people host their Minecraft servers on a VPS, so this could potentially impact them.