xref: /linux-6.15/include/linux/migrate.h (revision 50f9481e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MIGRATE_H
3 #define _LINUX_MIGRATE_H
4 
5 #include <linux/mm.h>
6 #include <linux/mempolicy.h>
7 #include <linux/migrate_mode.h>
8 #include <linux/hugetlb.h>
9 
10 typedef struct page *new_page_t(struct page *page, unsigned long private);
11 typedef void free_page_t(struct page *page, unsigned long private);
12 
13 struct migration_target_control;
14 
15 /*
16  * Return values from addresss_space_operations.migratepage():
17  * - negative errno on page migration failure;
18  * - zero on page migration success;
19  */
20 #define MIGRATEPAGE_SUCCESS		0
21 
22 /* Defined in mm/debug.c: */
23 extern const char *migrate_reason_names[MR_TYPES];
24 
25 #ifdef CONFIG_MIGRATION
26 
27 extern void putback_movable_pages(struct list_head *l);
28 extern int migrate_page(struct address_space *mapping,
29 			struct page *newpage, struct page *page,
30 			enum migrate_mode mode);
31 extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free,
32 		unsigned long private, enum migrate_mode mode, int reason,
33 		unsigned int *ret_succeeded);
34 extern struct page *alloc_migration_target(struct page *page, unsigned long private);
35 extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
36 
37 extern void migrate_page_states(struct page *newpage, struct page *page);
38 extern void migrate_page_copy(struct page *newpage, struct page *page);
39 extern int migrate_huge_page_move_mapping(struct address_space *mapping,
40 				  struct page *newpage, struct page *page);
41 extern int migrate_page_move_mapping(struct address_space *mapping,
42 		struct page *newpage, struct page *page, int extra_count);
43 
44 extern bool numa_demotion_enabled;
45 #else
46 
47 static inline void putback_movable_pages(struct list_head *l) {}
48 static inline int migrate_pages(struct list_head *l, new_page_t new,
49 		free_page_t free, unsigned long private, enum migrate_mode mode,
50 		int reason, unsigned int *ret_succeeded)
51 	{ return -ENOSYS; }
52 static inline struct page *alloc_migration_target(struct page *page,
53 		unsigned long private)
54 	{ return NULL; }
55 static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
56 	{ return -EBUSY; }
57 
58 static inline void migrate_page_states(struct page *newpage, struct page *page)
59 {
60 }
61 
62 static inline void migrate_page_copy(struct page *newpage,
63 				     struct page *page) {}
64 
65 static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
66 				  struct page *newpage, struct page *page)
67 {
68 	return -ENOSYS;
69 }
70 
71 #define numa_demotion_enabled	false
72 #endif /* CONFIG_MIGRATION */
73 
74 #ifdef CONFIG_COMPACTION
75 extern int PageMovable(struct page *page);
76 extern void __SetPageMovable(struct page *page, struct address_space *mapping);
77 extern void __ClearPageMovable(struct page *page);
78 #else
79 static inline int PageMovable(struct page *page) { return 0; }
80 static inline void __SetPageMovable(struct page *page,
81 				struct address_space *mapping)
82 {
83 }
84 static inline void __ClearPageMovable(struct page *page)
85 {
86 }
87 #endif
88 
89 #ifdef CONFIG_NUMA_BALANCING
90 extern int migrate_misplaced_page(struct page *page,
91 				  struct vm_area_struct *vma, int node);
92 #else
93 static inline int migrate_misplaced_page(struct page *page,
94 					 struct vm_area_struct *vma, int node)
95 {
96 	return -EAGAIN; /* can't migrate now */
97 }
98 #endif /* CONFIG_NUMA_BALANCING */
99 
100 #ifdef CONFIG_MIGRATION
101 
102 /*
103  * Watch out for PAE architecture, which has an unsigned long, and might not
104  * have enough bits to store all physical address and flags. So far we have
105  * enough room for all our flags.
106  */
107 #define MIGRATE_PFN_VALID	(1UL << 0)
108 #define MIGRATE_PFN_MIGRATE	(1UL << 1)
109 #define MIGRATE_PFN_LOCKED	(1UL << 2)
110 #define MIGRATE_PFN_WRITE	(1UL << 3)
111 #define MIGRATE_PFN_SHIFT	6
112 
113 static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
114 {
115 	if (!(mpfn & MIGRATE_PFN_VALID))
116 		return NULL;
117 	return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
118 }
119 
120 static inline unsigned long migrate_pfn(unsigned long pfn)
121 {
122 	return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
123 }
124 
125 enum migrate_vma_direction {
126 	MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
127 	MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
128 };
129 
130 struct migrate_vma {
131 	struct vm_area_struct	*vma;
132 	/*
133 	 * Both src and dst array must be big enough for
134 	 * (end - start) >> PAGE_SHIFT entries.
135 	 *
136 	 * The src array must not be modified by the caller after
137 	 * migrate_vma_setup(), and must not change the dst array after
138 	 * migrate_vma_pages() returns.
139 	 */
140 	unsigned long		*dst;
141 	unsigned long		*src;
142 	unsigned long		cpages;
143 	unsigned long		npages;
144 	unsigned long		start;
145 	unsigned long		end;
146 
147 	/*
148 	 * Set to the owner value also stored in page->pgmap->owner for
149 	 * migrating out of device private memory. The flags also need to
150 	 * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
151 	 * The caller should always set this field when using mmu notifier
152 	 * callbacks to avoid device MMU invalidations for device private
153 	 * pages that are not being migrated.
154 	 */
155 	void			*pgmap_owner;
156 	unsigned long		flags;
157 };
158 
159 int migrate_vma_setup(struct migrate_vma *args);
160 void migrate_vma_pages(struct migrate_vma *migrate);
161 void migrate_vma_finalize(struct migrate_vma *migrate);
162 int next_demotion_node(int node);
163 
164 #else /* CONFIG_MIGRATION disabled: */
165 
166 static inline int next_demotion_node(int node)
167 {
168 	return NUMA_NO_NODE;
169 }
170 
171 #endif /* CONFIG_MIGRATION */
172 
173 #endif /* _LINUX_MIGRATE_H */
174