You're running Linux, now it's time to make it run faster! I've been using Linux since 1993 (
) and I learned a few things along the way.
Most of these changes will improve your performance, a few I threw in because they'll make your system more stable. Enjoy!Sysctl
The system control facility lets you tune dozens of little bits of the Linux kernel. For performance gains only a few of them are really relevant. You change these by editing the /etc/sysctl.conf
file and then running sysctl -p
(or rebooting).vm.oom_kill_allocating_task = 1
By default when Linux runs out of memory it goes through the process list and starts killing off processes that it thinks are using too much memory. This sysctl makes Linux kill the runaway process that made the system run out of memory instead, which is usually what you want.vm.page-cluster = 5
When Linux reads from the swap file it reads 2^page-cluster pages at once. It won't help to raise it past 5 because the swap is laid out in 32-page clusters.Disk I/Orelatime
This option is a more intelligent way of tracking disk accesses that dramatically reduces disk writes and increases disk performance. Check your /etc/fstab
file and for your filesystems that are listed as ext2/ext3 in the third column, in the fourth column take out "defaults" or "noatime" if they're present and replace them with "relatime". If neither of those two are present in the fourth column, then add ",noatime" to whatever is there. You need to reboot for this to take effect.Defragmentation
This comes up often enough I may as well say a word. You don't have to. Seriously, you don't have to. The Linux ext2/ext3 filesystem is much more efficient and requires no defragmentation. Its performance does start degrading once it's around 95% full, though, so if you're at that point, go delete some ISO images or buy a new hard drive. Use the df -h
command to check your filesystem capacity.Readahead
When Linux reads a part of a file from disk, it can also "readahead" past the requested data blocks, before the program using the file requests them. (This is subtly different from the userspace readahead discussed below.) By default Linux will read ahead 128KB of data so that it's already in memory cache before the program needs it. For today's systems (RAID arrays, etc.) this may be too low. For instance, with the Dell PERC 5/i RAID card, OCN members found that turning off the RAID card's internal readahead and using a Linux readahead of 16MB gave the fastest performance. You can set the Linux readahead using the blockdev
command. Some examples:blockdev --getra /dev/sda
Shows you (in 512-byte blocks) the system readahead.blockdev --setra 32768 /dev/sda
Sets the system readahead to 16MB (32768 512-byte blocks).
You'll probably need to experiment and benchmark to find the best value for your particular system, but any value above the default should give you better disk performance.Memory
Your hard drive might have a 16MB or 32MB onboard cache and be linked to your CPU via a 100MHz PCI Express bus. Wouldn't it be nicer if you had, say, 2GB of disk cache linked 1:1 with your FSB? Well, with Linux, you do! Linux uses any free memory as a dynamically expanding and shrinking disk cache, and several of the tips below take advantage of this. To be fair, Windows does this too, just not as well, as anyone who's played with Vista's SuperFetch knows. So the performance tip here is: Buy more RAM.Applicationspreload
This package does for Linux what SuperFetch does for Windows Vista: it monitors your application usage and then whenever you boot up your system it will load your most frequently used applications into RAM while you're staring at the login prompt. The Linux version is different, though: It actually works. And Linux had it first. Preload isn't installed by default so you'll have to install it from your package manager. (It's a boot service; be sure to enable it.)readahead
This package is related to preload but it's tuned specifically for the boot process. It starts early in the boot process and starts preloading a list of files into memory which will be used in the startup scripts that run later. This will help shave a few seconds off the boot process because these files can load while the system is busy doing other things like getting a network address. Readahead is installed by default on some distributions but not others, so you'll want to check and see if you have it, and if not, install it from your package manager and enable its boot services. (On Fedora the services are readahead_early
; on old versions of Ubuntu it's just readahead
, and in current versions the service names are are early-readahead
. In all cases, the package name to install is readahead
I had better mention how to enable boot services:
On Fedora you run su -c /sbin/chkconfig <servicename> on
On Ubuntu you run sudo update-rc.d <servicename> defaultsThat's all for now!
I might think of a few things later; if I do, I'll update this post and bump it. Enjoy your performance tuned Linux box!