Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 1 | #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 Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 35 | * 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 Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 40 | * |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 41 | * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 42 | * " plus space for last_cpupid: | NODE | ZONE | LAST_CPUPID ... | FLAGS | |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 43 | * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 44 | * " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS | |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 45 | * 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 Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 64 | #ifdef CONFIG_NUMA_BALANCING |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 65 | #define LAST__PID_SHIFT 8 |
| 66 | #define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1) |
| 67 | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 68 | #define LAST__CPU_SHIFT NR_CPUS_BITS |
| 69 | #define LAST__CPU_MASK ((1 << LAST__CPU_SHIFT)-1) |
Mel Gorman | b795854 | 2013-10-07 11:29:07 +0100 | [diff] [blame] | 70 | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 71 | #define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT) |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 72 | #else |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 73 | #define LAST_CPUPID_SHIFT 0 |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 74 | #endif |
| 75 | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 76 | #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS |
| 77 | #define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 78 | #else |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 79 | #define LAST_CPUPID_WIDTH 0 |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 80 | #endif |
| 81 | |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 82 | /* |
| 83 | * We are going to use the flags for the page to node mapping if its in |
| 84 | * there. This includes the case where there is no node, so it is implicit. |
| 85 | */ |
| 86 | #if !(NODES_WIDTH > 0 || NODES_SHIFT == 0) |
| 87 | #define NODE_NOT_IN_PAGE_FLAGS |
| 88 | #endif |
| 89 | |
Peter Zijlstra | 9057289 | 2013-10-07 11:29:20 +0100 | [diff] [blame] | 90 | #if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0 |
| 91 | #define LAST_CPUPID_NOT_IN_PAGE_FLAGS |
Peter Zijlstra | 75980e9 | 2013-02-22 16:34:32 -0800 | [diff] [blame] | 92 | #endif |
| 93 | |
Peter Zijlstra | bbeae5b | 2013-02-22 16:34:30 -0800 | [diff] [blame] | 94 | #endif /* _LINUX_PAGE_FLAGS_LAYOUT */ |