Optimizing CPU for QEMU-KVM - What can I do?

Hello,

I just registered here, hoping to find anyone who is experienced with Linux and QEMU+KVM setups. Anyways, I'm running a Windows VM alongside Ubuntu, mostly using this setup for gaming on the side. I have been playing around and trying to optimize this setup, not entirely great for novice users...

Essentially, I'm trying to figure out how to optimize CPU utilization. Host CPU is the 4790k and have tried assigning only three cores and 2 threads to the VM, which isn't exactly what I would like in terms of performance. Anything beyond 3 cores tends to make games drop frames. Is there a possibility of increasing the CPU performance further? I've looked into vCPU configurations but that seems to only apply to everything but CLI setups and I'd rather stick to CLI instead of converting to xml.

Here is my current configuration here

Sorry if I screw something up or but this thread in the wrong place~

1 Like

$ lscpu

Is VT-x enabled?

Also, have you tried using virt-manager instead of the CLI? If it works through that GUI then it's a config error. If not, it's something in the system.

I would definitely try using virt-manager if you aren't. Makes it so easy. Also check out this series in setting up PCI pass through, it helped me a ton.http://vfio.blogspot.com/2015/05/vfio-gpu-how-to-series-part-3-host.html He also does some processor optimization in the later parts.

I also have a thread where my forays into this world are documented. I had some troubles setting it up, but right now I have a fully working Windows 10 VM that I play games in flawlessly.

So while your CPU does support virtualization it's only 4 cores, what you have been doing giving the KVM 3 of the 4 is about the best you can do leaving one core and two threads for the host system, using virt-manager you can do a little fudging and it might help but in my opinion your still going to be limited by your physical hardware (CPU).

You have to look at it like this, would you run Windows on a dual core or tri-core CPU and expect very much gaming performance? even though a lot of games are optimized for single or dual core usage there are other behind the scenes processes that the guest OS is doing while running the game that require clock tics and CPU cycles while also running the game in a stable environment.

When it comes to KVMs and running games you really need as much memory as you can afford and as many CPU cores that you can share, it's one of the reasons the AMD 8300 CPUs work so well in this application giving you the necessary cores to pass through to the guest to keep it happy while leaving a couple cores for the host system to run it's processes in a stable environment....and yes there is a performance hit for using a AMD CPU over a Intel but the price difference between the AMD and Intel octo-core CPUs gives the advantage to AMD in this situation.

But don't forget memory, if you look at the base requirements for whatever version of Windows your running in the KVM you want to exceed that number at least to the recommended amount or beyond, the more memory you have to give to the guest system the more forgiving it will be when Windows is tasked to run a higher level game.

Hope this helps.

Isn't the 8300 series just 4 cores? Anyways, I've allocated 8GB's to the VM and 8GB to the guest.
When I hear people say they can reach bare metal performance, I figured it was raw CPU and GPU performance. Oh well.

I'm not sure where I can begin to convert over. I semi tried once but it ran inside its own window and was very delayed, definitely didn't work the way I would've liked. Probably KVM wasn't working as the hypervisor?

There a few optimizations that you can try that are mentioned in the vga passthrought page on the experimental comunity wiki. If you have ram, start by enabling hugepages.

It's how cores are defined Intel and AMD have different ways to define what a core is or how instructions are processed through the cores, but the reality in this case is that the AMD 8300 series of CPUs are recognized has having 8 cores (threads are another issue...lol)

The thing you will find is that raw CPU performance isn't as big a factor as you might think, yes, performance is important to the overall picture but it really comes down to resources that can be split and allocated between the host and guest, clock speed isn't as big of a issue and the advantages of faster cycles vs more cores the more cores will win every time in this application.

It's like I said yesterday, you want the available resources to give the guest that relates or is the same amount of resources that you would give Windows running on bare metal, so if you give 8 gig of ram to your guest and the recommended amount for the OS or a given game is 16g then you have created a problem by short changing the guest, will it run?, sure it will, will you get bare metal performance...nope!

Another thing to consider is the allocated space you give the guest to use and is that space a separate drive or is it a partition of another drive, while both will work a separate drive is the preferred that is big enough to house your guest OS and in the case of Windows create a large enough swap file to be happy.

I've said this before but it needs to be said again, when running this type of setup you are creating two computers in one box, you need all the resources for both machines that can be divided up to give each what it needs to be happy, robust and stable, and while Linux is happy to run on minimal hardware and resources Windows isn't the least bit thrilled to be ran on anything but robust hardware and lots of resources, it's not known as a resource hog for nuthin'.

Then the last piece of the puzzle is the host OS (linux), not every Linux distro has the ability to run KVMs in the same stable state as others, while this is getting better distros like Fedora or OpenSuse have better more up-to-date support then some of the Debian based distros like Ubuntu and that's not that they won't work because they will but they require extra effort in the form of configuration and patching which isn't a big deal most of the time.

But the bottom line really comes back to your hardware, the amount of resources you have to share and where that falls in the recommendations of the guest OS and any software you want to run on that OS, give it what it wants and then a little more for margin, growth, and that weird game that taxes the hell out of a Windows environment on bare metal and you can achieve your goal.