• 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.


  • 相关阅读:
    extern--C#调用C++等其他非托管代码
    unhandledException详细介绍
    MySql如何安装?
    Mindoc搭建流程
    反射_IsDefined判断方法上有自定义的标签
    WebApi_返回Post格式数据
    编码
    IP地址与MAC地址
    Tcp/Ip:Telnet指令
    create-react-app使用的问题
  • 原文地址:https://www.cnblogs.com/ztguang/p/15742453.html
Copyright © 2020-2023  润新知