Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 2 | #ifndef PAGE_FLAGS_LAYOUT_H |
| 3 | #define PAGE_FLAGS_LAYOUT_H |
| 4 | |
| 5 | #include <linux/numa.h> |
| 6 | #include <generated/bounds.h> |
| 7 | |
| 8 | /* |
| 9 | * When a memory allocation must conform to specific limitations (such |
| 10 | * as being suitable for DMA) the caller will pass in hints to the |
| 11 | * allocator in the gfp_mask, in the zone modifier bits. These bits |
| 12 | * are used to select a priority ordered list of memory zones which |
| 13 | * match the requested limits. See gfp_zone() in include/linux/gfp.h |
| 14 | */ |
| 15 | #if MAX_NR_ZONES < 2 |
| 16 | #define ZONES_SHIFT 0 |
| 17 | #elif MAX_NR_ZONES <= 2 |
| 18 | #define ZONES_SHIFT 1 |
| 19 | #elif MAX_NR_ZONES <= 4 |
| 20 | #define ZONES_SHIFT 2 |
Dan Williams | b11a7b9 | 2016-03-17 14:19:41 -0700 | [diff] [blame] | 21 | #elif MAX_NR_ZONES <= 8 |
| 22 | #define ZONES_SHIFT 3 |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 23 | #else |
| 24 | #error ZONES_SHIFT -- too many zones configured adjust calculation |
| 25 | #endif |
| 26 | |
| 27 | #ifdef CONFIG_SPARSEMEM |
| 28 | #include <asm/sparsemem.h> |
| 29 | |
| 30 | /* SECTION_SHIFT #bits space required to store a section # */ |
| 31 | #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS) |
| 32 | |
| 33 | #endif /* CONFIG_SPARSEMEM */ |
| 34 | |
Arnd Bergmann | ee38d94 | 2019-08-02 21:49:02 -0700 | [diff] [blame] | 35 | #ifndef BUILD_VDSO32_64 |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 36 | /* |
| 37 | * page->flags layout: |
| 38 | * |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 39 | * There are five possibilities for how page->flags get laid out. The first |
| 40 | * pair is for the normal case without sparsemem. The second pair is for |
| 41 | * sparsemem when there is plenty of space for node and section information. |
| 42 | * The last is when there is insufficient space in page->flags and a separate |
| 43 | * lookup is necessary. |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 44 | * |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 45 | * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 46 | * " plus space for last_cpupid: | NODE | ZONE | LAST_CPUPID ... | FLAGS | |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 47 | * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 48 | * " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS | |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 49 | * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS | |
| 50 | */ |
| 51 | #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) |
| 52 | #define SECTIONS_WIDTH SECTIONS_SHIFT |
| 53 | #else |
| 54 | #define SECTIONS_WIDTH 0 |
| 55 | #endif |
| 56 | |
| 57 | #define ZONES_WIDTH ZONES_SHIFT |
| 58 | |
| 59 | #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS |
| 60 | #define NODES_WIDTH NODES_SHIFT |
| 61 | #else |
| 62 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
| 63 | #error "Vmemmap: No space for nodes field in page flags" |
| 64 | #endif |
| 65 | #define NODES_WIDTH 0 |
| 66 | #endif |
| 67 | |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 68 | #ifdef CONFIG_NUMA_BALANCING |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 69 | #define LAST__PID_SHIFT 8 |
| 70 | #define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1) |
| 71 | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 72 | #define LAST__CPU_SHIFT NR_CPUS_BITS |
| 73 | #define LAST__CPU_MASK ((1 << LAST__CPU_SHIFT)-1) |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 74 | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 75 | #define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT) |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 76 | #else |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 77 | #define LAST_CPUPID_SHIFT 0 |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 78 | #endif |
| 79 | |
Andrey Konovalov | 1116716 | 2020-12-22 12:02:10 -0800 | [diff] [blame] | 80 | #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) |
Arnd Bergmann | ee38d94 | 2019-08-02 21:49:02 -0700 | [diff] [blame] | 81 | #define KASAN_TAG_WIDTH 8 |
| 82 | #else |
| 83 | #define KASAN_TAG_WIDTH 0 |
| 84 | #endif |
| 85 | |
| 86 | #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT+KASAN_TAG_WIDTH \ |
| 87 | <= BITS_PER_LONG - NR_PAGEFLAGS |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 88 | #define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 89 | #else |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 90 | #define LAST_CPUPID_WIDTH 0 |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 91 | #endif |
| 92 | |
Andrey Konovalov | 2813b9c | 2018-12-28 00:30:57 -0800 | [diff] [blame] | 93 | #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH+LAST_CPUPID_WIDTH+KASAN_TAG_WIDTH \ |
| 94 | > BITS_PER_LONG - NR_PAGEFLAGS |
Arnd Bergmann | ee38d94 | 2019-08-02 21:49:02 -0700 | [diff] [blame] | 95 | #error "Not enough bits in page flags" |
Andrey Konovalov | 2813b9c | 2018-12-28 00:30:57 -0800 | [diff] [blame] | 96 | #endif |
| 97 | |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 98 | /* |
| 99 | * We are going to use the flags for the page to node mapping if its in |
| 100 | * there. This includes the case where there is no node, so it is implicit. |
Kees Cook | aecfd22 | 2020-06-03 13:28:45 -0700 | [diff] [blame] | 101 | * Note that this #define MUST have a value so that it can be tested with |
| 102 | * the IS_ENABLED() macro. |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 103 | */ |
| 104 | #if !(NODES_WIDTH > 0 || NODES_SHIFT == 0) |
Kees Cook | aecfd22 | 2020-06-03 13:28:45 -0700 | [diff] [blame] | 105 | #define NODE_NOT_IN_PAGE_FLAGS 1 |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 106 | #endif |
| 107 | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 108 | #if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0 |
| 109 | #define LAST_CPUPID_NOT_IN_PAGE_FLAGS |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 110 | #endif |
| 111 | |
Arnd Bergmann | ee38d94 | 2019-08-02 21:49:02 -0700 | [diff] [blame] | 112 | #endif |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 113 | #endif /* _LINUX_PAGE_FLAGS_LAYOUT */ |