Linux Performance HOWTO
This guide was written by Robert Sullivan, who can be contacted at firstname.lastname@example.org.
The purpose of this HOWTO is to provide the reader with a Linux system which has been optimised to the best possible performance. Many Linux systems come with software which is never used, and features which are never needed. This guide aims to trim down your system.
2.1 Package-based systems
When installing your Linux system, it is often easy to install too much. Many distributions have groups of packages, so if you want a certain program you have to install others as well. If you look for an ďindividual package selectionĒ option, you can choose what you want and leave out other software.
First, make sure you know what your system is going to be used for. Are you going to need a full-blown graphical environment with all the multimedia add-ons, or do you just need a web-browser and email client? Once you have the use of the system clear, it is easy to decide what you need and what you donít.
Often you donít need more than one graphical environment; some distributions install three or more on the default setup. Make your pick between KDE and GNOME, and also install one of the lighter window managers, such as IceWM or XFCE. If you want to have exceptional speed try Blackbox, Openbox or Fluxbox. A window manager can be very influential on your systemís performance, so with a low-end system choose a lighter one.
If you aren't going to be compiling anything at all, then you can leave out GCC (the GNU Compiler Collection) and the kernel source. For most users however, GCC and the kernel source should be installed.
Unless you prefer to have them, leave out all games. There is an abundance of them for Linux, and often if you donít use them you are merely wasting space on your hard drive.
If you have a low-end system, donít bother installing light and fast programs that run on a hefty graphical environment such as KDE or GNOME. Look for programs that require fewer dependencies.
Do you really need an integrated office suite, or just a word processor or spreadsheet? Avoid large suites of programs unless you need all of their features.
2.2 Source-based systems
Systems which are compiled from source are usually faster then their package-based counterparts. This is because source code can be optimised for your system: what processor you have, what features you need, and so on. Packages have to run on all systems, so you often end up running code which doesnít utilize your processorís features to greatest effect.
The most common source-based distribution is Gentoo (www.gentoo.org), although others are available, such as Linux From Scratch (www.linuxfromscratch.org) and ROCK Linux (www.rocklinux.org).
Source-based distributions can take some time to install, because everything has to be compiled. A full installation of Gentoo Linux can often take a weekend to complete, although pre-built packages are available for your processor if you want to speed up the install process. Updating is easier as well - most source-based distributions have a source tree whereby you can update whenever a new piece of software is available.
2.2.1 Optimizing your compiler flags
On Gentoo Linux, USE flags are options which affect the compiling process of applications all over your system. They define exactly what features and support are built in. You can add and remove flags in /etc/make.conf, where -X removes flag X, and X adds flag X. For instance, /etc/make.conf might be similar to this:
USE="-gnome -kde qt -arts -nls python perl oggvorbis opengl sdl
-postgres jpeg png truetype xml xml2 dvd avi aalib mpeg encode fbcon
You can find what various USE flags do on the Gentoo website.
There are also CFLAGS and CXXFLAGS, which tell the C or C++ compiler how to optimize the code which is being compiled for your system. For instance, with an Athlon XP processor, you would specify "-march=athlon-xp" so that the code was optimized for your specific processor. Information on optimizing CFLAGS and CXXFLAGS is usually found in /etc/make.conf.
2.2 Choosing your filesystem
Most systems will have either ext2, ext3 or reiserfs as their filesystem. ext3 and reiserfs are journalling filesystems - that is, they keep data about each file stored (called metadata) which helps if the drive has to be fscked after a hard reboot. ext2 is slightly faster than ext3, but without journalling, if you do a hard reboot you will have to wait several minutes while fsck checks your disk.
reiserfs is generally considered to be the fastest of the three, and it shows a significant performance increase in dealing with files smaller than 1Kb.
3. Post-install system configuration
Once you have installed your Linux system, you can remove any unnecessary parts of it that you wonít use, and make several tweaks to increase the overall speed of your system.
Hdparm is a tool which is used to maximize the performance of your hard drive. After using hdparm, most hard drives show a 2x increase in throughput, or in some cases a 6-10x increase.
Your Linux system comes with its hard drives reconfigured in the most basic possible setup. The hard drive configuration your system is installed with will work from the slowest 386, so if you have a newer hard drive, none of its new features are used.
Before you start tweaking with your disks, be warned that data corruption can occur if you push them too far, so be warned and if you have sensitive data make a backup.
If you are using current hardware (current meaning within the last 4 years), then there shouldn't be too large a risk, but if you have a quite old drive then be cautious when trying new settings.
With hdparm installed, type:
hdparm -Tt /dev/hda
at the console. If you are optimizing /dev/hdb or another drive, use the corresponding command. This command will show your drive's current speed. If you then type:
you will see what settings Linux is using for your hard disks. A typical output would be:
multcount = 0 (off)
I/O support = 0 (default 16-bit)
unmaskirq = 0 (off)
using_dma = 0 (off)
keepsettings = 0 (off)
nowerr = 0 (off)
readonly = 0 (off)
readahead = 8 (on)
geometry = 1870/255/63, sectors = 30043440, start = 0
The settings are nice and safe, but not necessarily optimal. Here's an explanation of some of the various options you can change for your drive:
multicount: This is the multiple sector count, which controls how many sectors are retrieved from the disk in a single I/O interrupt. All most all modern hard drives support this. This setting, when optimized, can increase hard drive throughput anywhere from 5% to 50%.
I/O support: This is the setting that will make a significant change to your system. Nearly all modern chipsets support 32-bit mode, and changing I/O support to this will almost certainly produce a twofold increase in speed.
using_dma: DMA can be tricky to use on older hardware. If you can get your hard drive to use DMA, then do it. But systems can hang if the hard drive doesn't support this setting.
Now we know what the main options do, shut down X and go into the console as root to ensure minimal chances of data loss. Here is a generally safe command you can use on your hard drive:
hdparm -m16 -c3 /dev/hda
When you check the hard drive throughput, it should practically have doubled.
There are some more dangerous options you can add:
hdparm -m16 -c3 -d1 -u1 -X34 /dev/hda
You can also try using the -X69 option.
With some of the riskier options, you should notice a large increase in your hard drive performance. Now edit your startup scripts so that hdparm runs at boot, because the settings have to be changed every time your system starts up--the scripts are usually found somewhere in /etc/rc.d or /etc/init.d depending on your distribution. You can also set the -k1 option to keep your settings if you're satisfied that they are perfectly safe.
3.2 Compiling your Kernel
The default kernel that comes with your distribution should work on most processors, but it won't use all the extras that your processor has. If you compile your kernel so that it's optimised for your system, you may see a noticeable performance increase. If your RAM is scarce, you should see a large improvement. This section doesn't normally apply to source-based distributions, because compiling the kernel is often part of the installation process (it is made even easier in Gentoo by genkernel).
Make sure your kernel is compiled for your processor. Usually there will be a specific option for your system (such as pentium4 or athlonxp), but if otherwise then select i486 for 486s or above, i586 for Pentium 1s or above, and i686 for Pentium 2s or above. Then decide what functions your system will need, and eliminate what you won't. If you don't use a joystick, disable the option, and so on.
Make sure that you have another kernel that you know works before you start testing your new one, or otherwise you won't be able to boot your system. I won't go into the details of compiling your kernel; there's another HOWTO that describes the process in detail.
3.3 Removing unnecessary virtual consoles
Your system is installed with about six or seven virtual consoles. Another virtual console can be used if you hang the current one, or if you want to run several programs at once. You can switch between them with Alt and the F keys.
Each virtual console that is running takes up an amount of memory. For most systems, even 4 consoles is too many - run with 3 if you are paranoid, but 2 virtual consoles should be sufficient. You can change the number of virtual consoles by editing the /etc/inittab file with your preferred editor. Search for lines similar to:
The initial number is the number of the virtual console, so comment out numbers 3 to 6 (by placing a # at the start of the line) if you have 6 consoles and you only want two.
Make sure you don't comment out the line beginning with 1, or else you will have no console whatsoever.
Usually, distributions set up several daemons, or services, to run at boot time. These may be unused - if you don't have Windows computers running on your network, why have a Samba daemon in your startup scripts? You can remove unnecessary daemons yourself by manually editing the scripts found in /etc/rc.d or /etc/init.d (depending on your distribution), or some distributions have tools to do the job for you, such as Mandrake. You can also speed up your bootup by taking this step.
3.5 The noatime attribute
Whenever a file is accessed in Linux, the current time and date are recorded. This is not usually needed, and you can gain a small amount of speed (which won't show up using hdparm -Tt) by disabling this option. This is done by editing your /etc/fstab file, and where on your hard drive line it says defaults, change it to defaults,noatime.
3.6 Unneeded documentation
If you need just an extra bit of hard disk space, you can remove the surplus images and documentation which come with most programs. When installing an RPM, you can choose not to install documentation with the --excludedocs option, or you can delete the files in /usr/doc. Other directories containing documentation are listed in /etc/man.config.
3.7 Removing international information
With very limited disk space, you can remove files in other languages from your computer by looking inside the /usr/share/locale and /usr/X11R6/lib/X11/locale directories.
3.8 Prelinking (mainly applies to source-based systems)
3.8.1 What is prelink?
Most applications use shared libraries, which have to be loaded into memory at runtime. With small programs, this takes hardly any time at all, but with larger programs that have more dependencies, the dynamic linking can take some time. On most systems, libraries aren't changed very often, so the linking process is the same each time. Prelink does the linking and stores it in the executable, so when you load the program no linking is needed (it's been prelinked).
What this means is that by prelinking some applications, you can decrease their starting time. A typical KDE program can load 50% faster.
The only maintenance required is to prelink everything again when you update libraries, but this doesn't happen very often. For best effect, prelinking should be done on a system that has already been linked with combreloc (see 3.10).
3.8.2 How do I use prelink?
First, you need to have glibc-2.3.1-r2 or greater installed with the binaries compiled with binutils-126.96.36.199.xx or greater. Prelink can be found on freshmeat.net, or on Gentoo you can type "emerge prelink".
Once prelink is installed, you can prelink all the binaries in the directories listed in /etc/prelink.conf with the following command:
There are a few things you should remember:
If an application's libraries change when you update it, you need to prelink it again to gain a speed advantage
prelink has an undo function, so all changes are reversible
If you're low on disk space and you prelink your entire system, your binaries may become truncated, leaving you with an unusable system. The file or readelf commands can check the state of a binary, or just check you have enough disk space before you prelink.
More information on prelink can be found in the Gentoo Linux Prelink Guide.
3.9 Optimizing your dialup connection
You can increase the speed of your dialup connection by adding:
to your /etc/ppp/options file. There should be a MTU and a MRU section to add these lines to.
combreloc is the GNU approved way of doing what prelink does, but combreloc does more than just C++ programs. It works on everything the GNU linker links. It has similar effects to prelink.
After combreloc is installed (you need binutils 2.12 or later), move /usr/bin/ld to /usr/bin/ld.orig, and create a script to replace /usr/bin/ld:
exec /usr/bin/ld.orig -z combreloc "$@"
Now, every time the GNU linker is called from /usr/bin/ld, this script will run, and use combreloc.
3.11 Configuring /etc/hosts
When /etc/hosts isn't configured correctly, this can seriously slow down your system. /etc/hosts contains your hostname. This is how you'd set your hostname to "linux":
edit /etc/hosts:127.0.0.1 localhost
This solution only works if you have serious problems with your system, such as applications taking over a minute to start.
4. Configuring X
4.1 Colour depth
There is hardly any visible difference between 15-bit, 16-bit and 24-bit colour depth, and changing to 15- or 16-bit will improve performance (this can be changed by editing the /etc/X11/XF86Config file or by using a configuration tool).
Icons, screen-savers and backgrounds can all slow your system down, so remove as many as possible. Many window managers have visual options, so in KDE or another window manager turn off anything you don't need, such as window shadowing. Themes can also slow your system down; set the style to default or "no theme".
4.3 Choosing a window manager
KDE and GNOME can be very sluggish even on a 500MHz machine, as they take up a large amount of system resources. IceWM is a good choice if you want speed without becoming minimalistic, but if you need faster performance try Blackbox or another light window manager, such as aewm.
If you absolutely need either KDE or GNOME, GNOME is slightly quicker.
4.4 X consoles
There is a multitude of consoles available for X, and some require more resources than others. rxvt and aterm are small and capable consoles if you don't need anything except a command line.
Still, rxvt can be made quicker by starting it with the -sl option, where is how many lines you want rxvt to remember. Reducing the number will save memory.
You can also save more memory by reducing the number of commands remembered; this can be done in bash by changing the HISTFILESIZE environment variable. To change it, use this command:
The default value for HISTFILESIZE is 500.
5. Choosing light and fast applications, and optimizing them
5.1 Web browsers
A web browser is one of the most commonly used applications on typical systems, and you will notice if it is faster than before. Mozilla can be sped up by using the Classic theme instead of "Modern", but it is still quite slow. An alternative with a Mozilla base would be Mozilla Firebird, or perhaps Galeon.
Mozilla Firebird is a good option for systems that aren't too slow, but require something faster than Mozilla. Firebird is a good choice because it has most of the features expected of a modern browser.
Dillo is another option for slower systems; it's a fast graphical browser with a small footprint (the binary is around 300Kb). It can handle most web pages, but it has no support for frames. Links-graphical is a graphical version of Links (a text-based web browser) which is another option to consider as well as Dillo.
There are several text-based alternatives, such as lynx, links and w3m, and these run in the console. At the moment, links is the most popular.
5.2 Office applications
Openoffice.org is quite slow, and on older machines it can have a loading time of over a minute. For just some simple word-processing, Abiword (www.abisource.com) is a good choice, as it is very light on resources, and it has support for Microsoft Word documents.
OpenOffice.org can be optimized somewhat. Go into the Tools menu, select Options and go to the Memory section. Under "graphics cache" change the option of "Use for OpenOffice.org" from 9 to something higher, such as 30. You can also adjust the other memory options for speed optimizations.
Gnumeric is also a good choice for a spreadsheet application.
Registered Linux User #325947
Check out Feather Linux
, my distro.
(Yes, it's shameless self promotion, deal with it