Skip to content

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!

44 points26 comments
Open on Reddit
About this post
Posted
Archived
Score
44 · 100% up
Kind
Text
ID
95xzik

Author

36
posts
153
comments
1
media
View profile

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.

31 points

Second IO bottleneck.

Also make sure you are not swapping. In that case zram may help you too.

16 points

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

4 points

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).

1 points

This will tune your desktop for responsiveness, not IO throughput:

sudo tee -a /etc/sysctl.d/99-sysctl.conf <<-EOF
vm.swappiness=1
vm.vfs_cache_pressure=50
vm.dirty_background_bytes=16777216
vm.dirty_bytes=50331648
EOF

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

12 points

Or just swap to BFQ for your IO elevator.

Or do both, but seriously using BFQ instead of CFQ does wonders.

3 points

The article is awesome, but it's also 11 years old (modified 5 years ago). Is it still relevant?

2 points

For that specific use case, the ck kernel does a nice job of retaining responsiveness.

8 points

Stupid question, do you have swap? My machine used to freeze when I didn't have it in my fstab

3 points

Yup, I have swap and even hibernation to swap enabled

1 points

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.

3 points

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:

grep processor /proc/cpuinfo |wc -l

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.

3 points

The default CPU scheduler is fine. But check if you have autogroup cpu scheduler enabled. It does wonders for responsiveness under heavy load.

2 points

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 ionice only 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.

1 points

I like BFQ for desktop responsiveness. I've found it to be awesome

1 points

The DE you use also has bearing on your desktop response under load.

1 points
unknown author

Deleted before we saved it.

1 points

Simply giving VM processes lower CPU priority could help a lot.

1 points

Thanks for the suggestions everyone! I did a few things and now my desktop responsiveness is significantly better.

First I made these changes:

$ cat /etc/sysctl.d/99-performance.conf 
vm.swappiness=1
vm.vfs_cache_pressure=50
vm.dirty_background_ratio = 3
vm.dirty_ratio = 10

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.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.