blob: 93506a114034ba96394b37529e629a392ae834c9 [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
20#else
21#error ZONES_SHIFT -- too many zones configured adjust calculation
22#endif
23
24#ifdef CONFIG_SPARSEMEM
25#include <asm/sparsemem.h>
26
27/* SECTION_SHIFT #bits space required to store a section # */
28#define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
29
30#endif /* CONFIG_SPARSEMEM */
31
32/*
33 * page->flags layout:
34 *
Peter Zijlstra75980e92013-02-22 16:34:32 -080035 * There are five possibilities for how page->flags get laid out. The first
36 * pair is for the normal case without sparsemem. The second pair is for
37 * sparsemem when there is plenty of space for node and section information.
38 * The last is when there is insufficient space in page->flags and a separate
39 * lookup is necessary.
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080040 *
Peter Zijlstra75980e92013-02-22 16:34:32 -080041 * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS |
42 * " plus space for last_nid: | NODE | ZONE | LAST_NID ... | FLAGS |
43 * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
44 * " plus space for last_nid: | SECTION | NODE | ZONE | LAST_NID ... | FLAGS |
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080045 * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS |
46 */
47#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
48#define SECTIONS_WIDTH SECTIONS_SHIFT
49#else
50#define SECTIONS_WIDTH 0
51#endif
52
53#define ZONES_WIDTH ZONES_SHIFT
54
55#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
56#define NODES_WIDTH NODES_SHIFT
57#else
58#ifdef CONFIG_SPARSEMEM_VMEMMAP
59#error "Vmemmap: No space for nodes field in page flags"
60#endif
61#define NODES_WIDTH 0
62#endif
63
Peter Zijlstra75980e92013-02-22 16:34:32 -080064#ifdef CONFIG_NUMA_BALANCING
65#define LAST_NID_SHIFT NODES_SHIFT
66#else
67#define LAST_NID_SHIFT 0
68#endif
69
70#if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_NID_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
71#define LAST_NID_WIDTH LAST_NID_SHIFT
72#else
73#define LAST_NID_WIDTH 0
74#endif
75
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080076/*
77 * We are going to use the flags for the page to node mapping if its in
78 * there. This includes the case where there is no node, so it is implicit.
79 */
80#if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
81#define NODE_NOT_IN_PAGE_FLAGS
82#endif
83
Peter Zijlstra75980e92013-02-22 16:34:32 -080084#if defined(CONFIG_NUMA_BALANCING) && LAST_NID_WIDTH == 0
85#define LAST_NID_NOT_IN_PAGE_FLAGS
86#endif
87
Peter Zijlstrabbeae5b2013-02-22 16:34:30 -080088#endif /* _LINUX_PAGE_FLAGS_LAYOUT */