1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PAGE_FLAGS_LAYOUT_H
3 #define PAGE_FLAGS_LAYOUT_H
5 #include <linux/numa.h>
6 #include <generated/bounds.h>
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
17 #elif MAX_NR_ZONES <= 2
19 #elif MAX_NR_ZONES <= 4
21 #elif MAX_NR_ZONES <= 8
24 #error ZONES_SHIFT -- too many zones configured adjust calculation
27 #ifdef CONFIG_SPARSEMEM
28 #include <asm/sparsemem.h>
30 /* SECTION_SHIFT #bits space required to store a section # */
31 #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
33 #endif /* CONFIG_SPARSEMEM */
35 #ifndef BUILD_VDSO32_64
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.
45 * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS |
46 * " plus space for last_cpupid: | NODE | ZONE | LAST_CPUPID ... | FLAGS |
47 * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
48 * " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS |
49 * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS |
51 #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
52 #define SECTIONS_WIDTH SECTIONS_SHIFT
54 #define SECTIONS_WIDTH 0
57 #define ZONES_WIDTH ZONES_SHIFT
59 #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
60 #define NODES_WIDTH NODES_SHIFT
62 #ifdef CONFIG_SPARSEMEM_VMEMMAP
63 #error "Vmemmap: No space for nodes field in page flags"
68 #ifdef CONFIG_NUMA_BALANCING
69 #define LAST__PID_SHIFT 8
70 #define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1)
72 #define LAST__CPU_SHIFT NR_CPUS_BITS
73 #define LAST__CPU_MASK ((1 << LAST__CPU_SHIFT)-1)
75 #define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT)
77 #define LAST_CPUPID_SHIFT 0
80 #ifdef CONFIG_KASAN_SW_TAGS
81 #define KASAN_TAG_WIDTH 8
83 #define KASAN_TAG_WIDTH 0
86 #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT+KASAN_TAG_WIDTH \
87 <= BITS_PER_LONG - NR_PAGEFLAGS
88 #define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
90 #define LAST_CPUPID_WIDTH 0
93 #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH+LAST_CPUPID_WIDTH+KASAN_TAG_WIDTH \
94 > BITS_PER_LONG - NR_PAGEFLAGS
95 #error "Not enough bits in page flags"
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.
102 #if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
103 #define NODE_NOT_IN_PAGE_FLAGS
106 #if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0
107 #define LAST_CPUPID_NOT_IN_PAGE_FLAGS
111 #endif /* _LINUX_PAGE_FLAGS_LAYOUT */