6.3. Tuning a Runing Linux System

When Linux first got started, changing options to the kernel often required recompiling. Getting information out of Linux required applications be recompiled to look at the right memory location to get things like user and process lists. After the release of the 1.0 kernel, the /proc filesystem arrived as a way to access information in a kernel-independent way. Because of this, a command like ps will keep operating even if the kernel rev changes. The /proc filesystem also allows you to change the kernel itself wile running, allowing you to add in features like TCP/IP forwarding, manage RAID cards, and so on.

6.3.1. The /proc filesystem

This portion is not strictly about tuning a system, but getting information out of your urnning system. In the event of serious memory or hardware issues, you can sometimes get information out of Linux.

The /proc heirarchy may change depending on the kernel revision, but is generally arranged into different classes.

Processes

Contains information about each of the running processes, organized by PID. Each process has its own directory of information, including status, list of file descriptors, command line, environment variables for the application, and working directory when the application was started.

bus

Contains information about the system busses. At this point, it works with the USB, PCI, and PCMCIA busses. More, like IEEE-1394 will list devices and controllers under this directory. The information about each device is less human readable than older directoried like /proc/pci , but human readability is not the point of /proc

cpuinfo

If you want to find out information about the CPU(s) installed in your system, you can take a look at the cpuinfo file. For each processor, you will get things like CPU speed, vendor, model type (Pentium II, Pentium III, etc.), and the ever-popular bogomips rating.

filesystems

This file has a list of the filesystems that the kernel currently knows about. We say currently, since modules can be loaded or removed to add or remove additional filesystem types. If you are having trouble mounting a filesystem, this is an easy way to make sure the filesystem type is supported by the kernel.

ide

If your system has IDE devices, this directory contains information about the IDE devices that are in your system. It is organized by IDE channels that are available, and each device has informaiton about the model name and number, serial number, capacity, and any other information specific to that IDE type. Tuning of IDE drives should be done using hdparm, and you can see Section 4.3.1.2 for usage.

meminfo

This file has the raw memory information that you would normally see as output of free. The first part of the ouput contains the memory listing in bytes, followed by most of the same information in kilobytes.

modules

You could easily mistake the contents of the modules file for the output of lsmod. There is a listing of the modules, size of the module, and dependencies for the module.

partitions

This file has a list of all the disk partitions that are known to Linux, including those not mounted or listed in /etc/fstab.

pci

This file may go away in the long term, in favor of /proc/bus/pci, but /proc/pci is more human readable, listing the device type, vendor, and device name. But this will only happen if the Linux kernel knows of the device.

scsi

SCSI-based systems can look at and tune their parameters here. Its setup if much the same as for IDE, listing chains, followed by devices on each chain.

swaps

Lists all mounted swap partitions (or files) mounted.

version

The version file contains version information of the kernel you are using. It's very helpful in that it has the user and host that the kernel was compiled on, GCC version used to compile the kernel, and date and time this kernel was compiled. This makes it much more helpful than uname, since you can quickly check a series of running machines and verify they all report the same kernel revision.

Not listed above is /proc/sys. This directory is where most of the runtime changes to the kernel take place. Access to this used to be done manually, using cat and echo to view or change settings of a running kernel. If you wanted runtime settings to be changed each time the machine booted, you had to add commands to the rc.local file for each setting.

An easier way to manage these settings is via the use of sysctl.

sysctl [-n] [variable] [-w variable=value] [-a] [-p filename]

If you use an argument of variable, you will get the current value of /proc/sys/variable. You can set it by adding an equal sign and value. You can get a list of what is available along with their current values by using -a.

As part of the Linux boot sequence on more modern distributions, sysctl is called with -p, which reads settings from /etc/sysctl.conf. This file can be edited by a text file, and contains a list of lines of the form variable=value.

#
# /etc/sysctl.conf - Configuration file for setting system variables
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
#net/ipv4/icmp_echo_ignore_broadcasts=1
net.ipv4.conf.all.hidden = 1
net.ipv4.conf.lo.hidden=1

As you can see, variable can separate out directories using either a slash (/), or a dot (.). Using the dot makes it look more like SNMP variables.

Since everything under /proc are regular files, security for viewing or setting are handled by regular file permissions. In some cases, only root can make changes, in others, only root can view or set.

6.3.2. Using powertweak

Another interface to change options of a running kernel is through the use of powertweak. Powertweak also runs on startup of linux, using a daemon called powertweakd to issue changes to the kernel. Configuration files are stored in the kernel in XML format.

An advantage of using powertweak over sysctl is that powertweak has a graphical and text interface. There is a pretty extensive help system that can give you information about each setting.

For those that just want to have optimized settings for a particular use, there are pre-made settings for laptops, web servers, routers, and Oracle usage. As an example, the laptop setting changes the kernel disk flush so the hard drive can spin down. These are just generic settings, as each different machine has different PCI devices that can also be set.

You can get the latest version of powertweak from http://www.powertweak.org/

Figure 6-2. Powertweak