Making the GUI faster in Ubuntu Linux

I’ve been using some form of Unix since I was introduced to the Internet my first year at University in 1995. I switched to Linux on the desktop full time in April 2005, and I’ve been managing my company’s mid-size network of servers and desktops for the past two years.

One thing I’ve noticed about Linux, even desktop-focused distributions, is that it’s largely tuned to the most desirable behaviour for a server. But what is desirable on a server isn’t necessarily desirable on a desktop. On Ubuntu Linux (or any Debian-based distro), add the following two lines to /etc/sysctl.conf:

vm.swappiness=1
vm.vfs_cache_pressure=50

These changes will be done automatically on reboot, but let’s load them now with:

sysctl -p

Now you’ll notice GUI applications feel more responsive and filesystem browsing will be faster when the disk is busy. What we have done is instruct the kernel to prefer to keep applications in RAM (swappiness) instead of disk cache, and to prefer to keep filesystem inodes and directory entries cached at the cost of files themselves. This means reading files from disk is slightly slower (IE, copying, moving, loading big files), but browsing the filesystem will be much faster.

Rudd-o.com wrote extensively on this last year. I recommend his write-up for anyone who wants to understand the issues in more depth.

For the record, I ran the tests in Rudd-o’s article. He advised creating a big file, then displaying the entire filesystem hierachy with find, and then copying that file. In my case, I went from 2 minutes, 6 seconds for the “find / > /dev/null” to just 17 seconds. That has made browsing in Konqueror a great deal faster.

In our case I wanted to get file system caches out of RAM! Setting the vfs_cache_pressure parameter to a value greater than 100 will tell the kernel to more actively reclaim RAM used by caches. A backup server of ours was swapping heavily, regardless of having 2 gigs of physical RAM and very few applications running.

I guess file caches being read into RAM were to blame, as the server is actively using rsync to backup about 25 workstations in our small office. The disk thrashing was very heavy, and I found this to resolve the problems:

sysctl -w vm.swappiness=20
* Tell the kernel to swap applications out of RAM less (give preference to code rather than data from caches). Might not have done as much to remedy the problem as the other settings below, default is 60 and I might switch back after monitoring.

sysctl -w vm.vfs_cache_pressure=10000
* Tell the kernel to reclaim physical RAM used by file system caches more often. Default setting is 100.

Thanks, Alan. That’s very helpful. I do a lot with BackupPC. If you have a chance to rebuild this server or replace it, you will be much happier with performance under RAID10. I recently built an identical machine to my backup server, except that it had 4x 1TB disks in RAID-10 configuration instead of 5x 500GB disks in RAID-5. I cloned the BackupPC filesystem to it, and started backups on it. Backups now finish 40% faster and I can run 25% more of them, simultaneously.