GFP_ATOMIC or GFP_KERNEL?

来源:互联网 发布:python xml解析 编辑:程序博客网 时间:2024/05/20 00:13

本文转载至:http://lists.metaprl.org/pipermail/cs134-labs/2002-October/000025.html

The short (or kinda long) answer is this:GFP_ATOMIC means roughly "make the allocation operation atomic".  Thismeans that the kernel will try to find the memory using a pile of freememory set aside for urgent allocation.  If that pile doesn't haveenough free pages, the operation will fail.  This flag is useful forallocation within interrupt handlers.GFP_KERNEL will try a little harder to find memory.  There's apossibility that the call to kmalloc() will sleep while the kernel istrying to find memory (thus making it unsuitable for interrupthandlers).  It's much more rare for an allocation with GFP_KERNEL tofail than with GFP_ATOMIC.In all cases, kmalloc() should only be used allocating small amounts ofmemory (a few kb).  vmalloc() is better for larger amounts.Also note that in lab 1 and lab 2, it would have been arguably better touse GFP_KERNEL instead of GFP_ATOMIC.  GFP_ATOMIC should be saved forthose instances in which a sleep would be totally unacceptable.This is a fuzzy issue though...there's no absolute right or wronganswer.
原创粉丝点击