Linux UDP 接收缓冲区的最大大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16460261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:53:56  来源:igfitidea点击:

Linux UDP max size of receive buffer

linuxsocketsnetwork-programmingudpbuffer

提问by Wac?aw Borowiec

What's the maximum size of Linux UDP receive buffer? I thought it's limited only by available RAM, but when I set

Linux UDP 接收缓冲区的最大大小是多少?我认为它仅受可用 RAM 的限制,但是当我设置

5GB for rmem_max:

rmem_max 为 5GB:

echo 5000000000 > /proc/sys/net/core/rmem_max

and 4GB for the actual socket buffer (in Erlang):

和 4GB 用于实际套接字缓冲区(在 Erlang 中):

gen_udp:listen(Port, [{recbuf, 4000000000}])

When I measure the buffer utilization, it shows:

当我测量缓冲区利用率时,它显示:

# netstat -u6anp | grep 5050
udp6  1409995136      0 :::5050  :::*       13483/beam.smp

I can't exceed this 1.4GB. For smaller buffer sizes, like e.g. 500MB, actual buffer size matched the configured value. My system is Debian 6.0, the machine has 50GB RAM available.

我不能超过这 1.4GB。对于较小的缓冲区大小,例如 500MB,实际缓冲区大小与配置值匹配。我的系统是 Debian 6.0,机器有 50GB RAM 可用。

采纳答案by Lech G?owiak

It seems that there is a limit in linux. I have tried setting rmem_max to 2^32-1 with success.

linux 好像有个限制。我尝试将 rmem_max 设置为 2^32-1 并成功。

   root@xxx:/proc/sys/net/core# echo 2147483647 > rmem_max
   root@xxx:/proc/sys/net/core# cat rmem_max
   2147483647

2^32 was too much:

2^32 太多了:

   root@xxx:/proc/sys/net/core# echo 2147483648 > rmem_max
   root@xxx:/proc/sys/net/core# cat rmem_max
   -18446744071562067968

Setting to 5000000000 yields:

设置为 5000000000 收益率:

   root@xxx:/proc/sys/net/core# echo 5000000000 > rmem_max
   root@xxx:/proc/sys/net/core# cat rmem_max
   705032704

I have tested in python that setting and getting socket receive buffer with

我已经在 python 中测试了设置和获取套接字接收缓冲区

   ss.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, bufferSize)
   print ss.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)

If 'bufferSize' is less then 1024^3 program prints doubled 'bufferSize', otherwise it falls back to 256.

如果 'bufferSize' 小于 1024^3 程序打印出双倍的 'bufferSize',否则返回到 256。

The value 705032704*2 = 1410065408 is close to the 1409995136 obtained by netstat.

值705032704*2 = 141006540​​8 接近netstat 得到的1409995136。

回答by Ivan Hamilton

2^32-1 (2147483647, maximum 32bit signed integer)

2^32-1(2147483647,最大 32 位有符号整数)

root@root@localhost:~# sysctl -w net.core.rmem_max=2147483647
net.core.rmem_max = 2147483647

root@localhost:~# sysctl -w net.core.rmem_max=2147483648
sysctl: setting key "net.core.rmem_max": Invalid argument
net.core.rmem_max = 2147483648

Echoing into the /procfilesystem appears to overflow when attempting to set larger values.

呼应到/proc文件系统中尝试设置较大的值时,会出现溢出。