public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: "Leonidas ." <leonidas137@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: GFP_NOWAIT and GFP_NOMEMALLOC
Date: Sun, 4 Oct 2009 20:56:27 +0200	[thread overview]
Message-ID: <20091004185627.GA1378@ucw.cz> (raw)
In-Reply-To: <f22d86810909290425s46406fe5ib00bcfc9673f70df@mail.gmail.com>

On Tue 2009-09-29 16:55:24, Leonidas . wrote:
> Hi list,
> 
> I am new here, I have googled/binged enough before posting this message,
> in case of redundancy please point me to appropriate links/resources etc.
> 
> I want to kmalloc memory while holding spinlocks in process context, here I
> can't use GFP_KERNEL flag since it can sleep. Using GFP_ATOMIC guarantees
> that allocation will succeed by allocating from emergency pools if needed.
> But I dont think, I need to use emergency pool and I want to limit my memory
> consumption to ZONE_NORMAL without sleeping, my module is ready to handle
> the allocation failure if any.

Umm. Either preallocate, or use gfp_atomic. It should be ok.

> Something like,
> 
> ptr =  kmalloc(..., GFP_KERNEL | GFP_DONT_SLEEP );
> 
> if( !ptr ) {
> 
>  /*GFP_KERNEL failed, Use GFP_ATOMIC pool*/
>  ptr =  kmalloc(..., GFP_ATOMIC );
> 
> }
> /*Go ahead and do stuff*/

That's pretty stupid, no? Just alloc GFP_ATOMIC directly... oh and
check return values...
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

      parent reply	other threads:[~2009-10-04 18:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29 11:25 GFP_NOWAIT and GFP_NOMEMALLOC Leonidas .
2009-09-29 11:59 ` Arjan van de Ven
2009-09-29 12:16   ` Leonidas .
2009-09-29 12:37     ` Arjan van de Ven
2009-09-29 12:43       ` Leonidas .
2009-10-04 18:56 ` Pavel Machek [this message]

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=20091004185627.GA1378@ucw.cz \
    --to=pavel@ucw.cz \
    --cc=leonidas137@gmail.com \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox