• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_PAGE_EXT_H
3 #define __LINUX_PAGE_EXT_H
4 
5 #include <linux/types.h>
6 #include <linux/stacktrace.h>
7 #include <linux/stackdepot.h>
8 
9 struct pglist_data;
10 struct page_ext_operations {
11 	size_t offset;
12 	size_t size;
13 	bool (*need)(void);
14 	void (*init)(void);
15 };
16 
17 #ifdef CONFIG_PAGE_EXTENSION
18 
19 enum page_ext_flags {
20 	PAGE_EXT_OWNER,
21 	PAGE_EXT_OWNER_ALLOCATED,
22 #if defined(CONFIG_PAGE_PINNER)
23 	/* page refcount was increased by GUP or follow_page(FOLL_GET) */
24 	PAGE_EXT_GET,
25 	/* page migration failed */
26 	PAGE_EXT_PINNER_MIGRATION_FAILED,
27 #endif
28 #if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT)
29 	PAGE_EXT_YOUNG,
30 	PAGE_EXT_IDLE,
31 #endif
32 };
33 
34 /*
35  * Page Extension can be considered as an extended mem_map.
36  * A page_ext page is associated with every page descriptor. The
37  * page_ext helps us add more information about the page.
38  * All page_ext are allocated at boot or memory hotplug event,
39  * then the page_ext for pfn always exists.
40  */
41 struct page_ext {
42 	unsigned long flags;
43 };
44 
45 extern unsigned long page_ext_size;
46 extern void pgdat_page_ext_init(struct pglist_data *pgdat);
47 
48 #ifdef CONFIG_SPARSEMEM
page_ext_init_flatmem(void)49 static inline void page_ext_init_flatmem(void)
50 {
51 }
52 extern void page_ext_init(void);
53 #else
54 extern void page_ext_init_flatmem(void);
page_ext_init(void)55 static inline void page_ext_init(void)
56 {
57 }
58 #endif
59 struct page_ext *lookup_page_ext(const struct page *page);
60 extern struct page_ext *page_ext_get(struct page *page);
61 extern void page_ext_put(struct page_ext *page_ext);
62 
page_ext_next(struct page_ext * curr)63 static inline struct page_ext *page_ext_next(struct page_ext *curr)
64 {
65 	void *next = curr;
66 	next += page_ext_size;
67 	return next;
68 }
69 
70 #else /* !CONFIG_PAGE_EXTENSION */
71 struct page_ext;
72 
pgdat_page_ext_init(struct pglist_data * pgdat)73 static inline void pgdat_page_ext_init(struct pglist_data *pgdat)
74 {
75 }
76 
page_ext_init(void)77 static inline void page_ext_init(void)
78 {
79 }
80 
page_ext_init_flatmem(void)81 static inline void page_ext_init_flatmem(void)
82 {
83 }
84 
page_ext_get(struct page * page)85 static inline struct page_ext *page_ext_get(struct page *page)
86 {
87 	return NULL;
88 }
89 
page_ext_put(struct page_ext * page_ext)90 static inline void page_ext_put(struct page_ext *page_ext)
91 {
92 }
93 #endif /* CONFIG_PAGE_EXTENSION */
94 #endif /* __LINUX_PAGE_EXT_H */
95