14.11. Tunable Kernel ParametersThe 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 SystemThe /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. 14.11.2. The sysctl UtilityAs 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.
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. |