From patchwork Fri Nov 16 15:31:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 199661 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D6E2B2C0082 for ; Sat, 17 Nov 2012 02:32:13 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752437Ab2KPPb5 (ORCPT ); Fri, 16 Nov 2012 10:31:57 -0500 Received: from mail-ie0-f174.google.com ([209.85.223.174]:50855 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752226Ab2KPPb4 (ORCPT ); Fri, 16 Nov 2012 10:31:56 -0500 Received: by mail-ie0-f174.google.com with SMTP id k13so3742593iea.19 for ; Fri, 16 Nov 2012 07:31:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; bh=O2kxcGBV6SvI0d3wo7mzN/rmpxr9TlWnC0eeNhtE39c=; b=ZWaClteCll9+5gjI6Lv3p/enD1jjLCU2cCFyyY0ppGFsy/raovge8J+8vruiXLiOb0 cLbA8f1maiLlkattWeABzumPSVvLalsJfRwDXCKMESI4zJAHDbl4G6QlAbHhG6K9XaOu GxeYxahbxKFmegpmjeT+jGATRwYlqPTuKCuDfTx/8mKSE7RSrbMoXOqmLA4E6VArOpsO 9egGjB5akMzkk+YICrGHrG2e/eLwFM/9b29tDEYjw/vPPcj02SfTktM7aMRF+oiiIPNm nmIMIJ6Nls7nF6kJzmpdz8o6lukQCyJYCHM9FqcMSIn6yu6h0eYNV2mKE+hYJmGa9822 QDlw== Received: by 10.50.188.199 with SMTP id gc7mr3739140igc.4.1353079915604; Fri, 16 Nov 2012 07:31:55 -0800 (PST) Received: from [172.16.54.60] ([172.16.54.60]) by mx.google.com with ESMTPS id vq4sm496581igb.10.2012.11.16.07.31.54 (version=SSLv3 cipher=OTHER); Fri, 16 Nov 2012 07:31:54 -0800 (PST) Subject: Re: [PATCH] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures From: Eric Dumazet To: David Miller Cc: netdev@vger.kernel.org, jln@google.com In-Reply-To: <20121116.013940.813652515905883288.davem@davemloft.net> References: <1353022864.10798.6.camel@edumazet-glaptop> <20121116.013940.813652515905883288.davem@davemloft.net> Date: Fri, 16 Nov 2012 07:31:53 -0800 Message-ID: <1353079913.10798.31.camel@edumazet-glaptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, 2012-11-16 at 01:39 -0500, David Miller wrote: > From: Eric Dumazet > Date: Thu, 15 Nov 2012 15:41:04 -0800 > > > From: Eric Dumazet > > > > order-5 allocations can fail with current kernels, we should > > try to reduce allocation sizes to allow network namespace > > creation. > > > > Reported-by: Julien Tinnes > > Signed-off-by: Eric Dumazet > > Indeed, this has to be done better. > > But this kind of retry solution results in non-deterministic behavior. > Yes the tcp metrics cache is best effort, but it's size can influence > behavior in a substantial way depending upon the workload. > > I would suggest that we instead use different limits, ones which the > page allocator will satisfy for us always with GFP_KERNEL. > > 1) include linux/mmzone.h > > 2) Make the two limits based upon PAGE_ALLOC_COSTLY_ORDER. > > That is, make the larger table size PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER > and the smaller one PAGE_SIZE << (PAGE_ALLOC_COSTLY_ORDER - 1). Well, we dont really know what the size needs to be, and your proposal reduces the size by a 4 factor, even for the initial namespace. Julien report was about Chrome browser own netns, on a suspend/resume cycle (or something like that) If size can influence behavior, we could try a vmalloc() if kmalloc() fails... Thanks [PATCH v3] tcp: handle tcp_net_metrics_init() order-5 memory allocation failures order-5 allocations can fail with current kernels, we should try vmalloc() as well. Reported-by: Julien Tinnes Signed-off-by: Eric Dumazet --- net/ipv4/tcp_metrics.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 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 diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 53bc584..f696d7c 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -9,6 +8,7 @@ #include #include #include +#include #include #include @@ -1034,7 +1034,10 @@ static int __net_init tcp_net_metrics_init(struct net *net) 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); + net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); + if (!net->ipv4.tcp_metrics_hash) + net->ipv4.tcp_metrics_hash = vzalloc(size); + if (!net->ipv4.tcp_metrics_hash) return -ENOMEM; @@ -1055,7 +1058,10 @@ static void __net_exit tcp_net_metrics_exit(struct net *net) tm = next; } } - kfree(net->ipv4.tcp_metrics_hash); + if (is_vmalloc_addr(net->ipv4.tcp_metrics_hash)) + vfree(net->ipv4.tcp_metrics_hash); + else + kfree(net->ipv4.tcp_metrics_hash); } static __net_initdata struct pernet_operations tcp_net_metrics_ops = {