lkml.org 
[lkml]   [2009]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: GFP_NOWAIT and GFP_NOMEMALLOC
From
On Tue, Sep 29, 2009 at 5:29 PM, Arjan van de Ven <arjan@infradead.org> wrote:
> On Tue, 29 Sep 2009 16:55:24 +0530
> "Leonidas ." <leonidas137@gmail.com> 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.
>
> GFP_NOWAIT is what you want.
>
> can you give us a pointer to what your module is about? Maybe there's
> better solutions...
>
>
> --
> Arjan van de Ven        Intel Open Source Technology Centre
> For development, discussion and tips for power savings,
> visit http://www.lesswatts.org
>


The module is going to be a profiling module and the user module which
is under profiling
will call the apis which I am exporting. My apis will collect certain
data from point
it is called and populate internal data strcuctures. My apis can be
called from process
context as well as interrupt context hence I am using spinlocks as
locking mechanism.
The amount of memory I am allocating each time my api is called around
100 bytes,
and in worst case I might end up allocating tens of thousands of
objects of almost same
size. I am aware that in such a scenario I should be using some kind
of memory pool
mechanism and preallocate my buffers to avoid frequent
allocations/deallocations.

But frankly, I am not very familiar with Linux kernel apis yet hence
have resorted to
using a tree data structure for the first cut where I allocate memory as needed
depending on the context I am executing in. To optimize a bit, I do
not free my memory
till some threshold is reached.

Some questions here:

1. GFP_NOWAIT as in kmalloc(size, GFP_KERNEL | GFPNOWAIT)?

or

kmalloc(size, GFP_NOWAIT), I know this one is a dumb one.

2. Any reference for the mempool kind of implementation mentioned above?

3. Any other pointers about design, references etc would be helpful.

-Leo.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-09-29 14:19    [W:0.336 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site