# Most versions of UNIX have a very low default buffer limit, which should be increased to at least 2MB. Also, note that UDP recommendations are only applicable for configurations which explicitly configure UDP in favor of TCP as TCP is the default for performance sensitive tasks.


# for read

cat /proc/sys/net/ipv4/tcp_rmem

# for write

cat /proc/sys/net/ipv4/tcp_wmem


sysctl net.ipv4.tcp_rmem

sysctl net.ipv4.tcp_wmem


sysctl -w net.core.rmem_max=2097152

sysctl -w net.core.wmem_max=2097152



# However, the default socket buffers are just set when the sock is initialised but the kernel then dynamically sizes them (unless set using setsockopt() with SO_SNDBUF). The actual size of the buffers for currently open sockets may be inspected using the ss command (part of the iproute package), which can also provide a bunch more info on sockets like congestion control parameter etc. E.g. To list the currently open TCP (t option) sockets and associated memory (m) information:


ss -m --info

ss -tm


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's a brief explanation of skmem (socket memory) - for more info you'll need to look at the kernel sources (e.g. 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


# There is also /proc/sys/net/core/rmem_default for recv and /proc/sys/net/core/wmem_default for send

cat /proc/sys/net/core/rmem_default

cat /proc/sys/net/core/wmem_default


#!/bin/bash
#
# aggregate size limitations for all connections, measured in pages; these values
# are for 4KB pages (getconf PAGESIZE)

/sbin/sysctl -w net.ipv4.tcp_mem=' 65536 131072 262144'

# limit on receive space bytes per-connection; overridable by SO_RCVBUF; still
# goverened by core.rmem_max

/sbin/sysctl -w net.ipv4.tcp_rmem=' 262144 4194304 8388608'

# limit on send space bytes per-connection; overridable by SO_SNDBUF; still
# goverered by core.wmem_max

/sbin/sysctl -w net.ipv4.tcp_wmem=' 65536 1048576 2097152'

# absolute limit on socket receive space bytes per-connection; cannot be
# overriden programatically

/sbin/sysctl -w net.core.rmem_max=16777216

# absolute limit on socket send space bytes per-connection; cannot be overriden;
# cannot be overriden programatically

/sbin/sysctl -w net.core.wmem_max=16777216