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

source code of linux/include/linux/page_idle.h