GFP在kmalloc标志中的含义是什么?

时间:2012-06-27 09:51:41

标签: linux-kernel kmalloc

GFPkmalloc个标记的含义是什么?例如GFP_KERNELGFP_ATOMIC

2 个答案:

答案 0 :(得分:18)

GFP =获取免费页数= __get_free_pages

这些标志是传递给分配内存的函数的标志,例如__get_free_pageskmalloc,告诉他们在分配时可以做什么和不可以做什么。

例如,GFP_ATOMIC表示分配时不会发生上下文切换(这意味着无法进行分页)。

答案 1 :(得分:2)

查看include/linux/gfp.h文件了解详情。

 100 /* This equals 0, but use constants in case they ever change */
 101 #define GFP_NOWAIT      (GFP_ATOMIC & ~__GFP_HIGH)
 102 /* GFP_ATOMIC means both !wait (__GFP_WAIT not set) and use emergency pool */
 103 #define GFP_ATOMIC      (__GFP_HIGH)
 104 #define GFP_NOIO        (__GFP_WAIT)
 105 #define GFP_NOFS        (__GFP_WAIT | __GFP_IO)
 106 #define GFP_KERNEL      (__GFP_WAIT | __GFP_IO | __GFP_FS)
 107 #define GFP_TEMPORARY   (__GFP_WAIT | __GFP_IO | __GFP_FS | \
 108                         __GFP_RECLAIMABLE)
 109 #define GFP_USER        (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
 110 #define GFP_HIGHUSER    (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL | \
 111                         __GFP_HIGHMEM)
 112 #define GFP_HIGHUSER_MOVABLE    (__GFP_WAIT | __GFP_IO | __GFP_FS | \
 113                                 __GFP_HARDWALL | __GFP_HIGHMEM | \
 114                                 __GFP_MOVABLE)
 115 #define GFP_IOFS        (__GFP_IO | __GFP_FS)
 116 #define GFP_TRANSHUGE   (GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
 117                         __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \
 118                         __GFP_NO_KSWAPD)