2

我一直在到处寻找解释何时使用kmalloc. 我找到了这个参考,它公平地解释了何时使用某些标志,但我在头文件中找不到其他标志,如GFP_HIGHUSER_PAGECACHE,GFP_HIGHUSER_MOVABLE和其他标志gfp.h......有人可以告诉我何时使用这些其他标志吗?

4

1 回答 1

3

您想要了解 Linux 虚拟内存管理器 (pdf) 的获取免费页面 (GFP) 标志部分。它适用于 2.4 内核,但仍应适用。

原帖:

2.6.32 gfp.h 开始

   /*
    * Action modifiers - doesn't change the zoning
    *
    * __GFP_REPEAT: Try hard to allocate the memory, but the allocation attempt
    * _might_ fail.  This depends upon the particular VM implementation.
    *
    * __GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
    * cannot handle allocation failures.
    *
    * __GFP_NORETRY: The VM implementation must not retry indefinitely.
    *
    * __GFP_MOVABLE: Flag that this page will be movable by the page migration
    * mechanism or reclaimed
    */    
    #define __GFP_WAIT      ((__force gfp_t)0x10u)  /* Can wait and reschedule? */
    #define __GFP_          ((__force gfp_t)0x20u)  /* Should access emergency pools? */
    #define __GFP_IO        ((__force gfp_t)0x40u)  /* Can start physical IO? */
    #define __GFP_FS        ((__force gfp_t)0x80u)  /* Can call down to low-level FS? */
    #define __GFP_COLD      ((__force gfp_t)0x100u) /* Cache-cold page required */
    #define __GFP_NOWARN    ((__force gfp_t)0x200u) /* Suppress page allocation failure warning */
    #define __GFP_REPEAT    ((__force gfp_t)0x400u) /* See above */
    #define __GFP_NOFAIL    ((__force gfp_t)0x800u) /* See above */
    #define __GFP_NORETRY   ((__force gfp_t)0x1000u)/* See above */
    #define __GFP_COMP      ((__force gfp_t)0x4000u)/* Add compound page metadata */
    #define __GFP_ZERO      ((__force gfp_t)0x8000u)/* Return zeroed page on success */
    #define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u) /* Don't use emergency reserves */
    #define __GFP_HARDWALL   ((__force gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */
    #define __GFP_THISNODE  ((__force gfp_t)0x40000u)/* No fallback, no policies */
    #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u) /* Page is reclaimable */

此外,来自内核档案

为了使代码更易于阅读,添加了一组三个 GFP 标志,称为 GFP_PAGECACHE、GFP_NOFS_PAGECACHE 和 GFP_HIGHUSER_PAGECACHE。

查看该页面上的差异源会显示您询问的标志是现有标志的组合:

 #define GFP_HIGHUSER_MOVABLE   (__GFP_WAIT | __GFP_IO | __GFP_FS | \
                 __GFP_HARDWALL | __GFP_HIGHMEM | \
                 __GFP_MOVABLE)
+#define GFP_NOFS_PAGECACHE (__GFP_WAIT | __GFP_IO | __GFP_MOVABLE)
+#define GFP_USER_PAGECACHE (__GFP_WAIT | __GFP_IO | __GFP_FS | \
+                __GFP_HARDWALL | __GFP_MOVABLE)
+#define GFP_HIGHUSER_PAGECACHE (__GFP_WAIT | __GFP_IO | __GFP_FS | \
+                __GFP_HARDWALL | __GFP_HIGHMEM | \
+                __GFP_MOVABLE)

 #ifdef CONFIG_NUMA
 #define GFP_THISNODE   (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY)
于 2011-03-07T05:52:15.093 回答