How to query tcp buffer sizes for a certain socket?

Latest response

Hi folks,

Does anybody know how to query the tcp buffer sizes for certain socket?

For example lets say I run iperf3 -c foo.example.com and want to query the tcp buffer sizes that are used for the tcp socket created for iperf3. How could I do that?

I tried to get a look into the file descriptor by running cat /proc/<PID>/fd/3 and so on but got a 'no such file or directory' error every time.

I do not want to query the general limits from /proc/sys/net/ipv4/tcp_mem. I would like to know the concrete parameters for a certain socket.

Thanks in advance for your help.

Best regards,
Joerg K.

Responses

The -m switch of ss gives socket memory info.

# ss -ntmp
State      Recv-Q Send-Q Local Address:Port  Peer Address:Port
ESTAB      0      0      10.xx.xx.xxx:22     10.yy.yy.yyy:12345  users:(("sshd",pid=1442,fd=3))
         skmem:(r0,rb369280,t0,tb87040,f4096,w0,o0,bl0,d92)

Here we can see this socket has Receive Buffer 369280 bytes, and Transmit Buffer 87040 bytes.

Keep in mind the kernel will double any socket buffer allocation for overhead. So a process asks for 256 KiB buffer with setsockopt(SO_RCVBUF) then it will get 512 KiB buffer space. This is described on man 7 tcp.

The entire print format of ss -m is given in the source:

        printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u",
               skmeminfo[SK_MEMINFO_RMEM_ALLOC],
               skmeminfo[SK_MEMINFO_RCVBUF],
               skmeminfo[SK_MEMINFO_WMEM_ALLOC],
               skmeminfo[SK_MEMINFO_SNDBUF],
               skmeminfo[SK_MEMINFO_FWD_ALLOC],
               skmeminfo[SK_MEMINFO_WMEM_QUEUED],
               skmeminfo[SK_MEMINFO_OPTMEM]);

        if (RTA_PAYLOAD(tb[attrtype]) >=
                (SK_MEMINFO_BACKLOG + 1) * sizeof(__u32))
                printf(",bl%u", skmeminfo[SK_MEMINFO_BACKLOG]);

        if (RTA_PAYLOAD(tb[attrtype]) >=
                (SK_MEMINFO_DROPS + 1) * sizeof(__u32))
                printf(",d%u", skmeminfo[SK_MEMINFO_DROPS]);

        printf(")");

I expect that the ALLOC values are only used when there is outstanding data - either data in a receive buffer waiting for an application to recv(), or un-ACKed sent data. You could test these with Ctrl+z to put a receiver to sleep, and firewalls to block ACKs. It's easier to use nc than iperf for that sort of testing. Socket option memory is rarely used.

Hi,

Thanks for your answer. That helps a lot.

Best regards, Joerg K.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.