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