From: "Michael S. Tsirkin" <mst@redhat.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: Romain Francoise <romain@orebokech.com>,
kvm@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vhost-net: fall back to vmalloc if high-order allocation fails
Date: Thu, 24 Jan 2013 12:06:00 +0200 [thread overview]
Message-ID: <20130124100600.GB8710@redhat.com> (raw)
In-Reply-To: <AE90C24D6B3A694183C094C60CF0A2F6026B711E@saturn3.aculab.com>
On Thu, Jan 24, 2013 at 09:45:50AM -0000, David Laight wrote:
> > + n = kmalloc(sizeof *n, GFP_KERNEL | __GFP_NOWARN);
> > + if (!n)
> > + n = vmalloc(sizeof *n);
>
> I'm slightly confused by this construct.
> I thought kmalloc(... GFP_KERNEL) would sleep waiting for
> memory (rather than return NULL).
>
> I realise that (for multi-page sizes) that kmalloc() and
> vmalloc() both need to find a contiguous block of kernel
> virtual addresses - in different address ranges, and
> that vmalloc() then has to find physical memory pages
> (which will not be contiguous).
>
> I think this means that kmalloc() is likely to be faster
> (if it doesn't have to sleep), but that vmalloc() is
> allocating from a much larger resource.
>
> This make me that that large allocations that are not
> temporary should probably be allocated with vmalloc().
vmalloc has some issues for example afaik it's not backed by
a huge page so I think its use puts more stress on the TLB cache.
> Is there a 'NO_SLEEP' flag to kmalloc()? is that all
> GFP_ATOMIC requests? If so you might try a non-sleeping
> kmalloc() with a vmalloc() if it fails.
>
> This all looks as though there should be a GFP_NONCONTIG
> flag (or similar) so that kmalloc() can make a decision itself.
>
> Of at least a wrapper - like the one for free().
>
> David
>
>
next prev parent reply other threads:[~2013-01-24 10:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-23 20:46 [PATCH] vhost-net: fall back to vmalloc if high-order allocation fails Romain Francoise
2013-01-23 21:04 ` Michael S. Tsirkin
2013-01-28 3:11 ` David Miller
2013-01-28 9:23 ` Romain Francoise
2013-06-28 7:16 ` Romain Francoise
2013-01-24 9:45 ` David Laight
2013-01-24 10:06 ` Michael S. Tsirkin [this message]
2013-01-24 10:37 ` David Laight
2013-01-25 3:03 ` Cong Wang
2013-01-25 5:15 ` Jason Wang
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=20130124100600.GB8710@redhat.com \
--to=mst@redhat.com \
--cc=David.Laight@ACULAB.COM \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=romain@orebokech.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).