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