All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joby Poriyath <joby.poriyath@citrix.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
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>
Subject: Re: [PATCH net-next] xen-netback: allocate xenvif arrays using vzalloc.
Date: Wed, 30 Oct 2013 10:39:59 +0000	[thread overview]
Message-ID: <20131030103958.GB3261@citrix.com> (raw)
In-Reply-To: <1383089532.4857.1.camel@edumazet-glaptop.roam.corp.google.com>

On Tue, Oct 29, 2013 at 04:32:12PM -0700, Eric Dumazet wrote:
> On Tue, 2013-10-29 at 16:24 -0700, Eric Dumazet wrote:
> > On Tue, 2013-10-29 at 18:46 +0000, Joby Poriyath wrote:
> > > On Tue, Oct 29, 2013 at 08:43:50AM -0700, Eric Dumazet wrote:
> > > > On Tue, 2013-10-29 at 15:27 +0000, Joby Poriyath wrote:
> > > > > This will reduce memory pressure when allocating struct xenvif.
> > > > > 
> > > > > The size of xenvif struct has increased from 168 to 36632 bytes (on x86-32).
> > > > > See commit b3f980bd827e6e81a050c518d60ed7811a83061d. This resulted in
> > > > > occasional netdev allocation failure in dom0 with 752MiB RAM, due to
> > > > > fragmented memory.
> > > > 
> > > > This looks overkill. 
> > > > 
> > > > Replacing a single allocation of ~36 KB into 5 vmalloc() looks like you
> > > > did not really tried other things...
> > > > 
> > > > This should be done generically in alloc_netdev_mqs()
> > > 
> > > Sorry Eric, I didn't quite understand how this can be generically done.
> > > 
> > > The netback interfaces are tied to the Xen guests (VMs) and these are created 
> > > when guests are started and deleted when guest are halted.
> > 
> > They are created by alloc_netdev_mqs()
> 
> Something like the following should be fine.
> 
> 
> 

Thanks for the patch.

> diff --git a/net/core/dev.c b/net/core/dev.c
> index 0054c8c..874a57a 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -6239,7 +6239,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;
>  

The net_device allocation rule {linux/Documentation/networking/netdevices.txt} states
that net_device struct must be allocated using kmalloc.

Is this safe to do?

> @@ -6302,7 +6304,10 @@ free_pcpu:
>  #endif
>  
>  free_p:
> -	kfree(p);
> +	if (is_vmalloc_addr(p))
> +		vfree(p);
> +	else
> +		kfree(p);
>  	return NULL;
>  }
>  EXPORT_SYMBOL(alloc_netdev_mqs);
> @@ -6339,7 +6344,12 @@ void free_netdev(struct net_device *dev)
>  
>  	/*  Compatibility with error handling in drivers */
>  	if (dev->reg_state == NETREG_UNINITIALIZED) {
> -		kfree((char *)dev - dev->padded);
> +		char *addr = (char *)dev - dev->padded;
> +
> +		if (is_vmalloc_addr(addr))
> +			vfree(addr);
> +		else
> +			kfree(addr);
>  		return;
>  	}
>  
> diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
> index d954b56..406c54b 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -1259,11 +1259,16 @@ exit:
>  static void netdev_release(struct device *d)
>  {
>  	struct net_device *dev = to_net_dev(d);
> +	char *addr;
>  
>  	BUG_ON(dev->reg_state != NETREG_RELEASED);
>  
>  	kfree(dev->ifalias);
> -	kfree((char *)dev - dev->padded);
> +	addr = (char *)dev - dev->padded;
> +	if (is_vmalloc_addr(addr))
> +		vfree(addr);
> +	else
> +		kfree(addr);
>  }
>  
>  static const void *net_namespace(struct device *d)
> 
> 

Thanks,
Joby

  reply	other threads:[~2013-10-30 10:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-29 15:27 [PATCH net-next] xen-netback: allocate xenvif arrays using vzalloc Joby Poriyath
2013-10-29 15:43 ` Eric Dumazet
2013-10-29 15:43 ` Eric Dumazet
2013-10-29 18:46   ` Joby Poriyath
2013-10-29 18:46   ` Joby Poriyath
2013-10-29 23:24     ` Eric Dumazet
2013-10-29 23:24     ` Eric Dumazet
2013-10-29 23:32       ` Eric Dumazet
2013-10-30 10:39         ` Joby Poriyath [this message]
2013-10-30 13:54           ` Eric Dumazet
2013-10-30 15:01             ` [PATCH net-next] net: extend net_device allocation to vmalloc() Eric Dumazet
2013-10-30 19:16               ` Ben Hutchings
2013-10-30 20:09                 ` Eric Dumazet
2013-10-30 20:09                 ` Eric Dumazet
2013-10-30 19:16               ` Ben Hutchings
2013-10-30 20:10               ` [PATCH v2 " Eric Dumazet
2013-11-04  4:19                 ` David Miller
2013-11-04  4:19                 ` David Miller
2013-10-30 20:10               ` Eric Dumazet
2013-10-30 15:01             ` [PATCH " Eric Dumazet
2013-10-30 10:39         ` [PATCH net-next] xen-netback: allocate xenvif arrays using vzalloc Joby Poriyath
2013-10-29 23:32       ` Eric Dumazet
2013-10-29 15:50 ` Wei Liu
2013-10-29 15:50 ` Wei Liu
  -- strict thread matches above, loose matches on Subject: below --
2013-10-29 15:27 Joby Poriyath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131030103958.GB3261@citrix.com \
    --to=joby.poriyath@citrix.com \
    --cc=andrew.bennieston@citrix.com \
    --cc=david.vrabel@citrix.com \
    --cc=eric.dumazet@gmail.com \
    --cc=ian.campbell@citrix.com \
    --cc=malcolm.crossley@citrix.com \
    --cc=netdev@vger.kernel.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.