【问题标题】:Setting Socket Receive Buffer Size, gets truncated to 244KB设置套接字接收缓冲区大小,被截断为 244KB
【发布时间】:2015-05-18 18:31:38
【问题描述】:

我正在尝试在 linux 上使用 setsockopt() 来增加我的套接字接收缓冲区大小。我可以成功地将其设置为低于 244KB 的任何值。任何超过 244KB 的值都会被截断为 244KB。

似乎存在某种系统限制,但我无法确定它的来源,因为它与以下值不对应:

$ cat /proc/sys/net/ipv4/tcp_rmem 
4096    87380   4194304
$ cat /proc/sys/net/ipv4/tcp_wmem 
4096    16384   4194304
$ cat /proc/sys/net/core/rmem_default 
124928
$ cat /proc/sys/net/core/wmem_default 
124928

默认值为 87380,但我无法将其增加到 4194304。它被限制为 244KB。有趣的是,该值为 2X rmem_default,我需要更改它吗?

谢谢

【问题讨论】:

    标签: linux sockets buffer


    【解决方案1】:

    来自 TCP 的手册页:

       The maximum sizes for socket buffers declared  via  the    SO_SNDBUF  and
       SO_RCVBUF  mechanisms  are  limited by the global net.core.rmem_max and
       net.core.wmem_max sysctls.  Note that TCP actually allocates twice  the
       size  of  the buffer requested in the setsockopt(2) call, and so a suc-
       ceeding getsockopt(2) call will not return the same size of  buffer  as
       requested  in  the  setsockopt(2)  call
    

    所以你传递给SO_SNDBUF/SO_RCVBUF 的东西在分配时会翻倍。因此,您不能在setsockopt 中传递最大值(4194304)

    【讨论】:

    • 谢谢,我可以通过改变 net.core.rmem_max 来改变它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 2011-11-15
    • 2015-03-18
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    相关资源
    最近更新 更多