Network---TCP buffer configuration

Source: Internet
Author: User
Tags memory usage min socket

Get all configuration related to TCP buffers in the Linux environment:

Net.ipv4.tcp_mem = 64608 86144 129216

Net.ipv4.tcp_wmem = 4096 16384 2756608

Net.ipv4.tcp_rmem = 4096 87380 2756608

Net.core.wmem_max = 262144

Net.core.rmem_max = 1048576

Net.core.wmem_default = 262144

Net.core.rmem_default = 1048576

The configuration for the Net.core begins with the network layer general configuration, and the Net.ipv4 begins with a configuration of IPv4 using the network configuration.

Net.core.wmem_max

Maximum Network Send window, unit byte, TCP protocol, when using setsockopt () to modify SO_SNDBUF, the maximum can only be modified to "net.core.wmem_max*2".

Net.core.wmem_default

Network Send window default size, unit bytes, in the TCP protocol, actually by net.ipv4.tcp_wmem[1] configuration coverage, feeling useless.

Net.core.rmem_max

Maximum Network receive window, unit byte, TCP protocol, when using setsockopt () to modify SO_RCVBUF, the maximum can only be modified to "net.core.rmem_max*2".

Net.core.rmem_default

The default size of the network receive window, the unit bytes, in the TCP protocol, is actually covered by the net.ipv4.tcp_rmem[1] configuration, which is estimated to be used in other protocols.

Net.ipv4.tcp_rmem

The TCP protocol defines each socket link that receives a window size, in bytes, with three values: Min, default, Max.

Min defaults to pagesize (4K bytes), each socket receives a lower limit of window size;

Default for each socket after a chain of the defaults to receive the window size, the default value is 16K, so-called window size is only a limit value, the actual corresponding memory buffer is allocated by the protocol stack management;

Max receives the maximum window size for each socket link, which is only valid when the SNDBUF is not modified with setsockopt () and is used to automatically adjust the upper limit of the window size for the TCP stack.

Net.ipv4.tcp_wmem

Each socket link defined by the TCP protocol sends a window size, in bytes, with three values: Min, default, Max, and the exact meaning is similar to Net.ipv4.tcp_rmem.

Net.ipv4.tcp_mem

TCP stack all link memory consumption limits, Unit pagesize (4K), including 3 configuration low, pressure, and high, typically these values are calculated based on the amount of system memory at system startup and do not require modification by the worker. The memory consumption of the entire system TCP link corresponds to the "Tcp:mem" value of/proc/net/sockstat.

Low: TCP does not consider freeing memory when TCP uses a number of memory pages below this value;

Pressure: When TCP uses more memory pages than this value, TCP attempts to stabilize its memory usage, enters pressure mode, and exits the pressure state when memory consumption is below the low value;

High: Allows all TCP sockets to queue buffer datagrams for the amount of pages, if this value is exceeded, the TCP connection will be rejected and errno to "enomem out of socket memory".

real-time observation of the system socket usage:

Cat/proc/net/sockstat

Sockets:used 294

Tcp:inuse Orphan 0 tw 0 alloc Mem 4

Udp:inuse 4 Mem 0

Udplite:inuse 0

Raw:inuse 0

Frag:inuse 0 Memory 0

Sockets:used: Total amount of all protocol sockets used

Tcp:inuse: Number of TCP sockets in use (listening), whose value is not more than NETSTAT–LNT | grep ^tcp | Wc–l

Tcp:orphan: Orphan TCP connections that do not belong to any process (useless, number of TCP sockets to be destroyed)

TCP:TW: Number of TCP connections waiting to be closed with values equal to time_wait status chain

Tcp:alloc (Allocated): The number of TCP sockets that have been allocated (established, requested to sk_buff). Its value equals Netstat–ant | grep ^tcp | Wc–l

TCP:MEM: Socket buffer Usage (per page size), which corresponds to the memory overhead of all TCP links in the system.

Udp:inuse: Number of UDP sockets in use

RAW: Simple IP layer Socket

FRAG: Number of IP segments used

setsockopt () source code:

Case SO_SNDBUF:

if (val > Sysctl_wmem_max)

val = Sysctl_wmem_max; Limit input Val value Max is Wmem_max

Sk->sk_userlocks |= sock_sndbuf_lock;//Lock, limit the sending window to adjust automatically

if ((Val * 2) < SOCK_MIN_SNDBUF)

Sk->sk_sndbuf = Sock_min_sndbuf; Send window minimum is 2K

Else

Sk->sk_sndbuf = val * 2; The actual send window is twice times the set value

Sk->sk_write_space (SK); Triggering a send operation after modifying the Send window

Break

setsockopt () Modify the Send window, receive window has these characteristics:

Maximum limited Net.core.rmem_max, Net.core.wmem_max;

After the modification, the window cannot be automatically adjusted by the protocol stack, the default window size can vary within a certain range, and if modified correctly, the actual modified value is twice times the value of the passed parameter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.