.. | .. |
---|
24 | 24 | #define ___GFP_HIGH 0x20u |
---|
25 | 25 | #define ___GFP_IO 0x40u |
---|
26 | 26 | #define ___GFP_FS 0x80u |
---|
27 | | -#define ___GFP_WRITE 0x100u |
---|
28 | | -#define ___GFP_NOWARN 0x200u |
---|
29 | | -#define ___GFP_RETRY_MAYFAIL 0x400u |
---|
30 | | -#define ___GFP_NOFAIL 0x800u |
---|
31 | | -#define ___GFP_NORETRY 0x1000u |
---|
32 | | -#define ___GFP_MEMALLOC 0x2000u |
---|
33 | | -#define ___GFP_COMP 0x4000u |
---|
34 | | -#define ___GFP_ZERO 0x8000u |
---|
35 | | -#define ___GFP_NOMEMALLOC 0x10000u |
---|
36 | | -#define ___GFP_HARDWALL 0x20000u |
---|
37 | | -#define ___GFP_THISNODE 0x40000u |
---|
38 | | -#define ___GFP_ATOMIC 0x80000u |
---|
39 | | -#define ___GFP_ACCOUNT 0x100000u |
---|
40 | | -#define ___GFP_DIRECT_RECLAIM 0x200000u |
---|
41 | | -#define ___GFP_KSWAPD_RECLAIM 0x400000u |
---|
| 27 | +#define ___GFP_ZERO 0x100u |
---|
| 28 | +#define ___GFP_ATOMIC 0x200u |
---|
| 29 | +#define ___GFP_DIRECT_RECLAIM 0x400u |
---|
| 30 | +#define ___GFP_KSWAPD_RECLAIM 0x800u |
---|
| 31 | +#define ___GFP_WRITE 0x1000u |
---|
| 32 | +#define ___GFP_NOWARN 0x2000u |
---|
| 33 | +#define ___GFP_RETRY_MAYFAIL 0x4000u |
---|
| 34 | +#define ___GFP_NOFAIL 0x8000u |
---|
| 35 | +#define ___GFP_NORETRY 0x10000u |
---|
| 36 | +#define ___GFP_MEMALLOC 0x20000u |
---|
| 37 | +#define ___GFP_COMP 0x40000u |
---|
| 38 | +#define ___GFP_NOMEMALLOC 0x80000u |
---|
| 39 | +#define ___GFP_HARDWALL 0x100000u |
---|
| 40 | +#define ___GFP_THISNODE 0x200000u |
---|
| 41 | +#define ___GFP_ACCOUNT 0x400000u |
---|
| 42 | +#define ___GFP_ZEROTAGS 0x800000u |
---|
| 43 | +#define ___GFP_SKIP_KASAN_POISON 0x1000000u |
---|
| 44 | +#ifdef CONFIG_CMA |
---|
| 45 | +#define ___GFP_CMA 0x2000000u |
---|
| 46 | +#else |
---|
| 47 | +#define ___GFP_CMA 0 |
---|
| 48 | +#endif |
---|
42 | 49 | #ifdef CONFIG_LOCKDEP |
---|
43 | | -#define ___GFP_NOLOCKDEP 0x800000u |
---|
| 50 | +#ifdef CONFIG_CMA |
---|
| 51 | +#define ___GFP_NOLOCKDEP 0x4000000u |
---|
| 52 | +#else |
---|
| 53 | +#define ___GFP_NOLOCKDEP 0x2000000u |
---|
| 54 | +#endif |
---|
44 | 55 | #else |
---|
45 | 56 | #define ___GFP_NOLOCKDEP 0 |
---|
46 | 57 | #endif |
---|
47 | | -#define ___GFP_CMA 0x1000000u |
---|
| 58 | + |
---|
48 | 59 | /* If the above are modified, __GFP_BITS_SHIFT may need updating */ |
---|
49 | 60 | |
---|
50 | 61 | /* |
---|
.. | .. |
---|
83 | 94 | * |
---|
84 | 95 | * %__GFP_HARDWALL enforces the cpuset memory allocation policy. |
---|
85 | 96 | * |
---|
86 | | - * %__GFP_THISNODE forces the allocation to be satisified from the requested |
---|
| 97 | + * %__GFP_THISNODE forces the allocation to be satisfied from the requested |
---|
87 | 98 | * node with no fallbacks or placement policy enforcements. |
---|
88 | 99 | * |
---|
89 | 100 | * %__GFP_ACCOUNT causes the allocation to be accounted to kmemcg. |
---|
.. | .. |
---|
112 | 123 | * the caller guarantees the allocation will allow more memory to be freed |
---|
113 | 124 | * very shortly e.g. process exiting or swapping. Users either should |
---|
114 | 125 | * be the MM or co-ordinating closely with the VM (e.g. swap over NFS). |
---|
| 126 | + * Users of this flag have to be extremely careful to not deplete the reserve |
---|
| 127 | + * completely and implement a throttling mechanism which controls the |
---|
| 128 | + * consumption of the reserve based on the amount of freed memory. |
---|
| 129 | + * Usage of a pre-allocated pool (e.g. mempool) should be always considered |
---|
| 130 | + * before using this flag. |
---|
115 | 131 | * |
---|
116 | 132 | * %__GFP_NOMEMALLOC is used to explicitly forbid access to emergency reserves. |
---|
117 | 133 | * This takes precedence over the %__GFP_MEMALLOC flag if both are set. |
---|
.. | .. |
---|
126 | 142 | * |
---|
127 | 143 | * Reclaim modifiers |
---|
128 | 144 | * ~~~~~~~~~~~~~~~~~ |
---|
| 145 | + * Please note that all the following flags are only applicable to sleepable |
---|
| 146 | + * allocations (e.g. %GFP_NOWAIT and %GFP_ATOMIC will ignore them). |
---|
129 | 147 | * |
---|
130 | 148 | * %__GFP_IO can start physical IO. |
---|
131 | 149 | * |
---|
.. | .. |
---|
210 | 228 | * %__GFP_COMP address compound page metadata. |
---|
211 | 229 | * |
---|
212 | 230 | * %__GFP_ZERO returns a zeroed page on success. |
---|
| 231 | + * |
---|
| 232 | + * %__GFP_ZEROTAGS returns a page with zeroed memory tags on success, if |
---|
| 233 | + * __GFP_ZERO is set. |
---|
| 234 | + * |
---|
| 235 | + * %__GFP_SKIP_KASAN_POISON returns a page which does not need to be poisoned |
---|
| 236 | + * on deallocation. Typically used for userspace pages. Currently only has an |
---|
| 237 | + * effect in HW tags mode. |
---|
213 | 238 | */ |
---|
214 | 239 | #define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) |
---|
215 | 240 | #define __GFP_COMP ((__force gfp_t)___GFP_COMP) |
---|
216 | 241 | #define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) |
---|
| 242 | +#define __GFP_ZEROTAGS ((__force gfp_t)___GFP_ZEROTAGS) |
---|
| 243 | +#define __GFP_SKIP_KASAN_POISON ((__force gfp_t)___GFP_SKIP_KASAN_POISON) |
---|
217 | 244 | |
---|
218 | 245 | /* Disable lockdep for GFP context tracking */ |
---|
219 | 246 | #define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP) |
---|
220 | 247 | |
---|
221 | 248 | /* Room for N __GFP_FOO bits */ |
---|
222 | | -#define __GFP_BITS_SHIFT (25) |
---|
223 | | -#ifdef CONFIG_LOCKDEP |
---|
224 | | -#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) |
---|
| 249 | +#ifdef CONFIG_CMA |
---|
| 250 | +#define __GFP_BITS_SHIFT (26 + IS_ENABLED(CONFIG_LOCKDEP)) |
---|
225 | 251 | #else |
---|
226 | | -#define __GFP_BITS_MASK (((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) & \ |
---|
227 | | - ~0x800000u) |
---|
| 252 | +#define __GFP_BITS_SHIFT (25 + IS_ENABLED(CONFIG_LOCKDEP)) |
---|
228 | 253 | #endif |
---|
| 254 | +#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) |
---|
229 | 255 | |
---|
230 | 256 | /** |
---|
231 | 257 | * DOC: Useful GFP flag combinations |
---|
.. | .. |
---|
238 | 264 | * %__GFP_FOO flags as necessary. |
---|
239 | 265 | * |
---|
240 | 266 | * %GFP_ATOMIC users can not sleep and need the allocation to succeed. A lower |
---|
241 | | - * watermark is applied to allow access to "atomic reserves" |
---|
| 267 | + * watermark is applied to allow access to "atomic reserves". |
---|
| 268 | + * The current implementation doesn't support NMI and few other strict |
---|
| 269 | + * non-preemptive contexts (e.g. raw_spin_lock). The same applies to %GFP_NOWAIT. |
---|
242 | 270 | * |
---|
243 | 271 | * %GFP_KERNEL is typical for kernel-internal allocations. The caller requires |
---|
244 | 272 | * %ZONE_NORMAL or a lower zone for direct access but can direct reclaim. |
---|
.. | .. |
---|
303 | 331 | #define GFP_DMA __GFP_DMA |
---|
304 | 332 | #define GFP_DMA32 __GFP_DMA32 |
---|
305 | 333 | #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) |
---|
306 | | -#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE) |
---|
| 334 | +#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | \ |
---|
| 335 | + __GFP_SKIP_KASAN_POISON) |
---|
307 | 336 | #define GFP_TRANSHUGE_LIGHT ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ |
---|
308 | 337 | __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) |
---|
309 | 338 | #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) |
---|
.. | .. |
---|
312 | 341 | #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE) |
---|
313 | 342 | #define GFP_MOVABLE_SHIFT 3 |
---|
314 | 343 | |
---|
315 | | -static inline int gfpflags_to_migratetype(const gfp_t gfp_flags) |
---|
| 344 | +static inline int gfp_migratetype(const gfp_t gfp_flags) |
---|
316 | 345 | { |
---|
317 | 346 | VM_WARN_ON((gfp_flags & GFP_MOVABLE_MASK) == GFP_MOVABLE_MASK); |
---|
318 | 347 | BUILD_BUG_ON((1UL << GFP_MOVABLE_SHIFT) != ___GFP_MOVABLE); |
---|
.. | .. |
---|
445 | 474 | | 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_DMA | ___GFP_HIGHMEM) \ |
---|
446 | 475 | ) |
---|
447 | 476 | |
---|
448 | | -static inline enum zone_type gfp_zone(gfp_t flags) |
---|
449 | | -{ |
---|
450 | | - enum zone_type z; |
---|
451 | | - int bit = (__force int) (flags & GFP_ZONEMASK); |
---|
452 | | - |
---|
453 | | - z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) & |
---|
454 | | - ((1 << GFP_ZONES_SHIFT) - 1); |
---|
455 | | - VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1); |
---|
456 | | - return z; |
---|
457 | | -} |
---|
| 477 | +enum zone_type gfp_zone(gfp_t flags); |
---|
458 | 478 | |
---|
459 | 479 | /* |
---|
460 | 480 | * There is only one page-allocator function, and two main namespaces to |
---|
.. | .. |
---|
491 | 511 | #endif |
---|
492 | 512 | #ifndef HAVE_ARCH_ALLOC_PAGE |
---|
493 | 513 | static inline void arch_alloc_page(struct page *page, int order) { } |
---|
| 514 | +#endif |
---|
| 515 | +#ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE |
---|
| 516 | +static inline int arch_make_page_accessible(struct page *page) |
---|
| 517 | +{ |
---|
| 518 | + return 0; |
---|
| 519 | +} |
---|
494 | 520 | #endif |
---|
495 | 521 | |
---|
496 | 522 | struct page * |
---|
.. | .. |
---|
541 | 567 | extern struct page *alloc_pages_vma(gfp_t gfp_mask, int order, |
---|
542 | 568 | struct vm_area_struct *vma, unsigned long addr, |
---|
543 | 569 | int node, bool hugepage); |
---|
544 | | -#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \ |
---|
| 570 | +#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \ |
---|
545 | 571 | alloc_pages_vma(gfp_mask, order, vma, addr, numa_node_id(), true) |
---|
546 | 572 | #else |
---|
547 | | -#define alloc_pages(gfp_mask, order) \ |
---|
548 | | - alloc_pages_node(numa_node_id(), gfp_mask, order) |
---|
| 573 | +static inline struct page *alloc_pages(gfp_t gfp_mask, unsigned int order) |
---|
| 574 | +{ |
---|
| 575 | + return alloc_pages_node(numa_node_id(), gfp_mask, order); |
---|
| 576 | +} |
---|
549 | 577 | #define alloc_pages_vma(gfp_mask, order, vma, addr, node, false)\ |
---|
550 | 578 | alloc_pages(gfp_mask, order) |
---|
551 | | -#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \ |
---|
| 579 | +#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \ |
---|
552 | 580 | alloc_pages(gfp_mask, order) |
---|
553 | 581 | #endif |
---|
554 | 582 | #define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0) |
---|
555 | 583 | #define alloc_page_vma(gfp_mask, vma, addr) \ |
---|
556 | 584 | alloc_pages_vma(gfp_mask, 0, vma, addr, numa_node_id(), false) |
---|
557 | | -#define alloc_page_vma_node(gfp_mask, vma, addr, node) \ |
---|
558 | | - alloc_pages_vma(gfp_mask, 0, vma, addr, node, false) |
---|
559 | 585 | |
---|
560 | 586 | extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order); |
---|
561 | 587 | extern unsigned long get_zeroed_page(gfp_t gfp_mask); |
---|
.. | .. |
---|
615 | 641 | } |
---|
616 | 642 | #endif /* CONFIG_PM_SLEEP */ |
---|
617 | 643 | |
---|
618 | | -#if (defined(CONFIG_MEMORY_ISOLATION) && defined(CONFIG_COMPACTION)) || defined(CONFIG_CMA) |
---|
| 644 | +#ifdef CONFIG_CONTIG_ALLOC |
---|
| 645 | +extern unsigned long pfn_max_align_up(unsigned long pfn); |
---|
| 646 | + |
---|
| 647 | +#define ACR_ERR_ISOLATE (1 << 0) |
---|
| 648 | +#define ACR_ERR_MIGRATE (1 << 1) |
---|
| 649 | +#define ACR_ERR_TEST (1 << 2) |
---|
| 650 | + |
---|
| 651 | +struct acr_info { |
---|
| 652 | + unsigned long nr_mapped; |
---|
| 653 | + unsigned long nr_migrated; |
---|
| 654 | + unsigned long nr_reclaimed; |
---|
| 655 | + unsigned int err; |
---|
| 656 | + unsigned long failed_pfn; |
---|
| 657 | +}; |
---|
| 658 | + |
---|
619 | 659 | /* The below functions must be run on a range from a single zone. */ |
---|
620 | 660 | extern int alloc_contig_range(unsigned long start, unsigned long end, |
---|
621 | | - unsigned migratetype, gfp_t gfp_mask); |
---|
622 | | -extern void free_contig_range(unsigned long pfn, unsigned nr_pages); |
---|
| 661 | + unsigned migratetype, gfp_t gfp_mask, |
---|
| 662 | + struct acr_info *info); |
---|
| 663 | +extern struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, |
---|
| 664 | + int nid, nodemask_t *nodemask); |
---|
623 | 665 | #endif |
---|
| 666 | +void free_contig_range(unsigned long pfn, unsigned int nr_pages); |
---|
624 | 667 | |
---|
625 | 668 | #ifdef CONFIG_CMA |
---|
626 | 669 | /* CMA stuff */ |
---|