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 | ||
8c9e8381 | 9 | #if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT) |
33c3fc71 VD |
10 | /* |
11 | * If there is not enough space to store Idle and Young bits in page flags, use | |
12 | * page ext flags instead. | |
13 | */ | |
e3089fd0 | 14 | static inline bool folio_test_young(const struct folio *folio) |
33c3fc71 | 15 | { |
b1d5488a CTK |
16 | struct page_ext *page_ext = page_ext_get(&folio->page); |
17 | bool page_young; | |
f86e4271 YS |
18 | |
19 | if (unlikely(!page_ext)) | |
20 | return false; | |
21 | ||
b1d5488a CTK |
22 | page_young = test_bit(PAGE_EXT_YOUNG, &page_ext->flags); |
23 | page_ext_put(page_ext); | |
24 | ||
25 | return page_young; | |
33c3fc71 VD |
26 | } |
27 | ||
35a020ba | 28 | static inline void folio_set_young(struct folio *folio) |
33c3fc71 | 29 | { |
b1d5488a | 30 | struct page_ext *page_ext = page_ext_get(&folio->page); |
f86e4271 YS |
31 | |
32 | if (unlikely(!page_ext)) | |
33 | return; | |
34 | ||
35 | set_bit(PAGE_EXT_YOUNG, &page_ext->flags); | |
b1d5488a | 36 | page_ext_put(page_ext); |
33c3fc71 VD |
37 | } |
38 | ||
35a020ba | 39 | static inline bool folio_test_clear_young(struct folio *folio) |
33c3fc71 | 40 | { |
b1d5488a CTK |
41 | struct page_ext *page_ext = page_ext_get(&folio->page); |
42 | bool page_young; | |
f86e4271 YS |
43 | |
44 | if (unlikely(!page_ext)) | |
45 | return false; | |
46 | ||
b1d5488a CTK |
47 | page_young = test_and_clear_bit(PAGE_EXT_YOUNG, &page_ext->flags); |
48 | page_ext_put(page_ext); | |
49 | ||
50 | return page_young; | |
33c3fc71 VD |
51 | } |
52 | ||
e3089fd0 | 53 | static inline bool folio_test_idle(const struct folio *folio) |
33c3fc71 | 54 | { |
b1d5488a CTK |
55 | struct page_ext *page_ext = page_ext_get(&folio->page); |
56 | bool page_idle; | |
f86e4271 YS |
57 | |
58 | if (unlikely(!page_ext)) | |
59 | return false; | |
60 | ||
e3089fd0 | 61 | page_idle = test_bit(PAGE_EXT_IDLE, &page_ext->flags); |
b1d5488a CTK |
62 | page_ext_put(page_ext); |
63 | ||
64 | return page_idle; | |
33c3fc71 VD |
65 | } |
66 | ||
35a020ba | 67 | static inline void folio_set_idle(struct folio *folio) |
33c3fc71 | 68 | { |
b1d5488a | 69 | struct page_ext *page_ext = page_ext_get(&folio->page); |
f86e4271 YS |
70 | |
71 | if (unlikely(!page_ext)) | |
72 | return; | |
73 | ||
74 | set_bit(PAGE_EXT_IDLE, &page_ext->flags); | |
b1d5488a | 75 | page_ext_put(page_ext); |
33c3fc71 VD |
76 | } |
77 | ||
35a020ba | 78 | static inline void folio_clear_idle(struct folio *folio) |
33c3fc71 | 79 | { |
b1d5488a | 80 | struct page_ext *page_ext = page_ext_get(&folio->page); |
f86e4271 YS |
81 | |
82 | if (unlikely(!page_ext)) | |
83 | return; | |
84 | ||
85 | clear_bit(PAGE_EXT_IDLE, &page_ext->flags); | |
b1d5488a | 86 | page_ext_put(page_ext); |
33c3fc71 | 87 | } |
8c9e8381 | 88 | #endif /* CONFIG_PAGE_IDLE_FLAG && !64BIT */ |
33c3fc71 | 89 | #endif /* _LINUX_MM_PAGE_IDLE_H */ |