1873e65bcSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2835c134eSMel Gorman /*
3835c134eSMel Gorman * Macros for manipulating and testing flags related to a
4d9c23400SMel Gorman * pageblock_nr_pages number of pages.
5835c134eSMel Gorman *
6835c134eSMel Gorman * Copyright (C) IBM Corporation, 2006
7835c134eSMel Gorman *
8835c134eSMel Gorman * Original author, Mel Gorman
9835c134eSMel Gorman * Major cleanups and reduction of bit operations, Andy Whitcroft
10835c134eSMel Gorman */
11835c134eSMel Gorman #ifndef PAGEBLOCK_FLAGS_H
12835c134eSMel Gorman #define PAGEBLOCK_FLAGS_H
13835c134eSMel Gorman
14835c134eSMel Gorman #include <linux/types.h>
15835c134eSMel Gorman
16125b860bSPingfan Liu #define PB_migratetype_bits 3
17835c134eSMel Gorman /* Bit indices that affect a whole block of pages */
18835c134eSMel Gorman enum pageblock_bits {
19c801ed38SPaul Jackson PB_migrate,
20125b860bSPingfan Liu PB_migrate_end = PB_migrate + PB_migratetype_bits - 1,
21c801ed38SPaul Jackson /* 3 bits required for migrate types */
22bb13ffebSMel Gorman PB_migrate_skip,/* If set the block is skipped by compaction */
23e58469baSMel Gorman
24e58469baSMel Gorman /*
25e58469baSMel Gorman * Assume the bits will always align on a word. If this assumption
26e58469baSMel Gorman * changes then get/set pageblock needs updating.
27e58469baSMel Gorman */
28835c134eSMel Gorman NR_PAGEBLOCK_BITS
29835c134eSMel Gorman };
30835c134eSMel Gorman
31d9c23400SMel Gorman #ifdef CONFIG_HUGETLB_PAGE
32d9c23400SMel Gorman
33d9c23400SMel Gorman #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
34d9c23400SMel Gorman
35d9c23400SMel Gorman /* Huge page sizes are variable */
36d00181b9SKirill A. Shutemov extern unsigned int pageblock_order;
37d9c23400SMel Gorman
38d9c23400SMel Gorman #else /* CONFIG_HUGETLB_PAGE_SIZE_VARIABLE */
39d9c23400SMel Gorman
40b3d40a2bSDavid Hildenbrand /*
41b3d40a2bSDavid Hildenbrand * Huge pages are a constant size, but don't exceed the maximum allocation
42b3d40a2bSDavid Hildenbrand * granularity.
43b3d40a2bSDavid Hildenbrand */
44*23baf831SKirill A. Shutemov #define pageblock_order min_t(unsigned int, HUGETLB_PAGE_ORDER, MAX_ORDER)
45d9c23400SMel Gorman
46d9c23400SMel Gorman #endif /* CONFIG_HUGETLB_PAGE_SIZE_VARIABLE */
47d9c23400SMel Gorman
48d9c23400SMel Gorman #else /* CONFIG_HUGETLB_PAGE */
49d9c23400SMel Gorman
50d9c23400SMel Gorman /* If huge pages are not used, group by MAX_ORDER_NR_PAGES */
51*23baf831SKirill A. Shutemov #define pageblock_order MAX_ORDER
52d9c23400SMel Gorman
53d9c23400SMel Gorman #endif /* CONFIG_HUGETLB_PAGE */
54d9c23400SMel Gorman
55d9c23400SMel Gorman #define pageblock_nr_pages (1UL << pageblock_order)
565f7fa13fSKefeng Wang #define pageblock_align(pfn) ALIGN((pfn), pageblock_nr_pages)
57ee0913c4SKefeng Wang #define pageblock_aligned(pfn) IS_ALIGNED((pfn), pageblock_nr_pages)
584f9bc69aSKefeng Wang #define pageblock_start_pfn(pfn) ALIGN_DOWN((pfn), pageblock_nr_pages)
594f9bc69aSKefeng Wang #define pageblock_end_pfn(pfn) ALIGN((pfn) + 1, pageblock_nr_pages)
60d9c23400SMel Gorman
61835c134eSMel Gorman /* Forward declaration */
62835c134eSMel Gorman struct page;
63835c134eSMel Gorman
64ca891f41SMatthew Wilcox (Oracle) unsigned long get_pfnblock_flags_mask(const struct page *page,
65dc4b0cafSMel Gorman unsigned long pfn,
66e58469baSMel Gorman unsigned long mask);
67dc4b0cafSMel Gorman
68dc4b0cafSMel Gorman void set_pfnblock_flags_mask(struct page *page,
69e58469baSMel Gorman unsigned long flags,
70dc4b0cafSMel Gorman unsigned long pfn,
71e58469baSMel Gorman unsigned long mask);
72e58469baSMel Gorman
73835c134eSMel Gorman /* Declarations for getting and setting flags. See mm/page_alloc.c */
74bb13ffebSMel Gorman #ifdef CONFIG_COMPACTION
75bb13ffebSMel Gorman #define get_pageblock_skip(page) \
76d93d5ab9SWei Yang get_pfnblock_flags_mask(page, page_to_pfn(page), \
77535b81e2SWei Yang (1 << (PB_migrate_skip)))
78bb13ffebSMel Gorman #define clear_pageblock_skip(page) \
79d93d5ab9SWei Yang set_pfnblock_flags_mask(page, 0, page_to_pfn(page), \
80535b81e2SWei Yang (1 << PB_migrate_skip))
81bb13ffebSMel Gorman #define set_pageblock_skip(page) \
82d93d5ab9SWei Yang set_pfnblock_flags_mask(page, (1 << PB_migrate_skip), \
83d93d5ab9SWei Yang page_to_pfn(page), \
84535b81e2SWei Yang (1 << PB_migrate_skip))
8521dc7e02SDavid Rientjes #else
get_pageblock_skip(struct page * page)8621dc7e02SDavid Rientjes static inline bool get_pageblock_skip(struct page *page)
8721dc7e02SDavid Rientjes {
8821dc7e02SDavid Rientjes return false;
8921dc7e02SDavid Rientjes }
clear_pageblock_skip(struct page * page)9021dc7e02SDavid Rientjes static inline void clear_pageblock_skip(struct page *page)
9121dc7e02SDavid Rientjes {
9221dc7e02SDavid Rientjes }
set_pageblock_skip(struct page * page)9321dc7e02SDavid Rientjes static inline void set_pageblock_skip(struct page *page)
9421dc7e02SDavid Rientjes {
9521dc7e02SDavid Rientjes }
96bb13ffebSMel Gorman #endif /* CONFIG_COMPACTION */
97bb13ffebSMel Gorman
98835c134eSMel Gorman #endif /* PAGEBLOCK_FLAGS_H */
99