1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MM_PAGE_IDLE_H
3 #define _LINUX_MM_PAGE_IDLE_H
5 #include <linux/bitops.h>
6 #include <linux/page-flags.h>
7 #include <linux/page_ext.h>
9 #ifdef CONFIG_PAGE_IDLE_FLAG
13 * If there is not enough space to store Idle and Young bits in page flags, use
14 * page ext flags instead.
16 static inline bool folio_test_young(struct folio *folio)
18 struct page_ext *page_ext = page_ext_get(&folio->page);
21 if (unlikely(!page_ext))
24 page_young = test_bit(PAGE_EXT_YOUNG, &page_ext->flags);
25 page_ext_put(page_ext);
30 static inline void folio_set_young(struct folio *folio)
32 struct page_ext *page_ext = page_ext_get(&folio->page);
34 if (unlikely(!page_ext))
37 set_bit(PAGE_EXT_YOUNG, &page_ext->flags);
38 page_ext_put(page_ext);
41 static inline bool folio_test_clear_young(struct folio *folio)
43 struct page_ext *page_ext = page_ext_get(&folio->page);
46 if (unlikely(!page_ext))
49 page_young = test_and_clear_bit(PAGE_EXT_YOUNG, &page_ext->flags);
50 page_ext_put(page_ext);
55 static inline bool folio_test_idle(struct folio *folio)
57 struct page_ext *page_ext = page_ext_get(&folio->page);
60 if (unlikely(!page_ext))
63 page_idle = test_bit(PAGE_EXT_IDLE, &page_ext->flags);
64 page_ext_put(page_ext);
69 static inline void folio_set_idle(struct folio *folio)
71 struct page_ext *page_ext = page_ext_get(&folio->page);
73 if (unlikely(!page_ext))
76 set_bit(PAGE_EXT_IDLE, &page_ext->flags);
77 page_ext_put(page_ext);
80 static inline void folio_clear_idle(struct folio *folio)
82 struct page_ext *page_ext = page_ext_get(&folio->page);
84 if (unlikely(!page_ext))
87 clear_bit(PAGE_EXT_IDLE, &page_ext->flags);
88 page_ext_put(page_ext);
90 #endif /* !CONFIG_64BIT */
92 #else /* !CONFIG_PAGE_IDLE_FLAG */
94 static inline bool folio_test_young(struct folio *folio)
99 static inline void folio_set_young(struct folio *folio)
103 static inline bool folio_test_clear_young(struct folio *folio)
108 static inline bool folio_test_idle(struct folio *folio)
113 static inline void folio_set_idle(struct folio *folio)
117 static inline void folio_clear_idle(struct folio *folio)
121 #endif /* CONFIG_PAGE_IDLE_FLAG */
123 static inline bool page_is_young(struct page *page)
125 return folio_test_young(page_folio(page));
128 static inline void set_page_young(struct page *page)
130 folio_set_young(page_folio(page));
133 static inline bool test_and_clear_page_young(struct page *page)
135 return folio_test_clear_young(page_folio(page));
138 static inline bool page_is_idle(struct page *page)
140 return folio_test_idle(page_folio(page));
143 static inline void set_page_idle(struct page *page)
145 folio_set_idle(page_folio(page));
147 #endif /* _LINUX_MM_PAGE_IDLE_H */