Is your Linux desktop sluggish?

I recently did a fresh install of the latest Linux Mint. Like the major versions before it, it's a joy to use, except when waking from a screen lock or when many tabs were open in my browser. Rebooting always helped instantly. Why?

When I first encountered this many years ago it seemed like a memory leak from a buggy application. No. Surprisingly, I found that it was a configuration issue. Linux was choosing to swap too much data to the drive, rather than leaving it in RAM.

This tendency has a name—swappiness—and it's easily fixable.

First, open a terminal window and see what the current configuration is:

cat /proc/sys/vm/swappiness

It will likely report a swappiness of 60, which is great for servers but much too high for desktop Linux use. We can temporarily reduce it with this command:

sudo sysctl vm.swappiness=10

Now, check to make sure it has changed by re-running the first command

cat /proc/sys/vm/swappiness

You may wish to continue to test your system for awhile and see if the performance begins to improve. Remember that it will revert to 60 when you reboot.

If, like me, you're overjoyed at how snappy the system remains with less swapping to disk, make the configuration permanent:

sudo nano /etc/sysctl.conf

If you don't see a reference to vm.swappiness, add these lines to the end of the file:

# Decrease the swap tendency
vm.swappiness = 10

Then save (using nano: ctrl-o) and exit (ctrl-x). This will be the new default for the life of the system, and you won't have to do it again until the next clean install.

I honestly don't know why all desktop Linux distros don't configure this way. I'll bet a lot of people have tried and quit Linux because it seemed slow in comparison to Windows. It's not, but it does need to be configured differently depending upon the intended use.

I hope this helped you.