[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.00.1009051555560.5003@chino.kir.corp.google.com>
Date: Sun, 5 Sep 2010 16:01:45 -0700 (PDT)
From: David Rientjes <rientjes@...gle.com>
To: Jiri Slaby <jirislaby@...il.com>
cc: Andrew Morton <akpm@...ux-foundation.org>,
Neil Brown <neilb@...e.de>, Alasdair G Kergon <agk@...hat.com>,
Chris Mason <chris.mason@...cle.com>,
Steven Whitehouse <swhiteho@...hat.com>,
Jens Axboe <jaxboe@...ionio.com>, Jan Kara <jack@...e.cz>,
Frederic Weisbecker <fweisbec@...il.com>,
linux-raid@...r.kernel.org, linux-btrfs@...r.kernel.org,
cluster-devel@...hat.com, linux-ext4@...r.kernel.org,
reiserfs-devel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [patch v2 1/5] mm: add nofail variants of kmalloc kcalloc and
kzalloc
On Thu, 2 Sep 2010, Jiri Slaby wrote:
> > @@ -334,6 +334,57 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
> > return kmalloc_node(size, flags | __GFP_ZERO, node);
> > }
> >
> > +/**
> > + * kmalloc_nofail - infinitely loop until kmalloc() succeeds.
> > + * @size: how many bytes of memory are required.
> > + * @flags: the type of memory to allocate (see kmalloc).
> > + *
> > + * NOTE: no new callers of this function should be implemented!
> > + * All memory allocations should be failable whenever possible.
> > + */
> > +static inline void *kmalloc_nofail(size_t size, gfp_t flags)
> > +{
> > + void *ret;
> > +
> > + for (;;) {
> > + ret = kmalloc(size, flags);
> > + if (ret)
> > + return ret;
> > + WARN_ON_ONCE(get_order(size) > PAGE_ALLOC_COSTLY_ORDER);
>
> This doesn't work as you expect. kmalloc will warn every time it fails.
It actually does work as I expect since the WARN_ON_ONCE() never even gets
triggered here for any of kmalloc_nofail()'s callers since they all have
sizes small enough that the conditional is never true. The page allocator
implicitly loops forever if the order <= PAGE_ALLOC_COSTLY_ORDER, so this
warning is only emitted if the #define implementation of the page
allocator only changes. That's intended, we want to know the consequences
of our change.
> __GFP_NOFAIL used to disable the warning.
No, it didn't, it was unnecessary for all of the kmalloc_nofail() callers
since they already implicitly loop. No warning is emitted (these are all
GFP_NOFS or GFP_NOIO users, there are no order-4 or larger GFP_ATOMIC
allocators using this interface).
> Actually what's wrong with
> __GFP_NOFAIL? I cannot find a reason in the changelogs why the patches
> are needed.
>
Couple reasons:
- it's unnecessary in the page allocator, it can be implemented at a
higher level, which allows us to remove these branches from the
slowpath,
- it's mostly unnecessary since all users have orders that will
implicitly loop forever anyway (although __GFP_NOFAIL does guarantee
that it won't fail even if we change the looping behavior internally,
these warnings help to isolate cases where it's needed), and
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists