aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/gfp.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/gfp.h')
-rw-r--r--include/linux/gfp.h142
1 files changed, 86 insertions, 56 deletions
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 975609cb8548..cb4089254f01 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -9,6 +9,34 @@
9 9
10struct vm_area_struct; 10struct vm_area_struct;
11 11
12/* Plain integer GFP bitmasks. Do not use this directly. */
13#define ___GFP_DMA 0x01u
14#define ___GFP_HIGHMEM 0x02u
15#define ___GFP_DMA32 0x04u
16#define ___GFP_MOVABLE 0x08u
17#define ___GFP_WAIT 0x10u
18#define ___GFP_HIGH 0x20u
19#define ___GFP_IO 0x40u
20#define ___GFP_FS 0x80u
21#define ___GFP_COLD 0x100u
22#define ___GFP_NOWARN 0x200u
23#define ___GFP_REPEAT 0x400u
24#define ___GFP_NOFAIL 0x800u
25#define ___GFP_NORETRY 0x1000u
26#define ___GFP_COMP 0x4000u
27#define ___GFP_ZERO 0x8000u
28#define ___GFP_NOMEMALLOC 0x10000u
29#define ___GFP_HARDWALL 0x20000u
30#define ___GFP_THISNODE 0x40000u
31#define ___GFP_RECLAIMABLE 0x80000u
32#ifdef CONFIG_KMEMCHECK
33#define ___GFP_NOTRACK 0x200000u
34#else
35#define ___GFP_NOTRACK 0
36#endif
37#define ___GFP_NO_KSWAPD 0x400000u
38#define ___GFP_OTHER_NODE 0x800000u
39
12/* 40/*
13 * GFP bitmasks.. 41 * GFP bitmasks..
14 * 42 *
@@ -18,10 +46,10 @@ struct vm_area_struct;
18 * without the underscores and use them consistently. The definitions here may 46 * without the underscores and use them consistently. The definitions here may
19 * be used in bit comparisons. 47 * be used in bit comparisons.
20 */ 48 */
21#define __GFP_DMA ((__force gfp_t)0x01u) 49#define __GFP_DMA ((__force gfp_t)___GFP_DMA)
22#define __GFP_HIGHMEM ((__force gfp_t)0x02u) 50#define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM)
23#define __GFP_DMA32 ((__force gfp_t)0x04u) 51#define __GFP_DMA32 ((__force gfp_t)___GFP_DMA32)
24#define __GFP_MOVABLE ((__force gfp_t)0x08u) /* Page is movable */ 52#define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE) /* Page is movable */
25#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) 53#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE)
26/* 54/*
27 * Action modifiers - doesn't change the zoning 55 * Action modifiers - doesn't change the zoning
@@ -38,27 +66,25 @@ struct vm_area_struct;
38 * __GFP_MOVABLE: Flag that this page will be movable by the page migration 66 * __GFP_MOVABLE: Flag that this page will be movable by the page migration
39 * mechanism or reclaimed 67 * mechanism or reclaimed
40 */ 68 */
41#define __GFP_WAIT ((__force gfp_t)0x10u) /* Can wait and reschedule? */ 69#define __GFP_WAIT ((__force gfp_t)___GFP_WAIT) /* Can wait and reschedule? */
42#define __GFP_HIGH ((__force gfp_t)0x20u) /* Should access emergency pools? */ 70#define __GFP_HIGH ((__force gfp_t)___GFP_HIGH) /* Should access emergency pools? */
43#define __GFP_IO ((__force gfp_t)0x40u) /* Can start physical IO? */ 71#define __GFP_IO ((__force gfp_t)___GFP_IO) /* Can start physical IO? */
44#define __GFP_FS ((__force gfp_t)0x80u) /* Can call down to low-level FS? */ 72#define __GFP_FS ((__force gfp_t)___GFP_FS) /* Can call down to low-level FS? */
45#define __GFP_COLD ((__force gfp_t)0x100u) /* Cache-cold page required */ 73#define __GFP_COLD ((__force gfp_t)___GFP_COLD) /* Cache-cold page required */
46#define __GFP_NOWARN ((__force gfp_t)0x200u) /* Suppress page allocation failure warning */ 74#define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) /* Suppress page allocation failure warning */
47#define __GFP_REPEAT ((__force gfp_t)0x400u) /* See above */ 75#define __GFP_REPEAT ((__force gfp_t)___GFP_REPEAT) /* See above */
48#define __GFP_NOFAIL ((__force gfp_t)0x800u) /* See above */ 76#define __GFP_NOFAIL ((__force gfp_t)___GFP_NOFAIL) /* See above */
49#define __GFP_NORETRY ((__force gfp_t)0x1000u)/* See above */ 77#define __GFP_NORETRY ((__force gfp_t)___GFP_NORETRY) /* See above */
50#define __GFP_COMP ((__force gfp_t)0x4000u)/* Add compound page metadata */ 78#define __GFP_COMP ((__force gfp_t)___GFP_COMP) /* Add compound page metadata */
51#define __GFP_ZERO ((__force gfp_t)0x8000u)/* Return zeroed page on success */ 79#define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) /* Return zeroed page on success */
52#define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u) /* Don't use emergency reserves */ 80#define __GFP_NOMEMALLOC ((__force gfp_t)___GFP_NOMEMALLOC) /* Don't use emergency reserves */
53#define __GFP_HARDWALL ((__force gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */ 81#define __GFP_HARDWALL ((__force gfp_t)___GFP_HARDWALL) /* Enforce hardwall cpuset memory allocs */
54#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ 82#define __GFP_THISNODE ((__force gfp_t)___GFP_THISNODE)/* No fallback, no policies */
55#define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u) /* Page is reclaimable */ 83#define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) /* Page is reclaimable */
56 84#define __GFP_NOTRACK ((__force gfp_t)___GFP_NOTRACK) /* Don't track with kmemcheck */
57#ifdef CONFIG_KMEMCHECK 85
58#define __GFP_NOTRACK ((__force gfp_t)0x200000u) /* Don't track with kmemcheck */ 86#define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
59#else 87#define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
60#define __GFP_NOTRACK ((__force gfp_t)0)
61#endif
62 88
63/* 89/*
64 * This may seem redundant, but it's a way of annotating false positives vs. 90 * This may seem redundant, but it's a way of annotating false positives vs.
@@ -66,7 +92,7 @@ struct vm_area_struct;
66 */ 92 */
67#define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK) 93#define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68 94
69#define __GFP_BITS_SHIFT 22 /* Room for 22 __GFP_FOO bits */ 95#define __GFP_BITS_SHIFT 23 /* Room for 23 __GFP_FOO bits */
70#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) 96#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
71 97
72/* This equals 0, but use constants in case they ever change */ 98/* This equals 0, but use constants in case they ever change */
@@ -85,6 +111,9 @@ struct vm_area_struct;
85 __GFP_HARDWALL | __GFP_HIGHMEM | \ 111 __GFP_HARDWALL | __GFP_HIGHMEM | \
86 __GFP_MOVABLE) 112 __GFP_MOVABLE)
87#define GFP_IOFS (__GFP_IO | __GFP_FS) 113#define GFP_IOFS (__GFP_IO | __GFP_FS)
114#define GFP_TRANSHUGE (GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
115 __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \
116 __GFP_NO_KSWAPD)
88 117
89#ifdef CONFIG_NUMA 118#ifdef CONFIG_NUMA
90#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY) 119#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY)
@@ -186,14 +215,14 @@ static inline int allocflags_to_migratetype(gfp_t gfp_flags)
186#endif 215#endif
187 216
188#define GFP_ZONE_TABLE ( \ 217#define GFP_ZONE_TABLE ( \
189 (ZONE_NORMAL << 0 * ZONES_SHIFT) \ 218 (ZONE_NORMAL << 0 * ZONES_SHIFT) \
190 | (OPT_ZONE_DMA << __GFP_DMA * ZONES_SHIFT) \ 219 | (OPT_ZONE_DMA << ___GFP_DMA * ZONES_SHIFT) \
191 | (OPT_ZONE_HIGHMEM << __GFP_HIGHMEM * ZONES_SHIFT) \ 220 | (OPT_ZONE_HIGHMEM << ___GFP_HIGHMEM * ZONES_SHIFT) \
192 | (OPT_ZONE_DMA32 << __GFP_DMA32 * ZONES_SHIFT) \ 221 | (OPT_ZONE_DMA32 << ___GFP_DMA32 * ZONES_SHIFT) \
193 | (ZONE_NORMAL << __GFP_MOVABLE * ZONES_SHIFT) \ 222 | (ZONE_NORMAL << ___GFP_MOVABLE * ZONES_SHIFT) \
194 | (OPT_ZONE_DMA << (__GFP_MOVABLE | __GFP_DMA) * ZONES_SHIFT) \ 223 | (OPT_ZONE_DMA << (___GFP_MOVABLE | ___GFP_DMA) * ZONES_SHIFT) \
195 | (ZONE_MOVABLE << (__GFP_MOVABLE | __GFP_HIGHMEM) * ZONES_SHIFT)\ 224 | (ZONE_MOVABLE << (___GFP_MOVABLE | ___GFP_HIGHMEM) * ZONES_SHIFT) \
196 | (OPT_ZONE_DMA32 << (__GFP_MOVABLE | __GFP_DMA32) * ZONES_SHIFT)\ 225 | (OPT_ZONE_DMA32 << (___GFP_MOVABLE | ___GFP_DMA32) * ZONES_SHIFT) \
197) 226)
198 227
199/* 228/*
@@ -203,31 +232,24 @@ static inline int allocflags_to_migratetype(gfp_t gfp_flags)
203 * allowed. 232 * allowed.
204 */ 233 */
205#define GFP_ZONE_BAD ( \ 234#define GFP_ZONE_BAD ( \
206 1 << (__GFP_DMA | __GFP_HIGHMEM) \ 235 1 << (___GFP_DMA | ___GFP_HIGHMEM) \
207 | 1 << (__GFP_DMA | __GFP_DMA32) \ 236 | 1 << (___GFP_DMA | ___GFP_DMA32) \
208 | 1 << (__GFP_DMA32 | __GFP_HIGHMEM) \ 237 | 1 << (___GFP_DMA32 | ___GFP_HIGHMEM) \
209 | 1 << (__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM) \ 238 | 1 << (___GFP_DMA | ___GFP_DMA32 | ___GFP_HIGHMEM) \
210 | 1 << (__GFP_MOVABLE | __GFP_HIGHMEM | __GFP_DMA) \ 239 | 1 << (___GFP_MOVABLE | ___GFP_HIGHMEM | ___GFP_DMA) \
211 | 1 << (__GFP_MOVABLE | __GFP_DMA32 | __GFP_DMA) \ 240 | 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_DMA) \
212 | 1 << (__GFP_MOVABLE | __GFP_DMA32 | __GFP_HIGHMEM) \ 241 | 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_HIGHMEM) \
213 | 1 << (__GFP_MOVABLE | __GFP_DMA32 | __GFP_DMA | __GFP_HIGHMEM)\ 242 | 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_DMA | ___GFP_HIGHMEM) \
214) 243)
215 244
216static inline enum zone_type gfp_zone(gfp_t flags) 245static inline enum zone_type gfp_zone(gfp_t flags)
217{ 246{
218 enum zone_type z; 247 enum zone_type z;
219 int bit = flags & GFP_ZONEMASK; 248 int bit = (__force int) (flags & GFP_ZONEMASK);
220 249
221 z = (GFP_ZONE_TABLE >> (bit * ZONES_SHIFT)) & 250 z = (GFP_ZONE_TABLE >> (bit * ZONES_SHIFT)) &
222 ((1 << ZONES_SHIFT) - 1); 251 ((1 << ZONES_SHIFT) - 1);
223 252 VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
224 if (__builtin_constant_p(bit))
225 MAYBE_BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
226 else {
227#ifdef CONFIG_DEBUG_VM
228 BUG_ON((GFP_ZONE_BAD >> bit) & 1);
229#endif
230 }
231 return z; 253 return z;
232} 254}
233 255
@@ -304,20 +326,28 @@ alloc_pages(gfp_t gfp_mask, unsigned int order)
304{ 326{
305 return alloc_pages_current(gfp_mask, order); 327 return alloc_pages_current(gfp_mask, order);
306} 328}
307extern struct page *alloc_page_vma(gfp_t gfp_mask, 329extern struct page *alloc_pages_vma(gfp_t gfp_mask, int order,
308 struct vm_area_struct *vma, unsigned long addr); 330 struct vm_area_struct *vma, unsigned long addr,
331 int node);
309#else 332#else
310#define alloc_pages(gfp_mask, order) \ 333#define alloc_pages(gfp_mask, order) \
311 alloc_pages_node(numa_node_id(), gfp_mask, order) 334 alloc_pages_node(numa_node_id(), gfp_mask, order)
312#define alloc_page_vma(gfp_mask, vma, addr) alloc_pages(gfp_mask, 0) 335#define alloc_pages_vma(gfp_mask, order, vma, addr, node) \
336 alloc_pages(gfp_mask, order)
313#endif 337#endif
314#define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0) 338#define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
339#define alloc_page_vma(gfp_mask, vma, addr) \
340 alloc_pages_vma(gfp_mask, 0, vma, addr, numa_node_id())
341#define alloc_page_vma_node(gfp_mask, vma, addr, node) \
342 alloc_pages_vma(gfp_mask, 0, vma, addr, node)
315 343
316extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order); 344extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order);
317extern unsigned long get_zeroed_page(gfp_t gfp_mask); 345extern unsigned long get_zeroed_page(gfp_t gfp_mask);
318 346
319void *alloc_pages_exact(size_t size, gfp_t gfp_mask); 347void *alloc_pages_exact(size_t size, gfp_t gfp_mask);
320void free_pages_exact(void *virt, size_t size); 348void free_pages_exact(void *virt, size_t size);
349/* This is different from alloc_pages_exact_node !!! */
350void *alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask);
321 351
322#define __get_free_page(gfp_mask) \ 352#define __get_free_page(gfp_mask) \
323 __get_free_pages((gfp_mask), 0) 353 __get_free_pages((gfp_mask), 0)
@@ -339,7 +369,7 @@ void drain_local_pages(void *dummy);
339 369
340extern gfp_t gfp_allowed_mask; 370extern gfp_t gfp_allowed_mask;
341 371
342extern void set_gfp_allowed_mask(gfp_t mask); 372extern void pm_restrict_gfp_mask(void);
343extern gfp_t clear_gfp_allowed_mask(gfp_t mask); 373extern void pm_restore_gfp_mask(void);
344 374
345#endif /* __LINUX_GFP_H */ 375#endif /* __LINUX_GFP_H */