Commit c43b874d authored by Jason Wang's avatar Jason Wang Committed by David S. Miller

tcp: properly initialize tcp memory limits

Commit 4acb4190 tries to fix the using uninitialized value
introduced by commit 3dc43e3e,  but it would make the
per-socket memory limits too small.

This patch fixes this and also remove the redundant codes
introduced in 4acb4190.
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Acked-by: default avatarGlauber Costa <glommer@parallels.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 786f5281
...@@ -778,7 +778,6 @@ EXPORT_SYMBOL_GPL(net_ipv4_ctl_path); ...@@ -778,7 +778,6 @@ EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
static __net_init int ipv4_sysctl_init_net(struct net *net) static __net_init int ipv4_sysctl_init_net(struct net *net)
{ {
struct ctl_table *table; struct ctl_table *table;
unsigned long limit;
table = ipv4_net_table; table = ipv4_net_table;
if (!net_eq(net, &init_net)) { if (!net_eq(net, &init_net)) {
...@@ -815,11 +814,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net) ...@@ -815,11 +814,6 @@ 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); tcp_init_mem(net);
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;
net->ipv4.ipv4_hdr = register_net_sysctl_table(net, net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
net_ipv4_ctl_path, table); net_ipv4_ctl_path, table);
......
...@@ -3229,7 +3229,6 @@ __setup("thash_entries=", set_thash_entries); ...@@ -3229,7 +3229,6 @@ __setup("thash_entries=", set_thash_entries);
void tcp_init_mem(struct net *net) 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; unsigned long 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;
...@@ -3298,7 +3297,8 @@ void __init tcp_init(void) ...@@ -3298,7 +3297,8 @@ void __init tcp_init(void)
sysctl_max_syn_backlog = max(128, cnt / 256); sysctl_max_syn_backlog = max(128, cnt / 256);
tcp_init_mem(&init_net); tcp_init_mem(&init_net);
limit = nr_free_buffer_pages() / 8; /* Set per-socket limits to no more than 1/128 the pressure threshold */
limit = nr_free_buffer_pages() << (PAGE_SHIFT - 10);
limit = max(limit, 128UL); limit = max(limit, 128UL);
max_share = min(4UL*1024*1024, limit); max_share = min(4UL*1024*1024, limit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment