blob: 7ec86bf31ce48602b2fdbbdadca43a9436c5d62a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -08002#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 Williamsb11a7b92016-03-17 14:19:41 -070021#elif MAX_NR_ZONES <= 8
22#define ZONES_SHIFT 3
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080023#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/*
36 * page->flags layout:
37 *
Peter Zijlstra75980e92013-02-22 16:34:32 -080038 * There are five possibilities for how page->flags get laid out. The first
39 * pair is for the normal case without sparsemem. The second pair is for
40 * sparsemem when there is plenty of space for node and section information.
41 * The last is when there is insufficient space in page->flags and a separate
42 * lookup is necessary.
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080043 *
Mel Gormanb7958542013-10-07 11:29:07 +010044 * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS |
Peter Zijlstra90572892013-10-07 11:29:20 +010045 * " plus space for last_cpupid: | NODE | ZONE | LAST_CPUPID ... | FLAGS |
Mel Gormanb7958542013-10-07 11:29:07 +010046 * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
Peter Zijlstra90572892013-10-07 11:29:20 +010047 * " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS |
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080048 * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS |
49 */
50#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
51#define SECTIONS_WIDTH SECTIONS_SHIFT
52#else
53#define SECTIONS_WIDTH 0
54#endif
55
56#define ZONES_WIDTH ZONES_SHIFT
57
58#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
59#define NODES_WIDTH NODES_SHIFT
60#else
61#ifdef CONFIG_SPARSEMEM_VMEMMAP
62#error "Vmemmap: No space for nodes field in page flags"
63#endif
64#define NODES_WIDTH 0
65#endif
66
Peter Zijlstra75980e92013-02-22 16:34:32 -080067#ifdef CONFIG_NUMA_BALANCING
Mel Gormanb7958542013-10-07 11:29:07 +010068#define LAST__PID_SHIFT 8
69#define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1)
70
Peter Zijlstra90572892013-10-07 11:29:20 +010071#define LAST__CPU_SHIFT NR_CPUS_BITS
72#define LAST__CPU_MASK ((1 << LAST__CPU_SHIFT)-1)
Mel Gormanb7958542013-10-07 11:29:07 +010073
Peter Zijlstra90572892013-10-07 11:29:20 +010074#define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT)
Peter Zijlstra75980e92013-02-22 16:34:32 -080075#else
Peter Zijlstra90572892013-10-07 11:29:20 +010076#define LAST_CPUPID_SHIFT 0
Peter Zijlstra75980e92013-02-22 16:34:32 -080077#endif
78
Peter Zijlstra90572892013-10-07 11:29:20 +010079#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
80#define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
Peter Zijlstra75980e92013-02-22 16:34:32 -080081#else
Peter Zijlstra90572892013-10-07 11:29:20 +010082#define LAST_CPUPID_WIDTH 0
Peter Zijlstra75980e92013-02-22 16:34:32 -080083#endif
84
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080085/*
86 * We are going to use the flags for the page to node mapping if its in
87 * there. This includes the case where there is no node, so it is implicit.
88 */
89#if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
90#define NODE_NOT_IN_PAGE_FLAGS
91#endif
92
Peter Zijlstra90572892013-10-07 11:29:20 +010093#if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0
94#define LAST_CPUPID_NOT_IN_PAGE_FLAGS
Peter Zijlstra75980e92013-02-22 16:34:32 -080095#endif
96
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080097#endif /* _LINUX_PAGE_FLAGS_LAYOUT */