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