linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits
@ 2012-02-02 10:07 Jason Wang
  2012-02-02 10:39 ` Glauber Costa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jason Wang @ 2012-02-02 10:07 UTC (permalink / raw)
  To: netdev, jasowang, davem, linux-kernel, glommer; +Cc: mst

Commit 4acb4190 tries to fix the using uninitialized value
introduced by commit 3dc43e3,  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: Jason Wang <jasowang@redhat.com>
---
 net/ipv4/sysctl_net_ipv4.c |    5 -----
 net/ipv4/tcp.c             |    4 ++--
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 4cb9cd2..1eb8caa 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -815,11 +815,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
 	net->ipv4.sysctl_rt_cache_rebuild_count = 4;
 
 	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_ctl_path, table);
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 06373b4..3a7514b 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3218,7 +3218,6 @@ __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;
@@ -3287,7 +3286,8 @@ void __init tcp_init(void)
 	sysctl_max_syn_backlog = max(128, cnt / 256);
 
 	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);
 	max_share = min(4UL*1024*1024, limit);
 


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits
  2012-02-02 10:07 [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits Jason Wang
@ 2012-02-02 10:39 ` Glauber Costa
  2012-02-02 19:27 ` David Miller
  2012-02-03  3:26 ` Jason Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Glauber Costa @ 2012-02-02 10:39 UTC (permalink / raw)
  To: Jason Wang; +Cc: netdev, davem, linux-kernel, mst

On 02/02/2012 02:07 PM, Jason Wang wrote:
> Commit 4acb4190 tries to fix the using uninitialized value
> introduced by commit 3dc43e3,  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: Jason Wang<jasowang@redhat.com>
Acked-by: Glauber Costa <glommer@parallels.com>

> ---
>   net/ipv4/sysctl_net_ipv4.c |    5 -----
>   net/ipv4/tcp.c             |    4 ++--
>   2 files changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
> index 4cb9cd2..1eb8caa 100644
> --- a/net/ipv4/sysctl_net_ipv4.c
> +++ b/net/ipv4/sysctl_net_ipv4.c
> @@ -815,11 +815,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
>   	net->ipv4.sysctl_rt_cache_rebuild_count = 4;
>
>   	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_ctl_path, table);
Ok, this is indeed a good change, since we avoid initializing it twice.

> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 06373b4..3a7514b 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -3218,7 +3218,6 @@ __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;
> @@ -3287,7 +3286,8 @@ void __init tcp_init(void)
>   	sysctl_max_syn_backlog = max(128, cnt / 256);
>
>   	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);
>   	max_share = min(4UL*1024*1024, limit);

Indeed, this ends up influencing the value of max_share used below to 
initialize the other fields.
I like your change because now the limit variable is being set 
independently between the global (now per-cgroup) and the per-socket 
limits. (it previously was limit = sysctl_tcp_mem[1] << (PAGE_SHIFT-7))

So in the end, I personally think this is even clearer than what we had 
before.

Acked-by: Glauber Costa <glommer@parallels.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits
  2012-02-02 10:07 [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits Jason Wang
  2012-02-02 10:39 ` Glauber Costa
@ 2012-02-02 19:27 ` David Miller
  2012-02-03  3:26 ` Jason Wang
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2012-02-02 19:27 UTC (permalink / raw)
  To: jasowang; +Cc: netdev, linux-kernel, glommer, mst

From: Jason Wang <jasowang@redhat.com>
Date: Thu, 02 Feb 2012 18:07:00 +0800

> Commit 4acb4190 tries to fix the using uninitialized value
> introduced by commit 3dc43e3,  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: Jason Wang <jasowang@redhat.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits
  2012-02-02 10:07 [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits Jason Wang
  2012-02-02 10:39 ` Glauber Costa
  2012-02-02 19:27 ` David Miller
@ 2012-02-03  3:26 ` Jason Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2012-02-03  3:26 UTC (permalink / raw)
  To: Jason Wang; +Cc: netdev, davem, linux-kernel, glommer, mst

On 02/02/2012 06:07 PM, Jason Wang wrote:
> Commit 4acb4190 tries to fix the using uninitialized value
> introduced by commit 3dc43e3,  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: Jason Wang<jasowang@redhat.com>
> ---

Just FYI, this fix the tcp performance regression, I test the virtio-net 
tcp performance:

without this patch:

[root@amd-6168-8-1 net-next]# netperf -H 192.168.100.4 -t TCP_MAERTS
TCP MAERTS TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.100.4 
(192.168.100.4) port 0 AF_INET
Recv   Send    Send
Socket Socket  Message  Elapsed
Size   Size    Size     Time     Throughput
bytes  bytes   bytes    secs.    10^6bits/sec

  87380  16384  16384    10.00    5997.95

with this patch:

[root@amd-6168-8-1 net-next]# netperf -H 192.168.100.4 -t TCP_MAERTS
TCP MAERTS TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.100.4 
(192.168.100.4) port 0 AF_INET
Recv   Send    Send
Socket Socket  Message  Elapsed
Size   Size    Size     Time     Throughput
bytes  bytes   bytes    secs.    10^6bits/sec

  87380  16384  16384    10.00    9670.98

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-03  3:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-02 10:07 [v3.3-rc2+ PATCH] tcp: properly initialize tcp memory limits Jason Wang
2012-02-02 10:39 ` Glauber Costa
2012-02-02 19:27 ` David Miller
2012-02-03  3:26 ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).