其他分享
首页 > 其他分享> > How to query tcp buffer sizes for a certain socket?

How to query tcp buffer sizes for a certain socket?

作者:互联网

https://access.redhat.com/discussions/3624151

 

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.


 

标签:MEMINFO,socket,sizes,buffer,SK,skmeminfo,printf
来源: https://www.cnblogs.com/ztguang/p/15742453.html