我一直到处寻找文档,该文档解释何时使用kmalloc的每个标志。我发现this reference可以合理解释何时使用某些标志,但是我在GFP_HIGHUSER_PAGECACHE头文件中找不到其他标志,例如GFP_HIGHUSER_MOVABLEgfp.h和其他标志...有人可以告诉我何时使用这些其他标志吗?

最佳答案

您要获取Understanding the Linux Virtual Memory Manager (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 */

另外,从kernel archives:



查看该页面上的diff源,可以看到您询问的标志是现有标志的组合:
 #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)

10-04 12:26
查看更多