1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_MM_PAGE_IDLE_H 3 #define _LINUX_MM_PAGE_IDLE_H 4 5 #include <linux/bitops.h> 6 #include <linux/page-flags.h> 7 #include <linux/page_ext.h> 8 9 #ifdef CONFIG_PAGE_IDLE_FLAG 10 11 #ifdef CONFIG_64BIT 12 static inline bool page_is_young(struct page *page) 13 { 14 return PageYoung(page); 15 } 16 17 static inline void set_page_young(struct page *page) 18 { 19 SetPageYoung(page); 20 } 21 22 static inline bool test_and_clear_page_young(struct page *page) 23 { 24 return TestClearPageYoung(page); 25 } 26 27 static inline bool page_is_idle(struct page *page) 28 { 29 return PageIdle(page); 30 } 31 32 static inline void set_page_idle(struct page *page) 33 { 34 SetPageIdle(page); 35 } 36 37 static inline void clear_page_idle(struct page *page) 38 { 39 ClearPageIdle(page); 40 } 41 #else /* !CONFIG_64BIT */ 42 /* 43 * If there is not enough space to store Idle and Young bits in page flags, use 44 * page ext flags instead. 45 */ 46 extern struct page_ext_operations page_idle_ops; 47 48 static inline bool page_is_young(struct page *page) 49 { 50 struct page_ext *page_ext = lookup_page_ext(page); 51 52 if (unlikely(!page_ext)) 53 return false; 54 55 return test_bit(PAGE_EXT_YOUNG, &page_ext->flags); 56 } 57 58 static inline void set_page_young(struct page *page) 59 { 60 struct page_ext *page_ext = lookup_page_ext(page); 61 62 if (unlikely(!page_ext)) 63 return; 64 65 set_bit(PAGE_EXT_YOUNG, &page_ext->flags); 66 } 67 68 static inline bool test_and_clear_page_young(struct page *page) 69 { 70 struct page_ext *page_ext = lookup_page_ext(page); 71 72 if (unlikely(!page_ext)) 73 return false; 74 75 return test_and_clear_bit(PAGE_EXT_YOUNG, &page_ext->flags); 76 } 77 78 static inline bool page_is_idle(struct page *page) 79 { 80 struct page_ext *page_ext = lookup_page_ext(page); 81 82 if (unlikely(!page_ext)) 83 return false; 84 85 return test_bit(PAGE_EXT_IDLE, &page_ext->flags); 86 } 87 88 static inline void set_page_idle(struct page *page) 89 { 90 struct page_ext *page_ext = lookup_page_ext(page); 91 92 if (unlikely(!page_ext)) 93 return; 94 95 set_bit(PAGE_EXT_IDLE, &page_ext->flags); 96 } 97 98 static inline void clear_page_idle(struct page *page) 99 { 100 struct page_ext *page_ext = lookup_page_ext(page); 101 102 if (unlikely(!page_ext)) 103 return; 104 105 clear_bit(PAGE_EXT_IDLE, &page_ext->flags); 106 } 107 #endif /* CONFIG_64BIT */ 108 109 #else /* !CONFIG_PAGE_IDLE_FLAG */ 110 111 static inline bool page_is_young(struct page *page) 112 { 113 return false; 114 } 115 116 static inline void set_page_young(struct page *page) 117 { 118 } 119 120 static inline bool test_and_clear_page_young(struct page *page) 121 { 122 return false; 123 } 124 125 static inline bool page_is_idle(struct page *page) 126 { 127 return false; 128 } 129 130 static inline void set_page_idle(struct page *page) 131 { 132 } 133 134 static inline void clear_page_idle(struct page *page) 135 { 136 } 137 138 #endif /* CONFIG_PAGE_IDLE_FLAG */ 139 140 #endif /* _LINUX_MM_PAGE_IDLE_H */ 141