Linux Audio

Check our new training course

In-person Linux kernel drivers training

Jun 16-20, 2025
Register
Loading...
v5.9
  1/* SPDX-License-Identifier: GPL-2.0 */
  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
 21#elif MAX_NR_ZONES <= 8
 22#define ZONES_SHIFT 3
 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
 35#ifndef BUILD_VDSO32_64
 36/*
 37 * page->flags layout:
 38 *
 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.
 44 *
 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 |
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 68#ifdef CONFIG_NUMA_BALANCING
 69#define LAST__PID_SHIFT 8
 70#define LAST__PID_MASK  ((1 << LAST__PID_SHIFT)-1)
 71
 72#define LAST__CPU_SHIFT NR_CPUS_BITS
 73#define LAST__CPU_MASK  ((1 << LAST__CPU_SHIFT)-1)
 74
 75#define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT)
 76#else
 77#define LAST_CPUPID_SHIFT 0
 78#endif
 79
 80#ifdef CONFIG_KASAN_SW_TAGS
 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
 88#define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
 89#else
 90#define LAST_CPUPID_WIDTH 0
 91#endif
 92
 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"
 96#endif
 97
 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.
101 * Note that this #define MUST have a value so that it can be tested with
102 * the IS_ENABLED() macro.
103 */
104#if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
105#define NODE_NOT_IN_PAGE_FLAGS 1
106#endif
107
108#if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0
109#define LAST_CPUPID_NOT_IN_PAGE_FLAGS
 
110#endif
111
112#endif
113#endif /* _LINUX_PAGE_FLAGS_LAYOUT */
v5.14.15
  1/* SPDX-License-Identifier: GPL-2.0 */
  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
 21#elif MAX_NR_ZONES <= 8
 22#define ZONES_SHIFT 3
 23#else
 24#error ZONES_SHIFT "Too many zones configured"
 25#endif
 26
 27#define ZONES_WIDTH		ZONES_SHIFT
 28
 29#ifdef CONFIG_SPARSEMEM
 30#include <asm/sparsemem.h>
 
 
 31#define SECTIONS_SHIFT	(MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
 32#else
 33#define SECTIONS_SHIFT	0
 34#endif
 35
 36#ifndef BUILD_VDSO32_64
 37/*
 38 * page->flags layout:
 39 *
 40 * There are five possibilities for how page->flags get laid out.  The first
 41 * pair is for the normal case without sparsemem. The second pair is for
 42 * sparsemem when there is plenty of space for node and section information.
 43 * The last is when there is insufficient space in page->flags and a separate
 44 * lookup is necessary.
 45 *
 46 * No sparsemem or sparsemem vmemmap: |       NODE     | ZONE |             ... | FLAGS |
 47 *      " plus space for last_cpupid: |       NODE     | ZONE | LAST_CPUPID ... | FLAGS |
 48 * classic sparse with space for node:| SECTION | NODE | ZONE |             ... | FLAGS |
 49 *      " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS |
 50 * classic sparse no space for node:  | SECTION |     ZONE    | ... | FLAGS |
 51 */
 52#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
 53#define SECTIONS_WIDTH		SECTIONS_SHIFT
 54#else
 55#define SECTIONS_WIDTH		0
 56#endif
 57
 58#if ZONES_WIDTH + SECTIONS_WIDTH + NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
 
 
 59#define NODES_WIDTH		NODES_SHIFT
 60#elif defined(CONFIG_SPARSEMEM_VMEMMAP)
 
 61#error "Vmemmap: No space for nodes field in page flags"
 62#else
 63#define NODES_WIDTH		0
 64#endif
 65
 66/*
 67 * Note that this #define MUST have a value so that it can be tested with
 68 * the IS_ENABLED() macro.
 69 */
 70#if NODES_SHIFT != 0 && NODES_WIDTH == 0
 71#define NODE_NOT_IN_PAGE_FLAGS	1
 72#endif
 73
 74#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
 75#define KASAN_TAG_WIDTH 8
 76#else
 77#define KASAN_TAG_WIDTH 0
 78#endif
 79
 80#ifdef CONFIG_NUMA_BALANCING
 81#define LAST__PID_SHIFT 8
 82#define LAST__PID_MASK  ((1 << LAST__PID_SHIFT)-1)
 83
 84#define LAST__CPU_SHIFT NR_CPUS_BITS
 85#define LAST__CPU_MASK  ((1 << LAST__CPU_SHIFT)-1)
 86
 87#define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT)
 88#else
 89#define LAST_CPUPID_SHIFT 0
 90#endif
 91
 92#if ZONES_WIDTH + SECTIONS_WIDTH + NODES_WIDTH + KASAN_TAG_WIDTH + LAST_CPUPID_SHIFT \
 
 
 
 
 
 
 93	<= BITS_PER_LONG - NR_PAGEFLAGS
 94#define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
 95#else
 96#define LAST_CPUPID_WIDTH 0
 97#endif
 98
 99#if LAST_CPUPID_SHIFT != 0 && LAST_CPUPID_WIDTH == 0
100#define LAST_CPUPID_NOT_IN_PAGE_FLAGS
 
 
 
 
 
 
 
 
 
 
 
101#endif
102
103#if ZONES_WIDTH + SECTIONS_WIDTH + NODES_WIDTH + KASAN_TAG_WIDTH + LAST_CPUPID_WIDTH \
104	> BITS_PER_LONG - NR_PAGEFLAGS
105#error "Not enough bits in page flags"
106#endif
107
108#endif
109#endif /* _LINUX_PAGE_FLAGS_LAYOUT */