What is the meaning of GFP
flags in kmalloc
? For instance GFP_KERNEL
, GFP_ATOMIC
?
Asked
Active
Viewed 1.4k times
18

Guy Avraham
- 3,482
- 3
- 38
- 50

user1485214
- 181
- 1
- 1
- 3
2 Answers
27
GFP = Get Free Pages = __get_free_pages
.
These flags are flags passed to functions that allocate memory, such as __get_free_pages
and kmalloc
, telling them what can and can't be done while allocating.
For example, GFP_ATOMIC
means no context-switch must happen while allocating (which means paging isn't possible).

ugoren
- 16,023
- 3
- 35
- 65
3
Look at the include/linux/gfp.h file for details.
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)

Ilya Matveychikov
- 3,936
- 2
- 27
- 42