Hello Guest, if you reading this it means you have not yet registered. Please take a second to Click here to register and in a few simple steps, you will be able to enjoy all the many features of our fine community. Please note that nicknames are prohibited lewd or meaningless (no numbers or letters at random) and introduce yourself in the section for you to meet our community.

Once you decide to optimize your system, it would be time to find which points can be improved. To achieve this, you can use these tools:
ps

This tool allows you to view what processes are running in your system. The range of the process you can see goes from your own ones to all-wide system processes. This command shows the PID for the process, the terminal associated, the accumulated time and the name of the process.
You can use ps to monitor what processes are running on your system and which are extensively using the CPU.

If you liked ps, you will like top. Top is a very efficient tool to keep track of processes continuously. The tool is invoked by running top at the prompt. With top, you can list processes ordered by CPU or memory usage. To know more about top, please read this article: Using Top More Efficiently.
vmstat

vmstat provides information about virtual memory, processes, cpu and more. It can be useful to monitor your global system statistics. This tool is a compilation of information that can be gathered from other well-known UNIX commands

This is a little but useful tool to measure execution times. It takes a command as an argument. Then executes it and shows a brief statistic about time spent by the process. This can help you to find out if a command takes more time than expected. Of course, this is specially useful if you are dealing with a program developed by you, so you can modify your sources and compile again to compare results.

[fernape@Hammer ~]$ time ls -R >/dev/null

real 0m0.117s
user 0m0.057s
sys 0m0.046s
x11perf

x11perf performs a benchmark over the X server. This command is invoked running x11perf from prompt. It can take a lot of parameters but running x11perf with -all parameter reveals a lot of information (but it will take a while...).

Obviously this information is not very useful if we can not compare it with other. Here is when x11perfcomp is in order. x11perfcomp is a shell script that compares two outputs generated by x11perf. Now, the way to analyze your X server performance is clear: take a snapshot of your server performance, make some changes in the configuration file and other system settings (remember that X window system uses shared memory and other IPC mechanisms that can affect performance), run x11perf again and finally, compare the results with x11perfcomp.

Below is a truncated output of x11perf. It is a very configurable tool, you can specify certain performance tests or tell him to run all available tests.

Results can be saved by redirecting the output of x11perf to a file. I executed x11perf once and saved the results in test1 file, then I changed some settings in my xorg.conf file and executed the benchmark again saving results in test2 file. Then I compared them:

[fernape@Hammer ~]$ x11perfcomp test1 test2

1: test1
2: test2

1 2 Operation
-------- -------- ---------
8310000.0 8140000.0 Dot

It appears that my changes were not very appropriate.

When x11perf is used, a white window is showed in the screen as you can see in the picture below. To avoid benchmarking result modification, don't touch that window nor move the mouse over it. The window will disappear when the tests are finished.

hdparm

One of the most important devices in your machine is the hard drive. It is used whenever a new process is loaded, when a memory region is swapped from memory to hard disk and when it is restored from the swap partition to memory again. And because UNIX like systems makes an extensively use of files for almost everything, it is very important to set up the hard disk properly. Hdparm helps you in benchmarking and setting your hard disk.

For now I only show you how to perform a test for your hard disk. If you are impatient and want to know what parameters you can set, read the next section: “Tuning your system”

I recommend you to run the test at least five times to take the mean value. And it is important not to use the rest of the system if it is possible, so the test will be not affected by other block disk requests.
Tuning your system

Now, we will see some tools that help us to fine tuning our system. We will also see some tips that can be useful to save memory and because of that, they are specially important for machines with no much memory.
Disabling system services

In a typical installation a lot of services are running to ensure maximum compatibility and usability experiences to the user. Since this is a good approach for most of people, sometimes, some services are not used at all while your system is up. Because of this, it is a good idea to disable these non used services. You can do this with several programs. In Red Hat based systems, you can use setup in console mode or serviceconf in a graphical session (showed below).

