嵌入式linux中文站在线图书

Previous Page
Next Page

23.7. Tuning via /proc Filesystem

The /proc filesystem was introduced in Chapter 3; it provides a simple interface for users to view and change kernel parameters and is the model for the newer sysfs directory. It contains a huge number of files (or rather, virtual data structures that look to the user just like files) that map to variables and functions inside the kernel and that can be used to tune the behavior of the networking component of the kernel as well.

The files used for IPv4 tuning are located mainly in two directories:


/proc/sys/net/ipv4/

Table 23-2 shows some of the files in this directory that are used by IPv4. The kernel variables associated with those files are declared in net/ipv4/sysctl_net_ipv4.c and are statically registered at boot time (see Chapter 3). Note that the directory contains many more files than the ones in Table 23-2. Most of the extra files are associated with L4 protocols, especially TCP.


/proc/sys/net/ipv4/conf/

This directory contains a subdirectory for each network device recognized by the kernel, plus other special directories (see Figure 36-4 in Chapter 36). Those subdirectories include configuration parameters that are device specific; among them are accept_redirects, send_redirects, accept_source_route, and forwarding. These will be covered in Chapter 36, with the exception of promote_secondaries, which is described in the section "Main Functions That Manipulate IP Addresses and Configuration."

Table 23-2. IPv4-related files in /proc/sys/net/ipv4

/proc filename

Associated kernel variable

Default value

ip_forward

ipv4_devconf.forwarding

0

ip_no_pmtu_disc

ipv4_config.no_pmtu_disc

0

ip_autoconfig

ipv4_config.autoconfig

0

ip_default_ttl

sysctl_ip_default_ttl

IPDEFTTL (64)

ip_nonlocal_bind

sysctl_ip_nonlocal_bind

0

ip_local_port_range

sysctl_ip_local_port_range[0]

sysctl_ip_local_port_range[1]

1

65535a

ipfrag_high_tresh

sysctl_ipfrag_high_thresh

256K

ipfrag_low_tresh

sysctl_ipfrag_low_thresh

192K

ipfrag_time

sysctl_ipfrag_time

IP_FRAG_TIME (30 * HZ)

ipfrag_secret_interval

sysctl_ipfrag_secret_interval

10 * 60 * HZ

ip_dynaddr

sysctl_ip_dynaddr

0

inet_peer_gc_maxtime

inet_peer_gc_maxtime

120 * HZ

inet_peer_gc_mintime

inet_peer_gc_mintime

10 * HZ

inet_peer_maxttl

inet_peer_maxttl

10 * 60 * HZ

inet_peer_minttl

inet_peer_minttl

120 * HZ

inet_peer_threshold

inet_peer_threshold

65536 + 128b

a These values are updated by tcp_init at boot time based on the amount of memory available in the system. Even if they are updated by TCP, they are used by any L4 protocol that uses ports.

b This value is updated by inet_initpeers at boot time based on the amount of memory available in the system.


The first three elements in Table 23-2 are members of two data structures of type ipv4_devconf and ipv4_config, located, respectively, in include/linux/inetdevice.h and include/net/ip.h and described later in this chapter. The other elements of those structures are either exported elsewhere or not exported at all (we will cover them in the associated chapters). The meaning of the files and kernel variables is as follows:


ip_forward

Set to a nonzero value to enable the device to forward traffic. See the section "Enabling and Disabling Forwarding" in Chapter 36.


ip_no_pmtu_disc

When 0, path MTU discovery is enabled.


ip_autoconfig

This is set to 1 when the IP configuration of the host was done via a protocol such as DHCP. See the section "IP Configuration."


ip_default_ttl

This is the default value of the IP TTL field used for unicast traffic. Multicast traffic uses the default value of 1 and does not have an equivalent sysctl variable to set it.


ip_nonlocal_bind

When nonzero, it is possible for an application to bind to an address that is not local to the host. This allows, for instance, binding a socket to an address even if the associated interface is down.


ip_local_port_range

Range of ports that can be used for outgoing connections.


ipfrag_high_thresh


ipfrag_low_thresh

Thresholds used to limit the amount of memory used by incoming IP fragments. When the memory used by fragments reaches ipfrag_high_thresh, old entries are removed until the memory used declines to ipfrag_low_thresh. See the section "Garbage Collection."


ipfrag_time

Maximum amount of time incoming IP fragments are kept in memory before expiring.


ipfrag_secret_interval

Interval after which the incoming IP fragments that are in the hash table are extracted and reinserted with a different hash function. See the section "Hash Table Reorganization" in Chapter 22.


ip_dynaddr

This variable is used to handle the case of sockets bound to addresses associated with dial-on-demand interfaces that do not receive any reply until the interface comes up. If ip_dynaddr is set, the sockets will retry binding.


inet_peer_threshold

Maximum number of inet_peer structures that can be allocated.


inet_peer_gc_maxtime


inet_peer_gc_mintime

Amount of time between regular garbage collection passes. Since the amount of memory usable by the inet_peer structures is limited (by inet_peer_threshold), there is a regular timer that expires unused entries based on these two variables. inet_peer_gc_maxtime is used when the system is not heavily loaded, and inet_peer_gc_mintime is used in the opposite case. Thus, the more entries there are, the more frequently the timer expires.


inet_peer_maxttl


inet_peer_minttl

Maximum and minimum TTL of inet_peer enTRies. Its value is supposed to be bigger than sysctl_ipfrag_time, for obvious reasons.


Previous Page
Next Page