Tips for optimizing desktop performance/responsiveness when system is under heavy load?
I use archlinux for work and lately I've been needing to run several (4-5) vms concurrently on my machine.
At times, when my vms are doing heavy work (e.g. extracting a 1GB zip file), the desktop on my host machine suffers heavy freezes and I'm basically unable to interact with it until the work in the vm finishes.
I have a very powerful host machine (laptop i7, 16GB RAM, 250GB SSD), so running these vms shouldn't really be too much of a strain.
I'm thinking my options right now are:
- play with my CPU scheduler. Sounds like the linux-zen kernel has a different scheduler that might be more desktop-friendly?
- play with my I/O scheduler. I'm using cfq right now. I've heard bfq might help a bit? But it seems like maybe it's not too stable yet?
- figure out a way to
nice/ionice/similar my vms. I'm using virt-manager/libvirt to manage my vms, but I'm not exactly sure how I could accomplish this
I'm also looking at the Improving performance section in the wiki. It seems to have a lot of information that could be useful, but before I go trying everything in there I'd really like to hear stories from anyone who's been in a similar situation.
Thanks!
About this post
- Posted
- Archived
- Score
- 44 · 100% up
- Kind
- Text
- ID
- 95xzik
26 comments
You're probably not limited by CPU at all, what you're describing is an IO bottleneck.
A CPU bottleneck would cause stutter but everything would still respond in a reasonable amount of time.
The deadline IO scheduler is the best for flash based storage I believe, definitely try that one out.
Second IO bottleneck.
Also make sure you are not swapping. In that case zram may help you too.
Yeah, I'm pretty sure it is an I/O bottleneck since I can actually produce similar behavior by just copying large files back and forth across my SSD
Agreed, the IO scheduler can make a big difference. Just a note that one should really try with different schedulers. It really depends on your workload, disk and expectation. On my laptop with SSD I had frequent lags when using the deadline scheduler with write heavy operations in the background. Switched to the CFQ scheduler and the system got more responsive under these conditions (but likely the total throughput was worde, but I did not measure that).
This will tune your desktop for responsiveness, not IO throughput:
Do not do it in servers.
Source: https://rudd-o.com/linux-and-free-software/tales-from-responsivenessland-why-linux-feels-slow-and-how-to-fix-that
Or just swap to BFQ for your IO elevator.
Or do both, but seriously using BFQ instead of CFQ does wonders.
The article is awesome, but it's also 11 years old (modified 5 years ago). Is it still relevant?
For that specific use case, the ck kernel does a nice job of retaining responsiveness.
Stupid question, do you have swap? My machine used to freeze when I didn't have it in my fstab
Yup, I have swap and even hibernation to swap enabled
I use linux-ck, (mostly for muqss scheduler) swappiness = 1, ananicy, my gnome desktop vanilla without animatios and some others litle tweaks from performance improving in arch wiki.
Well, it also smells to me to be a I/O bottleneck, but still, you say you run 4-5 VMs at a time. How many cores does your I7 have and does it have hyperthreading? Basically, what is the number returned by command:
If it shows, say 8 (meaning you probably have a quad core withouth hyperthreading), you should reserve at least two for you host and other 6 for VCPUs on you VMs. Never assign more VCPUs to VM guests than that.
Depending on what virtualization technology you are using, make sure you have appropriate drivers on your guests (eg. VirtualBox guest modules or vmtoolsd if VMWare) as that can greatly affect I/O performance - without it, I/O is emulated, with the modules it is paravirtualized, meaning the host is taking care of it. That being said, any complicated I/O scheduler on the guests is an overhead, you should really use "noop" scheduler on the VM guests, and the default CFQ is actually good on the host in this scenario. Check this out:
https://access.redhat.com/solutions/5427
https://kb.vmware.com/s/article/2011861
This is recommended for both VMWare gust OS-es and KVM/QEMU guests, should also be good on VirtualBox.
Lastly, from my own experience where I experienced almost the same problem as you have (I was doing "tar xvfj somebigfile.tar.bz2" on one of my guests and the hosts almost completely froze. As untarring was long, I had some time to try to figure out why this is happening. I discovered that the virtual disk of that particular VM was growing in size at that time. This disk was thinly provisioned, eg. growable. After the untarring finished, I added another disk to that VM, but this time of the fixed size and did the same operation on this new virtual disk, an voila, it finished in no time... Just my experience, this doesn't have to be your case.
Therefore, I would also recommend to use fixed size virtual disks for I/O heavy VMs (for an example database servers), for web servers or application servers without excessive logging, thinly provisioned volumes could be fine as I can see that you don't have that plenty of disk space on disposal.
The default CPU scheduler is fine. But check if you have autogroup cpu scheduler enabled. It does wonders for responsiveness under heavy load.
Consider Ananicy (ANother Auto NICe daemon) from AUR
https://github.com/Nefelim4ag/Ananicy
There's a "block multi-queue" = "blk-mq" thing for IO. To use it, you have to enable it on the kernel command line with a parameter
scsi_mod.use_blk_mq=y. The kernel will switch to an alternative set of IO schedulers after this. I don't know which one is best. I'm using "kyber" myself on SSDs, and "mq-deadline" on HDDs.With blk-mq enabled, you will not be able to use CFQ anymore, and I think
ioniceonly works with CFQ. It's silently not doing anything with other IO schedulers.I use just a single VM here sometimes. I noticed it starts up faster when using blk-mq.
About
linux-zen, the linux-zen package does not have a different CPU task scheduler right now. It uses the same CFS task scheduler as in the normal kernel. I don't know why it sometimes uses CFS and sometimes MuQSS (the one you would like to try). It's probably related to the fact that Arch starts using a newer kernel version before MuQSS is ported. Right now with linux-zen, you would have to compile the package yourself and change its configuration.If you want to try MuQSS, you should look into
linux-ck. There is an article about it here:https://wiki.archlinux.org/index.php/Linux-ck
There is a repo with binary packages, so you don't have to compile it yourself.
I like BFQ for desktop responsiveness. I've found it to be awesome
The DE you use also has bearing on your desktop response under load.
How to Throttle per process I/O to a max limit?
https://unix.stackexchange.com/questions/48138/how-to-throttle-per-process-i-o-to-a-max-limit
Deleted before we saved it.
Simply giving VM processes lower CPU priority could help a lot.
Thanks for the suggestions everyone! I did a few things and now my desktop responsiveness is significantly better.
First I made these changes:
It seemed to improve things a little bit but I was still experiencing freezing
So then I switched to BFQ scheduler. It's amazing! I have almost 0 freezing even under the heaviest workloads.
Linux ck and schedtoold, i notice nothing on 100% cpu, check http://ck.wikia.com/wiki/SchedulingPolicies and set heavy load stuff to idle