Re: how to use errno in kernel loadable modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Fri, 30 Dec 2005 15:39:21 +0530
Parag N(पराग़) <panemade@xxxxxxxxx> wrote:

>      I think you have to use kmalloc(64,GFP_ATOMIC) then u will not
> get any memory allocation error.

Okay, let's make a longer explanation. The code that actually does this
is __alloc_pages, at http://lxr.linux.no/source/mm/page_alloc.c#L695.

As you can see in http://lxr.linux.no/source/include/linux/gfp.h#L50,
GFP_ATOMIC doesn't have the __GFP_WAIT flag. This means that an atomic
allocations cannot sleep.

In __alloc_pages(), in we reach
http://lxr.linux.no/source/mm/page_alloc.c#L770 for an atomic
allocation, we fail and return NULL. Otherwise, if it's not an atomic
allocation (__GFP_WAIT is set), then we can try harder to free memory,
which will possibly require to sleep.

However, the thing is even more complicated because GFP_ATOMIC is
__GFP_HIGH, which autorizes __alloc_pages() to allocate memory from
an emergency pool (see http://lxr.linux.no/source/mm/page_alloc.c#L664
with gfp_high = TRUE). On the opposite, GFP_KERNEL doesn't have
__GFP_HIGH (but has __GFP_WAIT), so such allocations can sleep, but
won't go allocate inside the emergency pool.

See http://lxr.linux.no/source/include/linux/gfp.h#L29 for an
explanation of each __GFP_* flag.

For more information, read http://lwn.net/images/pdf/LDD3/ch08.pdf,
which is the 8th chapter of Linux Device Drivers. It explains all that
stuff very well.

Sincerly,

Thomas
-- 
PETAZZONI Thomas - thomas.petazzoni@xxxxxxxx 
http://{thomas,sos,kos}.enix.org - Jabber: thomas.petazzoni@xxxxxxxxx
http://{agenda,livret}dulibre.org - http://www.toulibre.org
Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E  1624 F653 CB30 98D3 F7A7

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux