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.h164
1 files changed, 132 insertions, 32 deletions
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 3760e7c5de02..cfdb35d71bca 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -5,6 +5,7 @@
5#include <linux/stddef.h> 5#include <linux/stddef.h>
6#include <linux/linkage.h> 6#include <linux/linkage.h>
7#include <linux/topology.h> 7#include <linux/topology.h>
8#include <linux/mmdebug.h>
8 9
9struct vm_area_struct; 10struct vm_area_struct;
10 11
@@ -20,7 +21,8 @@ struct vm_area_struct;
20#define __GFP_DMA ((__force gfp_t)0x01u) 21#define __GFP_DMA ((__force gfp_t)0x01u)
21#define __GFP_HIGHMEM ((__force gfp_t)0x02u) 22#define __GFP_HIGHMEM ((__force gfp_t)0x02u)
22#define __GFP_DMA32 ((__force gfp_t)0x04u) 23#define __GFP_DMA32 ((__force gfp_t)0x04u)
23 24#define __GFP_MOVABLE ((__force gfp_t)0x08u) /* Page is movable */
25#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE)
24/* 26/*
25 * Action modifiers - doesn't change the zoning 27 * Action modifiers - doesn't change the zoning
26 * 28 *
@@ -50,9 +52,20 @@ struct vm_area_struct;
50#define __GFP_HARDWALL ((__force gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */ 52#define __GFP_HARDWALL ((__force gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */
51#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ 53#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */
52#define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u) /* Page is reclaimable */ 54#define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u) /* Page is reclaimable */
53#define __GFP_MOVABLE ((__force gfp_t)0x100000u) /* Page is movable */
54 55
55#define __GFP_BITS_SHIFT 21 /* Room for 21 __GFP_FOO bits */ 56#ifdef CONFIG_KMEMCHECK
57#define __GFP_NOTRACK ((__force gfp_t)0x200000u) /* Don't track with kmemcheck */
58#else
59#define __GFP_NOTRACK ((__force gfp_t)0)
60#endif
61
62/*
63 * This may seem redundant, but it's a way of annotating false positives vs.
64 * allocations that simply cannot be supported (e.g. page tables).
65 */
66#define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67
68#define __GFP_BITS_SHIFT 22 /* Room for 22 __GFP_FOO bits */
56#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) 69#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
57 70
58/* This equals 0, but use constants in case they ever change */ 71/* This equals 0, but use constants in case they ever change */
@@ -115,24 +128,105 @@ static inline int allocflags_to_migratetype(gfp_t gfp_flags)
115 ((gfp_flags & __GFP_RECLAIMABLE) != 0); 128 ((gfp_flags & __GFP_RECLAIMABLE) != 0);
116} 129}
117 130
118static inline enum zone_type gfp_zone(gfp_t flags) 131#ifdef CONFIG_HIGHMEM
119{ 132#define OPT_ZONE_HIGHMEM ZONE_HIGHMEM
133#else
134#define OPT_ZONE_HIGHMEM ZONE_NORMAL
135#endif
136
120#ifdef CONFIG_ZONE_DMA 137#ifdef CONFIG_ZONE_DMA
121 if (flags & __GFP_DMA) 138#define OPT_ZONE_DMA ZONE_DMA
122 return ZONE_DMA; 139#else
140#define OPT_ZONE_DMA ZONE_NORMAL
123#endif 141#endif
142
124#ifdef CONFIG_ZONE_DMA32 143#ifdef CONFIG_ZONE_DMA32
125 if (flags & __GFP_DMA32) 144#define OPT_ZONE_DMA32 ZONE_DMA32
126 return ZONE_DMA32; 145#else
146#define OPT_ZONE_DMA32 ZONE_NORMAL
127#endif 147#endif
128 if ((flags & (__GFP_HIGHMEM | __GFP_MOVABLE)) == 148
129 (__GFP_HIGHMEM | __GFP_MOVABLE)) 149/*
130 return ZONE_MOVABLE; 150 * GFP_ZONE_TABLE is a word size bitstring that is used for looking up the
131#ifdef CONFIG_HIGHMEM 151 * zone to use given the lowest 4 bits of gfp_t. Entries are ZONE_SHIFT long
132 if (flags & __GFP_HIGHMEM) 152 * and there are 16 of them to cover all possible combinations of
133 return ZONE_HIGHMEM; 153 * __GFP_DMA, __GFP_DMA32, __GFP_MOVABLE and __GFP_HIGHMEM
154 *
155 * The zone fallback order is MOVABLE=>HIGHMEM=>NORMAL=>DMA32=>DMA.
156 * But GFP_MOVABLE is not only a zone specifier but also an allocation
157 * policy. Therefore __GFP_MOVABLE plus another zone selector is valid.
158 * Only 1bit of the lowest 3 bit (DMA,DMA32,HIGHMEM) can be set to "1".
159 *
160 * bit result
161 * =================
162 * 0x0 => NORMAL
163 * 0x1 => DMA or NORMAL
164 * 0x2 => HIGHMEM or NORMAL
165 * 0x3 => BAD (DMA+HIGHMEM)
166 * 0x4 => DMA32 or DMA or NORMAL
167 * 0x5 => BAD (DMA+DMA32)
168 * 0x6 => BAD (HIGHMEM+DMA32)
169 * 0x7 => BAD (HIGHMEM+DMA32+DMA)
170 * 0x8 => NORMAL (MOVABLE+0)
171 * 0x9 => DMA or NORMAL (MOVABLE+DMA)
172 * 0xa => MOVABLE (Movable is valid only if HIGHMEM is set too)
173 * 0xb => BAD (MOVABLE+HIGHMEM+DMA)
174 * 0xc => DMA32 (MOVABLE+HIGHMEM+DMA32)
175 * 0xd => BAD (MOVABLE+DMA32+DMA)
176 * 0xe => BAD (MOVABLE+DMA32+HIGHMEM)
177 * 0xf => BAD (MOVABLE+DMA32+HIGHMEM+DMA)
178 *
179 * ZONES_SHIFT must be <= 2 on 32 bit platforms.
180 */
181
182#if 16 * ZONES_SHIFT > BITS_PER_LONG
183#error ZONES_SHIFT too large to create GFP_ZONE_TABLE integer
184#endif
185
186#define GFP_ZONE_TABLE ( \
187 (ZONE_NORMAL << 0 * ZONES_SHIFT) \
188 | (OPT_ZONE_DMA << __GFP_DMA * ZONES_SHIFT) \
189 | (OPT_ZONE_HIGHMEM << __GFP_HIGHMEM * ZONES_SHIFT) \
190 | (OPT_ZONE_DMA32 << __GFP_DMA32 * ZONES_SHIFT) \
191 | (ZONE_NORMAL << __GFP_MOVABLE * ZONES_SHIFT) \
192 | (OPT_ZONE_DMA << (__GFP_MOVABLE | __GFP_DMA) * ZONES_SHIFT) \
193 | (ZONE_MOVABLE << (__GFP_MOVABLE | __GFP_HIGHMEM) * ZONES_SHIFT)\
194 | (OPT_ZONE_DMA32 << (__GFP_MOVABLE | __GFP_DMA32) * ZONES_SHIFT)\
195)
196
197/*
198 * GFP_ZONE_BAD is a bitmap for all combination of __GFP_DMA, __GFP_DMA32
199 * __GFP_HIGHMEM and __GFP_MOVABLE that are not permitted. One flag per
200 * entry starting with bit 0. Bit is set if the combination is not
201 * allowed.
202 */
203#define GFP_ZONE_BAD ( \
204 1 << (__GFP_DMA | __GFP_HIGHMEM) \
205 | 1 << (__GFP_DMA | __GFP_DMA32) \
206 | 1 << (__GFP_DMA32 | __GFP_HIGHMEM) \
207 | 1 << (__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM) \
208 | 1 << (__GFP_MOVABLE | __GFP_HIGHMEM | __GFP_DMA) \
209 | 1 << (__GFP_MOVABLE | __GFP_DMA32 | __GFP_DMA) \
210 | 1 << (__GFP_MOVABLE | __GFP_DMA32 | __GFP_HIGHMEM) \
211 | 1 << (__GFP_MOVABLE | __GFP_DMA32 | __GFP_DMA | __GFP_HIGHMEM)\
212)
213
214static inline enum zone_type gfp_zone(gfp_t flags)
215{
216 enum zone_type z;
217 int bit = flags & GFP_ZONEMASK;
218
219 z = (GFP_ZONE_TABLE >> (bit * ZONES_SHIFT)) &
220 ((1 << ZONES_SHIFT) - 1);
221
222 if (__builtin_constant_p(bit))
223 BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
224 else {
225#ifdef CONFIG_DEBUG_VM
226 BUG_ON((GFP_ZONE_BAD >> bit) & 1);
134#endif 227#endif
135 return ZONE_NORMAL; 228 }
229 return z;
136} 230}
137 231
138/* 232/*
@@ -172,30 +266,19 @@ static inline void arch_alloc_page(struct page *page, int order) { }
172#endif 266#endif
173 267
174struct page * 268struct page *
175__alloc_pages_internal(gfp_t gfp_mask, unsigned int order, 269__alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
176 struct zonelist *zonelist, nodemask_t *nodemask); 270 struct zonelist *zonelist, nodemask_t *nodemask);
177 271
178static inline struct page * 272static inline struct page *
179__alloc_pages(gfp_t gfp_mask, unsigned int order, 273__alloc_pages(gfp_t gfp_mask, unsigned int order,
180 struct zonelist *zonelist) 274 struct zonelist *zonelist)
181{ 275{
182 return __alloc_pages_internal(gfp_mask, order, zonelist, NULL); 276 return __alloc_pages_nodemask(gfp_mask, order, zonelist, NULL);
183} 277}
184 278
185static inline struct page *
186__alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
187 struct zonelist *zonelist, nodemask_t *nodemask)
188{
189 return __alloc_pages_internal(gfp_mask, order, zonelist, nodemask);
190}
191
192
193static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask, 279static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask,
194 unsigned int order) 280 unsigned int order)
195{ 281{
196 if (unlikely(order >= MAX_ORDER))
197 return NULL;
198
199 /* Unknown node is current node */ 282 /* Unknown node is current node */
200 if (nid < 0) 283 if (nid < 0)
201 nid = numa_node_id(); 284 nid = numa_node_id();
@@ -203,15 +286,20 @@ static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask,
203 return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask)); 286 return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask));
204} 287}
205 288
289static inline struct page *alloc_pages_exact_node(int nid, gfp_t gfp_mask,
290 unsigned int order)
291{
292 VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES);
293
294 return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask));
295}
296
206#ifdef CONFIG_NUMA 297#ifdef CONFIG_NUMA
207extern struct page *alloc_pages_current(gfp_t gfp_mask, unsigned order); 298extern struct page *alloc_pages_current(gfp_t gfp_mask, unsigned order);
208 299
209static inline struct page * 300static inline struct page *
210alloc_pages(gfp_t gfp_mask, unsigned int order) 301alloc_pages(gfp_t gfp_mask, unsigned int order)
211{ 302{
212 if (unlikely(order >= MAX_ORDER))
213 return NULL;
214
215 return alloc_pages_current(gfp_mask, order); 303 return alloc_pages_current(gfp_mask, order);
216} 304}
217extern struct page *alloc_page_vma(gfp_t gfp_mask, 305extern struct page *alloc_page_vma(gfp_t gfp_mask,
@@ -248,4 +336,16 @@ void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp);
248void drain_all_pages(void); 336void drain_all_pages(void);
249void drain_local_pages(void *dummy); 337void drain_local_pages(void *dummy);
250 338
339extern bool oom_killer_disabled;
340
341static inline void oom_killer_disable(void)
342{
343 oom_killer_disabled = true;
344}
345
346static inline void oom_killer_enable(void)
347{
348 oom_killer_disabled = false;
349}
350
251#endif /* __LINUX_GFP_H */ 351#endif /* __LINUX_GFP_H */