blob: 1e894d34bdceb2a91318bd1ea7796a17deeddf8b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Vladimir Davydov33c3fc72015-09-09 15:35:45 -07002#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_IDLE_PAGE_TRACKING
10
11#ifdef CONFIG_64BIT
12static inline bool page_is_young(struct page *page)
13{
14 return PageYoung(page);
15}
16
17static inline void set_page_young(struct page *page)
18{
19 SetPageYoung(page);
20}
21
22static inline bool test_and_clear_page_young(struct page *page)
23{
24 return TestClearPageYoung(page);
25}
26
27static inline bool page_is_idle(struct page *page)
28{
29 return PageIdle(page);
30}
31
32static inline void set_page_idle(struct page *page)
33{
34 SetPageIdle(page);
35}
36
37static inline void clear_page_idle(struct page *page)
38{
39 ClearPageIdle(page);
40}
41#else /* !CONFIG_64BIT */
42/*
43 * If there is not enough space to store Idle and Young bits in page flags, use
44 * page ext flags instead.
45 */
46extern struct page_ext_operations page_idle_ops;
47
48static inline bool page_is_young(struct page *page)
49{
Yang Shif86e4272016-06-03 14:55:38 -070050 struct page_ext *page_ext = lookup_page_ext(page);
51
52 if (unlikely(!page_ext))
53 return false;
54
55 return test_bit(PAGE_EXT_YOUNG, &page_ext->flags);
Vladimir Davydov33c3fc72015-09-09 15:35:45 -070056}
57
58static inline void set_page_young(struct page *page)
59{
Yang Shif86e4272016-06-03 14:55:38 -070060 struct page_ext *page_ext = lookup_page_ext(page);
61
62 if (unlikely(!page_ext))
63 return;
64
65 set_bit(PAGE_EXT_YOUNG, &page_ext->flags);
Vladimir Davydov33c3fc72015-09-09 15:35:45 -070066}
67
68static inline bool test_and_clear_page_young(struct page *page)
69{
Yang Shif86e4272016-06-03 14:55:38 -070070 struct page_ext *page_ext = lookup_page_ext(page);
71
72 if (unlikely(!page_ext))
73 return false;
74
75 return test_and_clear_bit(PAGE_EXT_YOUNG, &page_ext->flags);
Vladimir Davydov33c3fc72015-09-09 15:35:45 -070076}
77
78static inline bool page_is_idle(struct page *page)
79{
Yang Shif86e4272016-06-03 14:55:38 -070080 struct page_ext *page_ext = lookup_page_ext(page);
81
82 if (unlikely(!page_ext))
83 return false;
84
85 return test_bit(PAGE_EXT_IDLE, &page_ext->flags);
Vladimir Davydov33c3fc72015-09-09 15:35:45 -070086}
87
88static inline void set_page_idle(struct page *page)
89{
Yang Shif86e4272016-06-03 14:55:38 -070090 struct page_ext *page_ext = lookup_page_ext(page);
91
92 if (unlikely(!page_ext))
93 return;
94
95 set_bit(PAGE_EXT_IDLE, &page_ext->flags);
Vladimir Davydov33c3fc72015-09-09 15:35:45 -070096}
97
98static inline void clear_page_idle(struct page *page)
99{
Yang Shif86e4272016-06-03 14:55:38 -0700100 struct page_ext *page_ext = lookup_page_ext(page);
101
102 if (unlikely(!page_ext))
103 return;
104
105 clear_bit(PAGE_EXT_IDLE, &page_ext->flags);
Vladimir Davydov33c3fc72015-09-09 15:35:45 -0700106}
107#endif /* CONFIG_64BIT */
108
109#else /* !CONFIG_IDLE_PAGE_TRACKING */
110
111static inline bool page_is_young(struct page *page)
112{
113 return false;
114}
115
116static inline void set_page_young(struct page *page)
117{
118}
119
120static inline bool test_and_clear_page_young(struct page *page)
121{
122 return false;
123}
124
125static inline bool page_is_idle(struct page *page)
126{
127 return false;
128}
129
130static inline void set_page_idle(struct page *page)
131{
132}
133
134static inline void clear_page_idle(struct page *page)
135{
136}
137
138#endif /* CONFIG_IDLE_PAGE_TRACKING */
139
140#endif /* _LINUX_MM_PAGE_IDLE_H */