From patchwork Wed Oct 30 20:10:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 287335 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 C8C1C2C03AF for ; Thu, 31 Oct 2013 07:10:54 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754733Ab3J3UKt (ORCPT ); Wed, 30 Oct 2013 16:10:49 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:42501 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752966Ab3J3UKr (ORCPT ); Wed, 30 Oct 2013 16:10:47 -0400 Received: by mail-pa0-f53.google.com with SMTP id kx10so1454491pab.40 for ; Wed, 30 Oct 2013 13:10:47 -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=aBuaurRkanEBdbH/LDq+o+IeU9dJjIheUi5fUAuxTg8=; b=Sau2fkYC7G391nJrerU+uQ8U+IR2/S9t//TA9V5a7TEytZb5XT2ISpzBNLk0HaRxdE PKI0UzKv905Qi/cFX0b8xSyw/lv+1CminlGgHjKXVzD3xvtLHFEa78pTVOWHtBrOWfU0 bGSBUqVNuuq3RHq0gU01L8aBbb7Cvy2g5KEIuuKrlGgFQTiO9LUaSg0BriXRu+AmbiTY 8lWEw7ueYa6Qaah3s5f0RPMxRXpNvUClWVxm3ffjMQTIN0QKSGKC69ue4+sXlAobqovP hRiOfhg546UsbdNqMl9YQa5Oz2kH63GlSn00gpOly59gdiSWoiZF5eX4+pzGe1TL0bxP ymUQ== X-Received: by 10.66.159.234 with SMTP id xf10mr121962pab.139.1383163846998; Wed, 30 Oct 2013 13:10:46 -0700 (PDT) Received: from [172.29.164.64] ([172.29.164.64]) by mx.google.com with ESMTPSA id wp8sm43191571pbc.26.2013.10.30.13.10.44 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Wed, 30 Oct 2013 13:10:45 -0700 (PDT) Message-ID: <1383163844.4857.59.camel@edumazet-glaptop.roam.corp.google.com> Subject: [PATCH v2 net-next] net: extend net_device allocation to vmalloc() From: Eric Dumazet To: Joby Poriyath , Ben Hutchings Cc: David Miller , 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 13:10:44 -0700 In-Reply-To: <1383145278.4857.46.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> <1383145278.4857.46.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 Cc: Ben Hutchings --- v2: change the Documentation to point to alloc_netdev_mqs() instead of kmalloc()/vzalloc(), from Ben Documentation/networking/netdevices.txt | 10 +++++----- include/linux/netdevice.h | 1 + net/core/dev.c | 22 +++++++++++++++++----- net/core/net-sysfs.c | 2 +- 4 files changed, 24 insertions(+), 11 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..7d8d79f 100644 --- a/Documentation/networking/netdevices.txt +++ b/Documentation/networking/netdevices.txt @@ -10,12 +10,12 @@ 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)