From patchwork Wed Oct 30 15:01:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 287261 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 2CF822C03A6 for ; Thu, 31 Oct 2013 02:01:27 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754598Ab3J3PBX (ORCPT ); Wed, 30 Oct 2013 11:01:23 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:60443 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752517Ab3J3PBW (ORCPT ); Wed, 30 Oct 2013 11:01:22 -0400 Received: by mail-pa0-f47.google.com with SMTP id lf10so1051018pab.20 for ; Wed, 30 Oct 2013 08:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:content-transfer-encoding:mime-version; bh=w9PKk/8P1sXik/4AXdIQ2DTFnRQ9DGP9LHMBsOoCT84=; b=g5f6bF4KO/dQMv0BY37G+za+QVtwXvhz4KtaEvgi5QGkoAUyMVa8VZ/yT5fjVbK3fe BktdslmaL1OUwvJHHrwJu/LuMLwM1J4SlL7NVLWhzybW+CcHW1EdY+OPzmfGi9O1Ke1e 7X+UC2v8440O9jYSzkIl46CCNTqUwufUH8VxY/Vi5sG998+IvxRcnQW7Ag3Hq10kTKB0 QbXPbh4COq/ghqu6DKF6L79uqd3Ca3cVceNGQHYTtUG8qe/htA525jXoGrKi6qfuSg33 QDKtfR87FYNyy2bkWvTSVlyXb84Mx41adOuHoEzQldG/JAHjqy4mIReRi+Y+5Ai8CeRD y66Q== X-Received: by 10.68.244.2 with SMTP id xc2mr5716975pbc.58.1383145281471; Wed, 30 Oct 2013 08:01:21 -0700 (PDT) Received: from [172.29.164.64] ([172.29.164.64]) by mx.google.com with ESMTPSA id oj6sm5449628pab.9.2013.10.30.08.01.20 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Wed, 30 Oct 2013 08:01:21 -0700 (PDT) Message-ID: <1383145278.4857.46.camel@edumazet-glaptop.roam.corp.google.com> Subject: [PATCH net-next] net: extend net_device allocation to vmalloc() From: Eric Dumazet To: Joby Poriyath , David Miller Cc: netdev@vger.kernel.org, wei.liu2@citrix.com, ian.campbell@citrix.com, xen-devel@lists.xen.org, andrew.bennieston@citrix.com, david.vrabel@citrix.com, malcolm.crossley@citrix.com Date: Wed, 30 Oct 2013 08:01:18 -0700 In-Reply-To: <1383141242.4857.36.camel@edumazet-glaptop.roam.corp.google.com> References: <20131029152628.GA3065@citrix.com> <1383061430.5464.41.camel@edumazet-glaptop.roam.corp.google.com> <20131029184647.GA3261@citrix.com> <1383089055.4176.1.camel@edumazet-glaptop.roam.corp.google.com> <1383089532.4857.1.camel@edumazet-glaptop.roam.corp.google.com> <20131030103958.GB3261@citrix.com> <1383141242.4857.36.camel@edumazet-glaptop.roam.corp.google.com> X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet Joby Poriyath provided a xen-netback patch to reduce the size of xenvif structure as some netdev allocation could fail under memory pressure/fragmentation. This patch is handling the problem at the core level, allowing any netdev structures to use vmalloc() if kmalloc() failed. As vmalloc() adds overhead on a critical network path, add __GFP_REPEAT to kzalloc() flags to do this fallback only when really needed. Signed-off-by: Eric Dumazet Reported-by: Joby Poriyath --- Documentation/networking/netdevices.txt | 7 ++++--- include/linux/netdevice.h | 1 + net/core/dev.c | 22 +++++++++++++++++----- net/core/net-sysfs.c | 2 +- 4 files changed, 23 insertions(+), 9 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/Documentation/networking/netdevices.txt b/Documentation/networking/netdevices.txt index c7ecc70..df7cd19 100644 --- a/Documentation/networking/netdevices.txt +++ b/Documentation/networking/netdevices.txt @@ -10,9 +10,10 @@ network devices. struct net_device allocation rules ================================== Network device structures need to persist even after module is unloaded and -must be allocated with kmalloc. If device has registered successfully, -it will be freed on last use by free_netdev. This is required to handle the -pathologic case cleanly (example: rmmod mydriver padded; + + if (is_vmalloc_addr(addr)) + vfree(addr); + else + kfree(addr); +} + /** * alloc_netdev_mqs - allocate network device * @sizeof_priv: size of private data to allocate space for @@ -6239,7 +6249,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, /* ensure 32-byte alignment of whole construct */ alloc_size += NETDEV_ALIGN - 1; - p = kzalloc(alloc_size, GFP_KERNEL); + p = kzalloc(alloc_size, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT); + if (!p) + p = vzalloc(alloc_size); if (!p) return NULL; @@ -6248,7 +6260,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, dev->pcpu_refcnt = alloc_percpu(int); if (!dev->pcpu_refcnt) - goto free_p; + goto free_dev; if (dev_addr_init(dev)) goto free_pcpu; @@ -6301,8 +6313,8 @@ free_pcpu: kfree(dev->_rx); #endif -free_p: - kfree(p); +free_dev: + netdev_freemem(dev); return NULL; } EXPORT_SYMBOL(alloc_netdev_mqs); @@ -6339,7 +6351,7 @@ void free_netdev(struct net_device *dev) /* Compatibility with error handling in drivers */ if (dev->reg_state == NETREG_UNINITIALIZED) { - kfree((char *)dev - dev->padded); + netdev_freemem(dev); return; } diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index d954b56..d03f2c9 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1263,7 +1263,7 @@ static void netdev_release(struct device *d) BUG_ON(dev->reg_state != NETREG_RELEASED); kfree(dev->ifalias); - kfree((char *)dev - dev->padded); + netdev_freemem(dev); } static const void *net_namespace(struct device *d)