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 page_is_young(struct page * page)12static inline bool page_is_young(struct page *page) 13 { 14 return PageYoung(page); 15 } 16 set_page_young(struct page * page)17static inline void set_page_young(struct page *page) 18 { 19 SetPageYoung(page); 20 } 21 test_and_clear_page_young(struct page * page)22static inline bool test_and_clear_page_young(struct page *page) 23 { 24 return TestClearPageYoung(page); 25 } 26 page_is_idle(struct page * page)27static inline bool page_is_idle(struct page *page) 28 { 29 return PageIdle(page); 30 } 31 set_page_idle(struct page * page)32static inline void set_page_idle(struct page *page) 33 { 34 SetPageIdle(page); 35 } 36 clear_page_idle(struct page * page)37static 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 page_is_young(struct page * page)48static inline bool page_is_young(struct page *page) 49 { 50 struct page_ext *page_ext = page_ext_get(page); 51 bool page_young; 52 53 if (unlikely(!page_ext)) 54 return false; 55 56 page_young = test_bit(PAGE_EXT_YOUNG, &page_ext->flags); 57 page_ext_put(page_ext); 58 59 return page_young; 60 } 61 set_page_young(struct page * page)62static inline void set_page_young(struct page *page) 63 { 64 struct page_ext *page_ext = page_ext_get(page); 65 66 if (unlikely(!page_ext)) 67 return; 68 69 set_bit(PAGE_EXT_YOUNG, &page_ext->flags); 70 page_ext_put(page_ext); 71 } 72 test_and_clear_page_young(struct page * page)73static inline bool test_and_clear_page_young(struct page *page) 74 { 75 struct page_ext *page_ext = page_ext_get(page); 76 bool page_young; 77 78 if (unlikely(!page_ext)) 79 return false; 80 81 page_young = test_and_clear_bit(PAGE_EXT_YOUNG, &page_ext->flags); 82 page_ext_put(page_ext); 83 84 return page_young; 85 } 86 page_is_idle(struct page * page)87static inline bool page_is_idle(struct page *page) 88 { 89 struct page_ext *page_ext = page_ext_get(page); 90 bool page_idle; 91 92 if (unlikely(!page_ext)) 93 return false; 94 95 page_idle = test_bit(PAGE_EXT_IDLE, &page_ext->flags); 96 page_ext_put(page_ext); 97 98 return page_idle; 99 } 100 set_page_idle(struct page * page)101static inline void set_page_idle(struct page *page) 102 { 103 struct page_ext *page_ext = page_ext_get(page); 104 105 if (unlikely(!page_ext)) 106 return; 107 108 set_bit(PAGE_EXT_IDLE, &page_ext->flags); 109 page_ext_put(page_ext); 110 } 111 clear_page_idle(struct page * page)112static inline void clear_page_idle(struct page *page) 113 { 114 struct page_ext *page_ext = page_ext_get(page); 115 116 if (unlikely(!page_ext)) 117 return; 118 119 clear_bit(PAGE_EXT_IDLE, &page_ext->flags); 120 page_ext_put(page_ext); 121 } 122 #endif /* CONFIG_64BIT */ 123 124 #else /* !CONFIG_PAGE_IDLE_FLAG */ 125 page_is_young(struct page * page)126static inline bool page_is_young(struct page *page) 127 { 128 return false; 129 } 130 set_page_young(struct page * page)131static inline void set_page_young(struct page *page) 132 { 133 } 134 test_and_clear_page_young(struct page * page)135static inline bool test_and_clear_page_young(struct page *page) 136 { 137 return false; 138 } 139 page_is_idle(struct page * page)140static inline bool page_is_idle(struct page *page) 141 { 142 return false; 143 } 144 set_page_idle(struct page * page)145static inline void set_page_idle(struct page *page) 146 { 147 } 148 clear_page_idle(struct page * page)149static inline void clear_page_idle(struct page *page) 150 { 151 } 152 153 #endif /* CONFIG_PAGE_IDLE_FLAG */ 154 155 #endif /* _LINUX_MM_PAGE_IDLE_H */ 156