Reputation: 33
I'm trying to increase the size of my socket receive buffer size using setsockopt() on linux. I can set it successfully to any value below 244KB. Any value above 244KB gets truncated to 244KB.
There appears to be some sort of system limit in place, but I can't figure where it is coming from, as it doesn't correspond with values below:
$ 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
The default value is 87380 as expected, but I can't increase it to 4194304. It gets limited to 244KB. Interestingly that value is 2X rmem_default, do I need to change that?
Thanks
Upvotes: 1
Views: 1431
Reputation: 3541
From man page for 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 what you pass for SO_SNDBUF/SO_RCVBUF
gets doubled while allocation. And as such you cannot pass the max value (4194304) in setsockopt
Upvotes: 3