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 enum migrate_reason {
23 MR_COMPACTION,
24 MR_MEMORY_FAILURE,
25 MR_MEMORY_HOTPLUG,
26 MR_SYSCALL, /* also applies to cpusets */
27 MR_MEMPOLICY_MBIND,
28 MR_NUMA_MISPLACED,
29 MR_CONTIG_RANGE,
30 MR_TYPES
31 };
32
33 /* In mm/debug.c; also keep sync with include/trace/events/migrate.h */
34 extern const char *migrate_reason_names[MR_TYPES];
35
36 #ifdef CONFIG_MIGRATION
37
38 extern void putback_movable_pages(struct list_head *l);
39 extern int migrate_page_extra(struct address_space *mapping,
40 struct page *newpage, struct page *page,
41 enum migrate_mode mode, int extra_count);
42 extern int migrate_page(struct address_space *mapping,
43 struct page *newpage, struct page *page,
44 enum migrate_mode mode);
45 extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free,
46 unsigned long private, enum migrate_mode mode, int reason);
47 extern struct page *alloc_migration_target(struct page *page, unsigned long private);
48 extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
49 extern void putback_movable_page(struct page *page);
50
51 extern int migrate_prep(void);
52 extern int migrate_prep_local(void);
53 extern void migrate_page_states(struct page *newpage, struct page *page);
54 extern void migrate_page_copy(struct page *newpage, struct page *page);
55 extern int migrate_huge_page_move_mapping(struct address_space *mapping,
56 struct page *newpage, struct page *page);
57 extern int migrate_page_move_mapping(struct address_space *mapping,
58 struct page *newpage, struct page *page, int extra_count);
59 #else
60
putback_movable_pages(struct list_head * l)61 static inline void putback_movable_pages(struct list_head *l) {}
migrate_pages(struct list_head * l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason)62 static inline int migrate_pages(struct list_head *l, new_page_t new,
63 free_page_t free, unsigned long private, enum migrate_mode mode,
64 int reason)
65 { return -ENOSYS; }
alloc_migration_target(struct page * page,unsigned long private)66 static inline struct page *alloc_migration_target(struct page *page,
67 unsigned long private)
68 { return NULL; }
isolate_movable_page(struct page * page,isolate_mode_t mode)69 static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
70 { return -EBUSY; }
71
migrate_prep(void)72 static inline int migrate_prep(void) { return -ENOSYS; }
migrate_prep_local(void)73 static inline int migrate_prep_local(void) { return -ENOSYS; }
74
migrate_page_states(struct page * newpage,struct page * page)75 static inline void migrate_page_states(struct page *newpage, struct page *page)
76 {
77 }
78
migrate_page_copy(struct page * newpage,struct page * page)79 static inline void migrate_page_copy(struct page *newpage,
80 struct page *page) {}
81
migrate_huge_page_move_mapping(struct address_space * mapping,struct page * newpage,struct page * page)82 static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
83 struct page *newpage, struct page *page)
84 {
85 return -ENOSYS;
86 }
87
88 #endif /* CONFIG_MIGRATION */
89
90 #ifdef CONFIG_COMPACTION
91 extern int PageMovable(struct page *page);
92 extern void __SetPageMovable(struct page *page, struct address_space *mapping);
93 extern void __ClearPageMovable(struct page *page);
94 #else
PageMovable(struct page * page)95 static inline int PageMovable(struct page *page) { return 0; };
__SetPageMovable(struct page * page,struct address_space * mapping)96 static inline void __SetPageMovable(struct page *page,
97 struct address_space *mapping)
98 {
99 }
__ClearPageMovable(struct page * page)100 static inline void __ClearPageMovable(struct page *page)
101 {
102 }
103 #endif
104
105 #ifdef CONFIG_NUMA_BALANCING
106 extern bool pmd_trans_migrating(pmd_t pmd);
107 extern int migrate_misplaced_page(struct page *page,
108 struct vm_area_struct *vma, int node);
109 #else
pmd_trans_migrating(pmd_t pmd)110 static inline bool pmd_trans_migrating(pmd_t pmd)
111 {
112 return false;
113 }
migrate_misplaced_page(struct page * page,struct vm_area_struct * vma,int node)114 static inline int migrate_misplaced_page(struct page *page,
115 struct vm_area_struct *vma, int node)
116 {
117 return -EAGAIN; /* can't migrate now */
118 }
119 #endif /* CONFIG_NUMA_BALANCING */
120
121 #if defined(CONFIG_NUMA_BALANCING) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
122 extern int migrate_misplaced_transhuge_page(struct mm_struct *mm,
123 struct vm_area_struct *vma,
124 pmd_t *pmd, pmd_t entry,
125 unsigned long address,
126 struct page *page, int node);
127 #else
migrate_misplaced_transhuge_page(struct mm_struct * mm,struct vm_area_struct * vma,pmd_t * pmd,pmd_t entry,unsigned long address,struct page * page,int node)128 static inline int migrate_misplaced_transhuge_page(struct mm_struct *mm,
129 struct vm_area_struct *vma,
130 pmd_t *pmd, pmd_t entry,
131 unsigned long address,
132 struct page *page, int node)
133 {
134 return -EAGAIN;
135 }
136 #endif /* CONFIG_NUMA_BALANCING && CONFIG_TRANSPARENT_HUGEPAGE*/
137
138
139 #ifdef CONFIG_MIGRATION
140
141 /*
142 * Watch out for PAE architecture, which has an unsigned long, and might not
143 * have enough bits to store all physical address and flags. So far we have
144 * enough room for all our flags.
145 */
146 #define MIGRATE_PFN_VALID (1UL << 0)
147 #define MIGRATE_PFN_MIGRATE (1UL << 1)
148 #define MIGRATE_PFN_LOCKED (1UL << 2)
149 #define MIGRATE_PFN_WRITE (1UL << 3)
150 #define MIGRATE_PFN_SHIFT 6
151
migrate_pfn_to_page(unsigned long mpfn)152 static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
153 {
154 if (!(mpfn & MIGRATE_PFN_VALID))
155 return NULL;
156 return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
157 }
158
migrate_pfn(unsigned long pfn)159 static inline unsigned long migrate_pfn(unsigned long pfn)
160 {
161 return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
162 }
163
164 enum migrate_vma_direction {
165 MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
166 MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
167 };
168
169 struct migrate_vma {
170 struct vm_area_struct *vma;
171 /*
172 * Both src and dst array must be big enough for
173 * (end - start) >> PAGE_SHIFT entries.
174 *
175 * The src array must not be modified by the caller after
176 * migrate_vma_setup(), and must not change the dst array after
177 * migrate_vma_pages() returns.
178 */
179 unsigned long *dst;
180 unsigned long *src;
181 unsigned long cpages;
182 unsigned long npages;
183 unsigned long start;
184 unsigned long end;
185
186 /*
187 * Set to the owner value also stored in page->pgmap->owner for
188 * migrating out of device private memory. The flags also need to
189 * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
190 * The caller should always set this field when using mmu notifier
191 * callbacks to avoid device MMU invalidations for device private
192 * pages that are not being migrated.
193 */
194 void *pgmap_owner;
195 unsigned long flags;
196
197 /*
198 * Set to vmf->page if this is being called to migrate a page as part of
199 * a migrate_to_ram() callback.
200 */
201 struct page *fault_page;
202 };
203
204 int migrate_vma_setup(struct migrate_vma *args);
205 void migrate_vma_pages(struct migrate_vma *migrate);
206 void migrate_vma_finalize(struct migrate_vma *migrate);
207
208 #endif /* CONFIG_MIGRATION */
209
210 #endif /* _LINUX_MIGRATE_H */
211