Re: kmalloc in the schedule function

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

 



Hi
on 2.4.21-32(redhat enterprise update 5) when i call kmalloc  with GFP_KERNEL 
my system get hangs it hangs.. Anyone can suggest what should i do ..
 
-- Anil
 


Hareesh Nagarajan <hnagar2@xxxxxxxxx> wrote:
On 3/9/06, Mauricio Lin wrote:
> Hi all,
>
> Is it possible to use kmalloc() in schedule() function?
>
> I have used kmalloc to allocate memory in schedule() but it does not work
> since during the boot the kernel gets frozen.

kmalloc with the flag GFP_KERNEL can potentially sleep. Which means,
the resource, which in this case is memory, cannot be allocated in an
atomic manner, so the kernel can put the requester in a wait queue,
call schedule(). (and of course when the resource is available, the
requester is woken up.)

So now inside schedule() you have a call that can sleep, or in other
words, you have a call that can schedule(). So you see:

schedule()
kmalloc(...)
schedule()
kmalloc(...)
...

This is far from ideal. You will run out of stack, which inside the
kernel is only 4K. Stay away from kmalloc-ing inside schedule, or if
you really need to use kmalloc, use it with the flag GFP_ATOMIC.

--
c u
./hareesh

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



Yahoo! Mail
Use Photomail to share photos without annoying attachments.

[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