blob: 77b078c103b264d9b55361dec47c4a42f4595370 [file] [log] [blame]
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -08001#ifndef PAGE_FLAGS_LAYOUT_H
2#define PAGE_FLAGS_LAYOUT_H
3
4#include <linux/numa.h>
5#include <generated/bounds.h>
6
7/*
8 * When a memory allocation must conform to specific limitations (such
9 * as being suitable for DMA) the caller will pass in hints to the
10 * allocator in the gfp_mask, in the zone modifier bits. These bits
11 * are used to select a priority ordered list of memory zones which
12 * match the requested limits. See gfp_zone() in include/linux/gfp.h
13 */
14#if MAX_NR_ZONES < 2
15#define ZONES_SHIFT 0
16#elif MAX_NR_ZONES <= 2
17#define ZONES_SHIFT 1
18#elif MAX_NR_ZONES <= 4
19#define ZONES_SHIFT 2
Dan Williamsb11a7b92016-03-17 14:19:41 -070020#elif MAX_NR_ZONES <= 8
21#define ZONES_SHIFT 3
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080022#else
23#error ZONES_SHIFT -- too many zones configured adjust calculation
24#endif
25
26#ifdef CONFIG_SPARSEMEM
27#include <asm/sparsemem.h>
28
29/* SECTION_SHIFT #bits space required to store a section # */
30#define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
31
32#endif /* CONFIG_SPARSEMEM */
33
34/*
35 * page->flags layout:
36 *
Peter Zijlstra75980e92013-02-22 16:34:32 -080037 * There are five possibilities for how page->flags get laid out. The first
38 * pair is for the normal case without sparsemem. The second pair is for
39 * sparsemem when there is plenty of space for node and section information.
40 * The last is when there is insufficient space in page->flags and a separate
41 * lookup is necessary.
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080042 *
Mel Gormanb7958542013-10-07 11:29:07 +010043 * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS |
Peter Zijlstra90572892013-10-07 11:29:20 +010044 * " plus space for last_cpupid: | NODE | ZONE | LAST_CPUPID ... | FLAGS |
Mel Gormanb7958542013-10-07 11:29:07 +010045 * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
Peter Zijlstra90572892013-10-07 11:29:20 +010046 * " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS |
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080047 * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS |
48 */
49#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
50#define SECTIONS_WIDTH SECTIONS_SHIFT
51#else
52#define SECTIONS_WIDTH 0
53#endif
54
55#define ZONES_WIDTH ZONES_SHIFT
56
57#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
58#define NODES_WIDTH NODES_SHIFT
59#else
60#ifdef CONFIG_SPARSEMEM_VMEMMAP
61#error "Vmemmap: No space for nodes field in page flags"
62#endif
63#define NODES_WIDTH 0
64#endif
65
Peter Zijlstra75980e92013-02-22 16:34:32 -080066#ifdef CONFIG_NUMA_BALANCING
Mel Gormanb7958542013-10-07 11:29:07 +010067#define LAST__PID_SHIFT 8
68#define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1)
69
Peter Zijlstra90572892013-10-07 11:29:20 +010070#define LAST__CPU_SHIFT NR_CPUS_BITS
71#define LAST__CPU_MASK ((1 << LAST__CPU_SHIFT)-1)
Mel Gormanb7958542013-10-07 11:29:07 +010072
Peter Zijlstra90572892013-10-07 11:29:20 +010073#define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT)
Peter Zijlstra75980e92013-02-22 16:34:32 -080074#else
Peter Zijlstra90572892013-10-07 11:29:20 +010075#define LAST_CPUPID_SHIFT 0
Peter Zijlstra75980e92013-02-22 16:34:32 -080076#endif
77
Peter Zijlstra90572892013-10-07 11:29:20 +010078#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
79#define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
Peter Zijlstra75980e92013-02-22 16:34:32 -080080#else
Peter Zijlstra90572892013-10-07 11:29:20 +010081#define LAST_CPUPID_WIDTH 0
Peter Zijlstra75980e92013-02-22 16:34:32 -080082#endif
83
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080084/*
85 * We are going to use the flags for the page to node mapping if its in
86 * there. This includes the case where there is no node, so it is implicit.
87 */
88#if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
89#define NODE_NOT_IN_PAGE_FLAGS
90#endif
91
Peter Zijlstra90572892013-10-07 11:29:20 +010092#if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0
93#define LAST_CPUPID_NOT_IN_PAGE_FLAGS
Peter Zijlstra75980e92013-02-22 16:34:32 -080094#endif
95
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080096#endif /* _LINUX_PAGE_FLAGS_LAYOUT */