zoukankan      html  css  js  c++  java
  • 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.


  • 相关阅读:
    Go语言入门
    简述cookies 和 session
    Linux inode 理解
    BZOJ 1012 最大数maxnumber
    BZOJ 1087 互不侵犯king
    CSS从大图中抠取小图完整教程(background-position应用)
    javascript中i++与++i
    脱离文档流分析
    在Windows上以zip压缩包方式安装mysql
    centos7 python2.7下安装paramiko模块
  • 原文地址:https://www.cnblogs.com/ztguang/p/15742453.html
Copyright © 2011-2022 走看看