Re: how to use errno in kernel loadable modules

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

 



On Fri, 2005-12-30 at 16:27 +0530, Parag N(पराग़) wrote:
> Hi,
> On 12/30/05, Arjan van de Ven <arjan@xxxxxxxxxxxxx> wrote:
> > On Fri, 2005-12-30 at 15:39 +0530, Parag N(पराग़) wrote:
> > > Hi,
> > >
> > > On 12/30/05, Tetsuo Handa <from-kernelnewbies@xxxxxxxxxxxxxxxxxxx> wrote:
> > > > Hi,
> > > >
> > > > kishore wrote:
> > > > >     I am using kmalloc in my module. It returned NULL; by that i understood
> > > > > there may be some scarcity in allocating the requested amount of memory ( i
> > > > > requested for 64 bytes). I returned -ENOMEM, but i thought there may be some
> > > > > way to return error number rather than what am using.
> > > > The kmalloc() can allocate up to 128 Kilo Bytes.
> > > > Allocation for only 64 Bytes SHOULD NOT FAIL!
> > > > I doubt you passed wrong parameters to kmalloc().
> > > >
> > >      I think you have to use kmalloc(64,GFP_ATOMIC) then u will not
> > > get any memory allocation error.
> >
> > GFP_ATOMIC allocations are MORE likely to fail actually!
> > (and are also more likely to bring the VM into big trouble so should be
> > avoided if at all possible)
> >
> >
>    What leads me to think to use GFP_ATOMIC is following explanation for flags
> GFP_ATOMIC 	The allocation is high-priority and does not sleep. This
> is the flag to use in interrupt handlers, bottom halves and other
> situations where you cannot sleep.
> GFP_KERNEL 	This is a normal allocation and might block. This is the
> flag to use in process context code when it is safe to sleep.
>         If kmalloc fails for allocating memory thru' GFP_KERNEL which
> might be case of blocking request of kmalloc then i thought to use
> high priority allocation flag.
> If i am wrong correct me.

the thing is.. with GFP_KERNEL the kernel is allowed to do IO (eg swap
or write back dirty pagecache) so it can actually free memory a lot
better to give you some, than with GFP_ATOMIC. Eg with GFP_ATOMIC you
tie the hands of the VM, so it can do less work to make the allocation
succeed. 



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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