How to find linux socket buffer size

What is the default socket buffer size for linux? Is there a team to see this?

+53
linux sockets buffer
Oct 23 '11 at 8:05
source share
5 answers

If you want to see the size of your buffer in the terminal, you can see:

  • /proc/sys/net/ipv4/tcp_rmem (for reading)
  • /proc/sys/net/ipv4/tcp_wmem (for writing)

They contain three numbers, which are the minimum, standard, and maximum values ​​of the memory size (in bytes), respectively.

+99
Oct 23 '11 at 8:26
source share

To get the buffer size in a c / C ++ program, the following is a stream

 int n; unsigned int m = sizeof(n); int fdsocket; fdsocket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); // example getsockopt(fdsocket,SOL_SOCKET,SO_RCVBUF,(void *)&n, &m); // now the variable n will have the socket size 
+28
Jul 12 2018-12-12T00:
source share

Although, as mentioned, in /proc you can see the current default socket buffer sizes, but you can also check them using sysctl (Note: although the name includes ipv4, these sizes also apply to ipv6 sockets - ipv6 code tcp_v6_init_sock () just calls the function ipv4 tcp_init_sock ()):

  sysctl net.ipv4.tcp_rmem sysctl net.ipv4.tcp_wmem 

However, by default, socket buffers are simply set when sock is initialized, and then the kernel dynamically resizes them (if not set using setsockopt () with SO_SNDBUF). The actual buffer size for currently open sockets can be checked using the ss command (part of the iproute package), which can also provide much more information about sockets, such as the congestion control parameter, etc. For example. To view the list of currently open TCP sockets (option t ) and their associated memory ( m ):

 ss -tm 

Here is an example output:

 State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 192.168.56.102:ssh 192.168.56.1:56328 skmem:(r0,rb369280,t0,tb87040,f0,w0,o0,bl0,d0) 

Here is a brief explanation of skmem (socket memory) - for more information, you need to take a look at the kernel source (for example, sock.h ):

 r:sk_rmem_alloc rb:sk_rcvbuf # current receive buffer size t:sk_wmem_alloc tb:sk_sndbuf # current transmit buffer size f:sk_forward_alloc w:sk_wmem_queued # persistent transmit queue size o:sk_omem_alloc bl:sk_backlog d:sk_drops 
+1
May 23 '19 at 16:23
source share

Although, as already noted, in / proc you can see the current default socket buffer sizes, but you can also check them using sysctl (Note: Although the name includes ipv4, these sizes also apply to ipv6 - ipv6 sockets). The tcp_v6_init_sock () code simply calls the ipv4 function tcp_init_sock ()):

  sysctl net.ipv4.tcp_rmem sysctl net.ipv4.tcp_wmem 

However, by default, socket buffers are simply set when sock is initialized, and then the kernel dynamically resizes them (if not set using setsockopt () with SO_SNDBUF). The actual buffer size for currently open sockets can be checked using the ss command (part of the iproute package). For example, to view a list of currently open TCP sockets ( t option) and related memory information ( m ):

 ss -tm 

Here is an example output:

 State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 192.168.56.102:ssh 192.168.56.1:56328 skmem:(r0,rb369280,t0,tb87040,f0,w0,o0,bl0,d0) 

Here is a brief explanation of skmem (memory socket) - for more information, you need to take a look at the kernel source (for example, sock.h ):

 r:sk_rmem_alloc rb:sk_rcvbuf - current receive buffer size t:sk_wmem_alloc tb:sk_sndbuf - current transmit buffer size f:sk_forward_alloc w:sk_wmem_queued - persistent transmit queue size o:sk_omem_alloc bl:sk_backlog d:sk_drops 
0
May 23 '19 at 16:21
source share

The atomic size is 4096 bytes, the maximum size is 65536 bytes. Sendfile uses 16 channels of 4096 bytes in size. cmd: ioctl (fd, FIONREAD, & buff_size).

-5
Mar 13 '15 at 10:58
source share



All Articles