Re: kmalloc in the schedule function

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

 



On 3/9/06, Mauricio Lin <mauriciolin2000@xxxxxxxxxxxx> 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/



[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