Linux UDP max size of receive buffer

后端 未结 2 1071
梦如初夏
梦如初夏 2021-02-03 11:13

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

5GB for rmem_max:

echo 5000000000 >         


        
相关标签:
2条回答
  • 2021-02-03 11:44

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

    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 /proc filesystem appears to overflow when attempting to set larger values.

    0 讨论(0)
  • 2021-02-03 11:47

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

       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:

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

    Setting to 5000000000 yields:

       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

       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.

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

    0 讨论(0)
提交回复
热议问题