Patchwork tcp: handle tcp_net_metrics_init() order-5 memory allocation failures

login
register
mail settings
Submitter Eric Dumazet
Date Nov. 15, 2012, 11:41 p.m.
Message ID <1353022864.10798.6.camel@edumazet-glaptop>
Download mbox | patch
Permalink /patch/199457/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Eric Dumazet - Nov. 15, 2012, 11:41 p.m.
From: Eric Dumazet <edumazet@google.com>

order-5 allocations can fail with current kernels, we should
try to reduce allocation sizes to allow network namespace
creation.

Reported-by: Julien Tinnes <jln@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp_metrics.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches - Nov. 15, 2012, 11:55 p.m.
On Thu, 2012-11-15 at 15:41 -0800, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> order-5 allocations can fail with current kernels, we should
> try to reduce allocation sizes to allow network namespace
> creation.
> 
> Reported-by: Julien Tinnes <jln@google.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  net/ipv4/tcp_metrics.c |   13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
> index 53bc584..15e93c4 100644
> --- a/net/ipv4/tcp_metrics.c
> +++ b/net/ipv4/tcp_metrics.c
> @@ -1030,14 +1030,17 @@ static int __net_init tcp_net_metrics_init(struct net *net)
>  		else
>  			slots = 8 * 1024;
>  	}
> -
> +retry:
>  	net->ipv4.tcp_metrics_hash_log = order_base_2(slots);
>  	size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log;
>  
> -	net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL);
> -	if (!net->ipv4.tcp_metrics_hash)
> -		return -ENOMEM;
> -
> +	net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
> +	if (!net->ipv4.tcp_metrics_hash) {
> +		if (slots <= 16)
> +			return -ENOMEM;

maybe readd the warning for OOM reporting here?

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric Dumazet - Nov. 16, 2012, 12:47 a.m.
On Thu, 2012-11-15 at 15:55 -0800, Joe Perches wrote:

> maybe readd the warning for OOM reporting here?
> 


Storing tcp metrics is a best effort, this can be silently ignored.

And order-0 are going to work, unless machine is in critical state,
that gives enough room.




--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index 53bc584..15e93c4 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -1030,14 +1030,17 @@  static int __net_init tcp_net_metrics_init(struct net *net)
 		else
 			slots = 8 * 1024;
 	}
-
+retry:
 	net->ipv4.tcp_metrics_hash_log = order_base_2(slots);
 	size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log;
 
-	net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL);
-	if (!net->ipv4.tcp_metrics_hash)
-		return -ENOMEM;
-
+	net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
+	if (!net->ipv4.tcp_metrics_hash) {
+		if (slots <= 16)
+			return -ENOMEM;
+		slots >>= 1;
+		goto retry;
+	}
 	return 0;
 }