Tuning a Linux kernel
Many modules and drivers in the kernel were designed with the knowledge that one size doesn't fit all. To increase flexibility, special hooks allow parameters such as an internal table's size or the kernel's behavior in a particular circumstance to be adjusted on the fly by the system administrator. These hooks are accessible through an extensive kernel-to-userland interface represented by files in the /proc filesystem. In many cases, a large user-level application (especially an "infrastructure" application such as a database) will require you to adjust parameters to accommodate its needs.
Special files in /proc/sys let you view and set kernel options at run time. These files mimic standard Linux files, but they are really back doors into the kernel. If one of these files has a value you would like to change, you can try writing to it. Unfortunately, not all of the files can be written to (regardless of their apparent permissions), and no documentation tells you which ones can and cannot be written.
For example, to change the maximum number of open files a process can have, try something like
# echo 32768 > /proc/sys/fs/file-max
Once you get used to this unorthodox interface, you'll find it quite useful, especially for changing configuration options. A word of caution, however: changes are not remembered across reboots. If you want to make permanent changes, you should use the /etc/sysctl.conf file documented below. Table 12.1 lists some useful options.
Table 12.1 Files in /proc/sys for some sample tunable kernel parameters
Dir1 |
File |
Default |
Function |
|
|
|
|
F |
file-max |
4096 |
Sets max # of open files per process |
F |
inode-max |
16384 |
Sets max # of open inodes per process |
N |
ip_forward |
0 |
Allows IP forwarding when set to 1 |
N |
icmp_echo_ignore_all |
0 |
Ignores ICMP pings when set to 1 |
N |
icmp_echo_ignore_broadcasts |
0 |
Ignores broadcast pings when set to 1 |
K |
shmmax |
32M |
Sets max shared memory size |
K |
ctrl-alt-del |
0 |
Reboot on Ctrl-Alt-Delete sequence? |
C |
autoeject |
0 |
Auto-eject CD-ROM on dismount? |
A less kludgy way to modify these same parameters can be found on most systems in the form of the sysctl command. sysctl can set individual variables either from the command line or by reading a list of variable=value pairs from a file. By default, the file /etc/sysctl.conf is read at boot time and its contents used to set initial (custom) parameter values.
For example, the command
# sysctl net.ipv4.ip_forward=0
turns off IP forwarding. Note that you form the variable names used by sysctl by replacing the /'s in the /proc/sys directory structure with dots.