提交 4acb4190 编写于 作者: G Glauber Costa 提交者: David S. Miller

net/tcp: Fix tcp memory limits initialization when !CONFIG_SYSCTL

sysctl_tcp_mem() initialization was moved to sysctl_tcp_ipv4.c
in commit 3dc43e3e, since it
became a per-ns value.

That code, however, will never run when CONFIG_SYSCTL is
disabled, leading to bogus values on those fields - causing hung
TCP sockets.

This patch fixes it by keeping an initialization code in
tcp_init(). It will be overwritten by the first net namespace
init if CONFIG_SYSCTL is compiled in, and do the right thing if
it is compiled out.

It is also named properly as tcp_init_mem(), to properly signal
its non-sysctl side effect on TCP limits.
Reported-by: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NGlauber Costa <glommer@parallels.com>
Cc: David S. Miller <davem@davemloft.net>
Link: http://lkml.kernel.org/r/4F22D05A.8030604@parallels.com
[ renamed the function, tidied up the changelog a bit ]
Signed-off-by: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 8a8ee9af
...@@ -311,6 +311,8 @@ extern struct proto tcp_prot; ...@@ -311,6 +311,8 @@ extern struct proto tcp_prot;
#define TCP_ADD_STATS_USER(net, field, val) SNMP_ADD_STATS_USER((net)->mib.tcp_statistics, field, val) #define TCP_ADD_STATS_USER(net, field, val) SNMP_ADD_STATS_USER((net)->mib.tcp_statistics, field, val)
#define TCP_ADD_STATS(net, field, val) SNMP_ADD_STATS((net)->mib.tcp_statistics, field, val) #define TCP_ADD_STATS(net, field, val) SNMP_ADD_STATS((net)->mib.tcp_statistics, field, val)
extern void tcp_init_mem(struct net *net);
extern void tcp_v4_err(struct sk_buff *skb, u32); extern void tcp_v4_err(struct sk_buff *skb, u32);
extern void tcp_shutdown (struct sock *sk, int how); extern void tcp_shutdown (struct sock *sk, int how);
......
...@@ -814,6 +814,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net) ...@@ -814,6 +814,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
net->ipv4.sysctl_rt_cache_rebuild_count = 4; net->ipv4.sysctl_rt_cache_rebuild_count = 4;
tcp_init_mem(net);
limit = nr_free_buffer_pages() / 8; limit = nr_free_buffer_pages() / 8;
limit = max(limit, 128UL); limit = max(limit, 128UL);
net->ipv4.sysctl_tcp_mem[0] = limit / 4 * 3; net->ipv4.sysctl_tcp_mem[0] = limit / 4 * 3;
......
...@@ -3216,6 +3216,16 @@ static int __init set_thash_entries(char *str) ...@@ -3216,6 +3216,16 @@ static int __init set_thash_entries(char *str)
} }
__setup("thash_entries=", set_thash_entries); __setup("thash_entries=", set_thash_entries);
void tcp_init_mem(struct net *net)
{
/* Set per-socket limits to no more than 1/128 the pressure threshold */
unsigned long limit = nr_free_buffer_pages() / 8;
limit = max(limit, 128UL);
net->ipv4.sysctl_tcp_mem[0] = limit / 4 * 3;
net->ipv4.sysctl_tcp_mem[1] = limit;
net->ipv4.sysctl_tcp_mem[2] = net->ipv4.sysctl_tcp_mem[0] * 2;
}
void __init tcp_init(void) void __init tcp_init(void)
{ {
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
...@@ -3276,9 +3286,9 @@ void __init tcp_init(void) ...@@ -3276,9 +3286,9 @@ void __init tcp_init(void)
sysctl_tcp_max_orphans = cnt / 2; sysctl_tcp_max_orphans = cnt / 2;
sysctl_max_syn_backlog = max(128, cnt / 256); sysctl_max_syn_backlog = max(128, cnt / 256);
/* Set per-socket limits to no more than 1/128 the pressure threshold */ tcp_init_mem(&init_net);
limit = ((unsigned long)init_net.ipv4.sysctl_tcp_mem[1]) limit = nr_free_buffer_pages() / 8;
<< (PAGE_SHIFT - 7); limit = max(limit, 128UL);
max_share = min(4UL*1024*1024, limit); max_share = min(4UL*1024*1024, limit);
sysctl_tcp_wmem[0] = SK_MEM_QUANTUM; sysctl_tcp_wmem[0] = SK_MEM_QUANTUM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册