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