Owen
Owen

Reputation: 4173

which kmalloc flag should be used

I've been searching everywhere finding a documentation that explains when to use each flags of kmalloc. I found this reference which fairly explains when to use some of the flags but I can't find the other flags like GFP_HIGHUSER_PAGECACHE, GFP_HIGHUSER_MOVABLE and other flags in gfp.h header file... Can somebody tell me when to use these other flags?

Upvotes: 2

Views: 3042

Answers (1)

Rob
Rob

Reputation: 5286

You want section Get Free Page (GFP) Flags of Understanding the Linux Virtual Memory Manager (pdf). It is for the 2.4 kernel but it should still apply.

original post:

From the 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 */

Also, from kernel archives:

To make code easier to read, a set of three GFP flags are added called GFP_PAGECACHE, GFP_NOFS_PAGECACHE and GFP_HIGHUSER_PAGECACHE.

Looking at the diff source on that page shows the flags you were asking about are a combination of existing flags:

 #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)

Upvotes: 3

Related Questions