Author:阿冬哥
Created:2013-4-17
Blog:http://blog.csdn.net/c359719435/
Copyright 2013 阿冬哥 http://blog.csdn.net/c359719435/
使用以及转载请注明出处
1 case SO_SNDBUF: 2 /* Don‘t error on this BSD doesn‘t and if you think 3 about it this is right. Otherwise apps have to 4 play ‘guess the biggest size‘ games. RCVBUF/SNDBUF 5 are treated in BSD as hints */ 6 7 if (val > sysctl_wmem_max)//val是我们想设置的缓冲区大小的值 8 val = sysctl_wmem_max;//大于最大值,则val值设置成最大值 9 10 sk->sk_userlocks |= SOCK_SNDBUF_LOCK; 11 if ((val * 2) < SOCK_MIN_SNDBUF)//val的两倍小于最小值,则设置成最小值 12 sk->sk_sndbuf = SOCK_MIN_SNDBUF; 13 else 14 sk->sk_sndbuf = val * 2;//val的两倍大于最小值,则设置成val值的两倍 15 16 /* 17 * Wake up sending tasks if we 18 * upped the value. 19 */ 20 sk->sk_write_space(sk); 21 break; 22 23 case SO_RCVBUF: 24 /* Don‘t error on this BSD doesn‘t and if you think 25 about it this is right. Otherwise apps have to 26 play ‘guess the biggest size‘ games. RCVBUF/SNDBUF 27 are treated in BSD as hints */ 28 29 if (val > sysctl_rmem_max) 30 val = sysctl_rmem_max; 31 32 sk->sk_userlocks |= SOCK_RCVBUF_LOCK; 33 /* FIXME: is this lower bound the right one? */ 34 if ((val * 2) < SOCK_MIN_RCVBUF) 35 sk->sk_rcvbuf = SOCK_MIN_RCVBUF; 36 else 37 sk->sk_rcvbuf = val * 2; 38 break;
1 SO_RCVBUF: 2 Sets or gets the maximum socket receive buffer in bytes. 3 The kernel doubles this value (to allow space for bookkeeping overhead) when it is set using setsockopt(2), 4 and this doubled value is returned by getsockopt(2). 5 The default value is set by the /proc/sys/net/core/rmem_default file, 6 and the maximum allowed value is set by the /proc/sys/net/core/rmem_max file. 7 The minimum (doubled) value for this option is 256.
[root@cfs_netstorage core]# cat /proc/sys/net/core/rmem_default1048576[root@cfs_netstorage core]# cat /proc/sys/net/core/wmem_default512488
/proc/sys/net/ipv4/tcp_wmem[root@cfs_netstorage core]# cat /proc/sys/net/ipv4/tcp_wmem4096 16384 131072 //第一个表示最小值,第二个表示默认值,第三个表示最大值。/proc/sys/net/ipv4/tcp_rmem[root@cfs_netstorage core]# cat /proc/sys/net/ipv4/tcp_rmem4096 87380 174760
原文:https://www.cnblogs.com/shihuvini/p/9927549.html