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.
Tags: ubuntu
-
When I copy those lines verbatim I get:
root@apu:/etc# sysctl -p
error: “sysctl -w vm.swappiness” is an unknown key
error: “sysctl -w vm.vfs_cache_pressure” is an unknown keyI presume it should be:
vm.swappiness=1
vm.vfs_cache_pressure=50I’m still opening and closing windows trying to see if I notice a difference.
-
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.sysctl -w vm.dirty_ratio=2
* Tell the kernel to keep the dirty page / physical RAM ratio lower, 2%. Default is 10.sysctl -w vm.dirty_background_ratio=1
* Tell the kernel to start swapping dirty pages out as soon as they hit 1% (start flushing out early, before hitting the above ratio)Hope this helps someone. For reference, our server is Ubuntu 9.04, kernel 2.6.33, using BackupPC and an ext3 RAID5 (md).
5 comments
Comments feed for this article
Trackback link: https://www.tolaris.com/2008/09/28/making-the-gui-faster-in-ubuntu-linux/trackback/