Section 14.11. Tunable Kernel Parameters


[Page 590 (continued)]

14.11. Tunable Kernel Parameters

The Linux kernel has many constant values that may be examined to find out how things are working or modified in order to improve the performance of the system. Altering kernel parameters to improve performance is referred to as system tuning. In addition to modifying kernel source code or header files, recompiling the kernel, and rebooting the system (as was required in "the old days"), Linux provides two more manageable methods of examining and modifying kernel parameters.

14.11.1. The /proc File System

The /proc file system is not really a file system at all, but an abstraction of kernel data with an interface that resembles a file system. By registering itself with the Linux virtual file system (VFS), the /proc file system looks just like a normal part of the Linux file system. Most "files" in the /proc file system are read-only, but the super-user can modify some of them.

Each process has its own directory in the /proc file system, named with its process ID (PID). That pseudodirectory contains other files that provide access to information about the running process.

Other named directories contain files whose contents are computed from live kernel data when the file is opened. For example, to find information about the CPU on the system, you can look at the file /proc/cpuinfo.

Most of the interesting kernel-related data is found in /proc/sys. For example, to find and change the maximum number of open files allowed on the system, I might do this:

# cat /proc/sys/fs/file-max 18999 # echo 25000 >/proc/sys/fs/file-max # cat /proc/sys/fs/file-max 25000 # _ 


Note that when you modify a kernel parameter this way, it is modified only in the live running kernel. When the system reboots, it will return to its default value. To make a modification permanent, you must add the command to a boot script so it is executed every time the system is booted.


[Page 591]

14.11.2. The sysctl Utility

As convenient it is to modify kernel parameters through the /proc file system, it lacks a bit as a user interface. So Linux also provides the BSD 4.4-inspired sysctl utility as a command-line interface to data in /proc/sys.

Figure 14-13. The sysctl utility.

Utility: sysctl -aw { parameter=value }

sysctl -p file

The sysctl utility provides a convenient command-line interface to the kernel parameters available in /proc/sys. When the -a option is used, sysctl prints all the kernel parameter names and their values. When the -w option is used, subsequent parameter=value specifications are used to modify the parameter in the running kernel (when run as root). When the -p option is used, parameter=value specifications are read from the named file. By default, this file is "/etc/sysctl.conf" and can be used to reset kernel parameters at boot time.


The sysctl command equivalent to the modification I made manually in the previous section would be:

# sysctl -w fs.file-max=25000 fs.file-max = 25000 # _ 


The same restriction applies: unless this change is made at boot time (e.g., added to /etc/sysctl.conf), the kernel will revert to its previous setting after a reboot.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net