Some of the services you would like to disable are:
Network Manager: chooses the best available connection (are you always connected and permanently moving?)
bluetooth: if you usually don't work with bluetooth devices you can disable it.
cron: disable it if you have not programmed tasks (maybe you would like to run these tasks for yourself instead of schedule them).
cups: printer daemon (I have it disabled in my laptop since I don't print from it)
iptables: the linux firewall. At your own risk.
irda: Same as bluetooth for Infra Red communications
irqbalance: disable if you are not working with an SMP system.
nfs: you can disable it if you are not sharing your files through NFS.
misc. servers (ssh, sftpd...): A lot of servers are launched by default. Do you really want your system becomes a server?
vnc: Virtual Network Console. Disable if you don't need remote graphical access to your system.

In Red Hat systems, you can add and remove system services using the chkconfig command (for non graphical sessions) in this way:

chkconfig service on/off

Other systems have their own mechanisms for managing services. See your handbook.
Disabling X at booting.

You would like to disable X or not, depending of the type of user you are. I’m a fanatical of the command line, and I have disable X at boot time. When I start my system I log in a console do my work and shut it down. This can save a lot of RAM if you don’t mind to deal with bash (or the shell you use). If you want to disable X, go to the /etc/inittab file and change the line:

id:5:initdefault:

For this one:

id:3:initdefault:

The next time you boot your system, you will be in pure command line. This not only saves memory but it is faster for simply operations, e.g. If I want to insert a line in my movie list file I waste less time in console mode than in graphical mode, waiting for GNOME, Metacity and X server to be loaded.
Removing consoles

One of the cool features of a linux distribution is the availability of several terminals. These terminals are accessed with Ctrl+Fn keys and allows to log in more than once in the system. But sincerely, I have been using Linux since several years ago and I never needed more than three or maybe four terminals at a time. So you can save some memory by disabling some of them. Even more, if you usually use a graphical desktop, you can use one or more gnome-terminals or konsoles, so you can safely left only one additional terminal in your system and free the other ones.

To achieve this, the /etc/inittab file must be modified again. Just comment the lines that set the terminals:

Notice that buffered disk reads have decreased dramatically! It is more than 15x worse (compared to the test performed above...).
Sysctl

Probably this is the best tool for tuning linux systems. It can configure a lot of system parameters while the linux kernel is running. It handles this, by reading and writing to kernel variables through procfs files.

The complete list of available variables is shown by typing:

[root@Hammer ~]# sysctl -a

It would be a waste of time to explain every variable in this long list. Instead of that, if you are curious, you can play with them (most of them are self-explanatory).

My advice: look at networking options.
Installing video card drivers

This is one of the devices that I’m sure you are not using all its capabilities if you are working with a stock configuration and installation. The biggest video card vendors, like Nvidia, ATI or Intel provides their own proprietary drivers for linux. This license issue is the reason by which they are not included in most of the distributions. Proprietary drivers can improve your video card performance very much. Let’s use x11perf again. I run a deepcopyplane500 test with the “Standard VGA” driver chosen by my stock installation. I saved the result in test1 file. Then I change to the ATI proprietary drivers for my ATI Radeon Mobility 9700 and run the test again saving the result in test2 file.

The use of x11perfcomp will reveal the big difference between the two drivers.

As you can see, it is really a good idea to install the proper optimised driver for your video card.

Going further, you can even improve the performance of the driver. Nvidia and ATI, allows you to install a precompiled package or to generate a new one. The last option allows you to compile the driver for your specific machine instead of use a generic one.

If you choose the recompile option, you will need your kernel sources, but fortunately the installers make a good job and generate the package automatically without additional work.
Drivers for frequency scaling

If you are using a processor with variable frequency (e.g. Centrino or AMD64) you would like to properly set up your processor configuration to save battery charge. Cpufreq is a program that helps you to do this. It can manage Centrino and AMD64 processors, and allows you to control the frequency value by means of an interface under /sys. With cpufreq you can fix the frequency to the minimum value (max. saving), the maximum value (better performance), or let the driver choose when to increase or decrease the frequency.

To install this daemon, you will need libsysfs and a linux kernel capable of frequency scaling. Most of the modern distributions comes with cpufreq installed. Now it is time to configure it. In my case, it was not properly configured so my AMD was at 100% of use all the time.

See documentation for additional information. You can install the cpufreq applet to easily configure your driver.
I want more: Compiling your linux kernel (the easy way...)

The linux kernel is the core of the operating system. It is used permanently when you are working with your distribution. Even when you are executing a “hello world” program, is the kernel who loads the program, attends to memory requests and executes system calls to perform the actual work you can see.

Due to this, it is very important to have installed and properly configured (and optimized) your linux kernel. Compiling the kernel is a long and complex topic that can't be covered here in depth. However, you can be lucky if your distribution provides default configuration files for the most common architectures. This is the case of the Red Hat based systems. Let's see how to easily recompile our kernel:

First of all, I assume that you have your linux kernel sources properly installed in your machine.

Now, we move to the sources directory, typically something like:

/usr/src/linux-2.6.9/

At this moment, we want to start to configure our new kernel.

make gconfig

We could start to configure from scratch but this is not our objective. We could forget an important feature and then our kernel will be possibly broken. So, load a configuration file from “configs” subdirectory:

These configuration files ensure that you will obtain the same result you had with a stock kernel but with your specific processor optimizations. You can safely load this file and don't worry about anything. The picture below shows the configuration file loaded.

Even more, in my case, I'm sure my processor is an Athlon64 so I can set it in the options and deselect the Generic-x86-64 option.
Then save your settings and continue with the process:

make;
make modules;
make modules_install;

And if needed, create your initrd file.

If you have compiled and installed your kernel successfully, you will take advantage of your system architecture without a big effort.
Conclusions

Linux vendors make a great effort to build optimized versions of linux systems. However the success in installation is very important too. So, the vendors should estimate both factors. Due to this, some parts of the system are not ready to work at maximum performance. Our mission is to find these points and lead them to a better performance state.

Moreover, since vendors want linux become a wide-used operating system, sometimes they start a lot of services that are not usually used. As an advanced user, it is important to disable these services and features to save memory and other system resources.

The best strategy: if you are not using that feature you can safely disable it. You will save system resources.

Linux systems can be fully configured. Let's take advantage of this!
----------------------------------------------------------------------------------------------