1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Macros for manipulating and testing flags related to a
4 * pageblock_nr_pages number of pages.
5 *
6 * Copyright (C) IBM Corporation, 2006
7 *
8 * Original author, Mel Gorman
9 * Major cleanups and reduction of bit operations, Andy Whitcroft
10 */
11 #ifndef PAGEBLOCK_FLAGS_H
12 #define PAGEBLOCK_FLAGS_H
13
14 #include <linux/types.h>
15
16 #define PB_migratetype_bits 3
17 /* Bit indices that affect a whole block of pages */
18 enum pageblock_bits {
19 PB_migrate,
20 PB_migrate_end = PB_migrate + PB_migratetype_bits - 1,
21 /* 3 bits required for migrate types */
22 PB_compact_skip,/* If set the block is skipped by compaction */
23
24 #ifdef CONFIG_MEMORY_ISOLATION
25 /*
26 * Pageblock isolation is represented with a separate bit, so that
27 * the migratetype of a block is not overwritten by isolation.
28 */
29 PB_migrate_isolate, /* If set the block is isolated */
30 #endif
31 /*
32 * Assume the bits will always align on a word. If this assumption
33 * changes then get/set pageblock needs updating.
34 */
35 __NR_PAGEBLOCK_BITS
36 };
37
38 #define NR_PAGEBLOCK_BITS (roundup_pow_of_two(__NR_PAGEBLOCK_BITS))
39
40 #define MIGRATETYPE_MASK ((1UL << (PB_migrate_end + 1)) - 1)
41
42 #ifdef CONFIG_MEMORY_ISOLATION
43 #define MIGRATETYPE_AND_ISO_MASK \
44 (((1UL << (PB_migrate_end + 1)) - 1) | BIT(PB_migrate_isolate))
45 #else
46 #define MIGRATETYPE_AND_ISO_MASK MIGRATETYPE_MASK
47 #endif
48
49 #if defined(CONFIG_HUGETLB_PAGE)
50
51 #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
52
53 /* Huge page sizes are variable */
54 extern unsigned int pageblock_order;
55
56 #else /* CONFIG_HUGETLB_PAGE_SIZE_VARIABLE */
57
58 /*
59 * Huge pages are a constant size, but don't exceed the maximum allocation
60 * granularity.
61 */
62 #define pageblock_order MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
63
64 #endif /* CONFIG_HUGETLB_PAGE_SIZE_VARIABLE */
65
66 #elif defined(CONFIG_TRANSPARENT_HUGEPAGE)
67
68 #define pageblock_order MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
69
70 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
71
72 /* If huge pages are not used, group by PAGE_BLOCK_MAX_ORDER */
73 #define pageblock_order PAGE_BLOCK_MAX_ORDER
74
75 #endif /* CONFIG_HUGETLB_PAGE */
76
77 #define pageblock_nr_pages (1UL << pageblock_order)
78 #define pageblock_align(pfn) ALIGN((pfn), pageblock_nr_pages)
79 #define pageblock_aligned(pfn) IS_ALIGNED((pfn), pageblock_nr_pages)
80 #define pageblock_start_pfn(pfn) ALIGN_DOWN((pfn), pageblock_nr_pages)
81 #define pageblock_end_pfn(pfn) ALIGN((pfn) + 1, pageblock_nr_pages)
82
83 /* Forward declaration */
84 struct page;
85
86 enum migratetype get_pfnblock_migratetype(const struct page *page,
87 unsigned long pfn);
88 bool get_pfnblock_bit(const struct page *page, unsigned long pfn,
89 enum pageblock_bits pb_bit);
90 void set_pfnblock_bit(const struct page *page, unsigned long pfn,
91 enum pageblock_bits pb_bit);
92 void clear_pfnblock_bit(const struct page *page, unsigned long pfn,
93 enum pageblock_bits pb_bit);
94
95 /* Declarations for getting and setting flags. See mm/page_alloc.c */
96 #ifdef CONFIG_COMPACTION
97 #define get_pageblock_skip(page) \
98 get_pfnblock_bit(page, page_to_pfn(page), PB_compact_skip)
99 #define clear_pageblock_skip(page) \
100 clear_pfnblock_bit(page, page_to_pfn(page), PB_compact_skip)
101 #define set_pageblock_skip(page) \
102 set_pfnblock_bit(page, page_to_pfn(page), PB_compact_skip)
103 #else
get_pageblock_skip(struct page * page)104 static inline bool get_pageblock_skip(struct page *page)
105 {
106 return false;
107 }
clear_pageblock_skip(struct page * page)108 static inline void clear_pageblock_skip(struct page *page)
109 {
110 }
set_pageblock_skip(struct page * page)111 static inline void set_pageblock_skip(struct page *page)
112 {
113 }
114 #endif /* CONFIG_COMPACTION */
115
116 #endif /* PAGEBLOCK_FLAGS_H */
117