All TCP/IP tuning parameters are located in the /proc/sys/net/ directory. For example, here are some of the most important tuning parameters, followed by their meanings:
1. /proc/sys/net/core/rmem_max — Maximum TCP data receiving buffer
2. /proc/sys/net/core/wmem_max — Maximum TCP data sending buffer
3. /proc/sys/net/ipv4/tcp_timestamps — The timestamp is added to the TCP header by 12 bytes (please refer to RFC 1323).
4. /proc/sys/net/ipv4/tcp_sack — selective response
5. /proc/sys/net/ipv4/tcp_window_scaling — Supports larger TCP windows. If the maximum TCP window exceeds 65535 (64K), this value must be set to 1
6. rmem_default — default receive window size
7. rmem_max — the maximum size of the receiving window
8. wmem_default — default sending window size
9. wmem_max — the maximum size of the sending window
All contents in the /proc directory are temporary, so any changes will be lost after restarting the system.
It is recommended to automatically modify the TCP/IP parameters when the system starts:
Add the following code to the /etc/rc.local file, and then save the file. The following TCP/IP parameters will be automatically modified when the system reboots:
echo 256960 > /proc/sys/net/core/rmem_default
echo 256960 > /proc/sys/net/core/rmem_max
echo 256960 > /proc/sys/net/core/wmem_default
echo 256960 > /proc/sys/net/core/wmem_max
echo 0 > /proc/sys/net/ipv4/tcp_timestamps
echo 1 > /proc/sys/net/ipv4/tcp_sack
echo 1 > /proc/sys/net/ipv4/tcp_window_scaling
TCP/IP parameters are self-explanatory, TCP window size is set to 256960, TCP timestamps are disabled (cancel adding 12 bytes to each packet header), larger TCP windows and TCP selective responses are supported .
The above values are set based on the Internet connection and maximum bandwidth/latency rate.
Note: The values in the above example can be used in practice, but they only include part of the parameters.
Another method: Use /etc/sysctl.conf to configure the parameters to the values you set when the system starts:
net.core.rmem_default = 256960
net.core.rmem_max = 256960
net.core.wmem_default = 256960
net.core.wmem_max = 256960
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_sack =1
net.ipv4.tcp_window_scaling = 1
-------------------------------------------------- ---------------
/proc/sys/fs/super-max
This file specifies the maximum number of superblock handlers. Any file system mounted requires the use of a superblock, so if a large number of file systems are mounted, the superblock handler may be exhausted.
Default setting: 256
/proc/sys/fs/super-nr
This file shows the current number of allocated superblocks. This file is read-only and is used for display information only.
/proc/sys/kernel
/proc/sys/kernel/acct
This file has three configurable values that control when process accounting begins based on the amount of free space (expressed as a percentage) on the file system containing the log:
If free space falls below this percentage value, stop process accounting
If the free space is higher than this percentage value, start process accounting
How often (in seconds) the above two values are checked
To change a value in this file, a space-separated sequence of numbers should be returned.
Default setting: 2 4 30
These values cause accounting to stop if there is less than 2% free space on the file system containing the journal, and start accounting again if there is 4% or more free space. Checks are done every 30 seconds.
/proc/sys/kernel/ctrl-alt-del
This file has a binary value that controls how the system reacts when it receives the ctrl+alt+delete key combination. These two values represent:
A value of zero (0) means that ctrl+alt+delete is captured and sent to the init program. This will allow the system to shut down and restart gracefully, just as if you entered the shutdown command.
A value of one (1) means that ctrl+alt+delete is not captured and a non-clean shutdown will be performed, as if the power was turned off directly.
Default setting: 0
/proc/sys/kernel/domainname
This file allows you to configure the network domain name. It has no default value. The domain name may or may not have been set.
/proc/sys/kernel/hostname
This file allows you to configure network hostnames. It has no default value, the hostname may or may not have been set.
/proc/ss/kernel/msgmax
This file specifies the maximum length of messages sent from one process to another. Message passing between processes occurs in the kernel's memory and is not swapped to disk, so if you increase this value, you will increase the amount of memory used by the operating system.
Default setting: 8192
/proc/sys/kernel/msgmnb
This file specifies the maximum number of bytes in a message queue.
Default setting: 16384
/proc/sys/kernel/msgmni
This file specifies the maximum number of Message Queuing IDs.
Default setting: 16
/proc/sys/kernel/panic
This file indicates how long, in seconds, the kernel waits before rebooting if a "kernel panic" occurs. A setting of zero (0) seconds will disable a reboot in the event of a kernel panic.
Default setting: 0
/proc/sys/kernel/printk
This file has four numeric values that define where the logging message is sent based on its importance. For more information about the different log levels, read the syslog(2) manpage. The four values of this file are:
Console log level: Messages with a priority higher than this value will be printed to the console
Default message logging level: messages without priority will be printed with this priority
Minimum console log level: The minimum value to which the console log level can be set (highest priority)
Default console log level: The default value for the console log level
Default setting: 6 4 1 7
/proc/sys/kernel/shmall
This file is the total amount of shared memory (in bytes) available on the system at any given moment.
Default setting: 2097152
/proc/sys/kernel/shmax
This file specifies the maximum size (in bytes) of shared memory segments allowed by the kernel.
Default setting: 33554432
/proc/sys/kernel/shmmni
This file represents the maximum number of shared memory segments used for the entire system.
Default setting: 4096
/proc/sys/kernel/sysrq
If the value specified in this file is non-zero, the System Request Key is activated.
Default setting: 0
/proc/sys/kernel/threads-max
This file specifies the maximum number of threads that the kernel can use.
Default setting: 2048
/proc/sys/net
/proc/sys/net/core/message_burst
The time (in 1/10 seconds) required to write a new warning message; other warning messages received during this time will be discarded. This is used to prevent Denial of Service attacks used by someone who attempts to "flood" your system with messages.
Default setting: 50 (5 seconds)
/proc/sys/net/core/message_cost
This file holds the cost value associated with each warning message. The larger the value, the more likely the warning message is to be ignored.
Default setting: 5
/proc/sys/net/core/netdev_max_backlog
This file specifies the maximum number of packets that are allowed to be queued when the interface receives packets faster than the kernel can process them.
Default setting: 300
/proc/sys/net/core/optmem_max
This file specifies the maximum buffer size allowed for each socket.
/proc/sys/net/core/rmem_default
This file specifies the default value for the receive socket buffer size in bytes.
/proc/sys/net/core/rmem_max
This file specifies the maximum receive socket buffer size in bytes.
/proc/sys/net/core/wmem_default
This file specifies the default value for the send socket buffer size in bytes.
/proc/sys/net/core/wmem_max
This file specifies the maximum send socket buffer size in bytes.
/proc/sys/net/ipv4
All IPv4 and IPv6 parameters are documented in the kernel source code documentation. See the file /usr/src/linux/Documentation/networking/ip-sysctl.txt.
/proc/sys/net/ipv6
Same as IPv4.
/proc/sys/vm
/proc/sys/vm/buffermem
This file controls the amount of overall system memory used for buffer memory (expressed as a percentage). It has three values, which are set by writing a sequence of numbers separated by spaces to the file.
Minimum percentage of memory used for buffers
If a situation occurs where there is not much system memory left and system memory is being reduced, the system will attempt to maintain the amount of buffer memory.
Maximum percentage of memory used for buffers
Default setting: 2 10 60
/proc/sys/vm/freepages
This file controls how the system responds to various levels of available memory. It has three values, which are set by writing a sequence of numbers separated by spaces to the file.
The kernel is only allowed to allocate some memory if the number of available pages in the system reaches a minimum limit.
If the number of free pages in the system falls below this limit, the kernel will initiate swapping in a more aggressive manner to free up memory and maintain system performance.
The kernel will try to keep this amount of system memory available. Values below this will enable kernel swapping.
Default setting: 512 768 1024
/proc/sys/vm/kswapd
This file controls how the kernel is allowed to swap memory. It has three values, which are set by writing a space-separated sequence of numbers to the file:
The maximum number of pages the kernel attempts to free at one time. If you want to increase the bandwidth during memory swapping, you need to increase this value.
The minimum number of times the kernel attempts to free a page per swap.
The number of pages written by the kernel in one swap. This has the greatest impact on system performance. The larger this value is, the more data is exchanged and the less time is spent on disk seeks. However, a value that is too large can adversely affect system performance by "flooding" the request queue.
Default setting: 512 32 8
/proc/sys/vm/pagecache
This file does the same job as /proc/sys/vm/buffermem, but is a memory map of the file and a general cache.
Make kernel settings persistent
A convenient utility is provided here for changing any kernel parameter in the /proc/sys directory. It allows you to change the running kernel (similar to the echo and redirection methods used above), but it also has a configuration file that is executed when the system boots. This allows you to make changes to the running kernel and add those changes to the configuration file so that they persist across system reboots.
This utility is called sysctl and is fully documented in the manpage for sysctl(8). The configuration file of sysctl is /etc/sysctl.conf, which can be edited and recorded under sysctl.conf(8). sysctl treats files under /proc/sys as individual variables that can be changed. Therefore, taking the file /proc/sys/fs/file-max under /proc/sys as an example, it represents the maximum number of file handles allowed in the system. This file is represented as fs.file-max.
This example reveals some wonderful things about sysctl notation. Since sysctl can only change variables in the /proc/sys directory, and people always think that variables are in this directory, that part of the variable name (/proc/sys) is omitted. Another change to note is the replacement of the directory separator (forward slash /) with the English period (dot.).
There are two simple rules for converting files in /proc/sys into variables in sysctl:
Remove the front part /proc/sys.
Change forward slashes in filenames to dots.
These two rules allow you to convert any file name in /proc/sys into any variable name in sysctl. The general conversion from file to variable is:
/proc/sys/dir/file --> dir.file
dir1.dir2.file --> /proc/sys/dir1/dir2/file
You can use the command sysctl -a to view all variables that can be changed and their current settings.
Variables can also be changed using sysctl, which does exactly the same thing as the echo method used above. Its representation is:
sysctl -w dir.file="value"
Using file-max as an example again, use one of the following two methods to change the value to 16384.