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