]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
b20a3503 CL |
2 | #ifndef _LINUX_MIGRATE_H |
3 | #define _LINUX_MIGRATE_H | |
4 | ||
b20a3503 | 5 | #include <linux/mm.h> |
906e0be1 | 6 | #include <linux/mempolicy.h> |
6536e312 | 7 | #include <linux/migrate_mode.h> |
8b913238 | 8 | #include <linux/hugetlb.h> |
b20a3503 | 9 | |
666feb21 | 10 | typedef struct page *new_page_t(struct page *page, unsigned long private); |
68711a74 | 11 | typedef void free_page_t(struct page *page, unsigned long private); |
95a402c3 | 12 | |
19fc7bed JK |
13 | struct migration_target_control; |
14 | ||
78bd5209 RA |
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 | |
d6d86c0a | 21 | |
7b2a2d4a MG |
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, | |
7039e1db | 28 | MR_NUMA_MISPLACED, |
31025351 | 29 | MR_CONTIG_RANGE, |
d1e153fe | 30 | MR_LONGTERM_PIN, |
7cd12b4a | 31 | MR_TYPES |
7b2a2d4a | 32 | }; |
78bd5209 | 33 | |
7cd12b4a | 34 | /* In mm/debug.c; also keep sync with include/trace/events/migrate.h */ |
9a2f45ff | 35 | extern const char *migrate_reason_names[MR_TYPES]; |
7cd12b4a | 36 | |
906e0be1 | 37 | #ifdef CONFIG_MIGRATION |
64cdd548 | 38 | |
5733c7d1 | 39 | extern void putback_movable_pages(struct list_head *l); |
9927e388 PJ |
40 | extern int migrate_page(struct address_space *mapping, |
41 | struct page *newpage, struct page *page, | |
42 | enum migrate_mode mode); | |
68711a74 | 43 | extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free, |
9c620e2b | 44 | unsigned long private, enum migrate_mode mode, int reason); |
19fc7bed | 45 | extern struct page *alloc_migration_target(struct page *page, unsigned long private); |
9e5bcd61 | 46 | extern int isolate_movable_page(struct page *page, isolate_mode_t mode); |
95a402c3 | 47 | |
2916ecc0 | 48 | extern void migrate_page_states(struct page *newpage, struct page *page); |
290408d4 NH |
49 | extern void migrate_page_copy(struct page *newpage, struct page *page); |
50 | extern int migrate_huge_page_move_mapping(struct address_space *mapping, | |
51 | struct page *newpage, struct page *page); | |
36bc08cc | 52 | extern int migrate_page_move_mapping(struct address_space *mapping, |
37109694 | 53 | struct page *newpage, struct page *page, int extra_count); |
b20a3503 | 54 | #else |
64cdd548 | 55 | |
5733c7d1 | 56 | static inline void putback_movable_pages(struct list_head *l) {} |
68711a74 DR |
57 | static inline int migrate_pages(struct list_head *l, new_page_t new, |
58 | free_page_t free, unsigned long private, enum migrate_mode mode, | |
59 | int reason) | |
9c620e2b | 60 | { return -ENOSYS; } |
19fc7bed JK |
61 | static inline struct page *alloc_migration_target(struct page *page, |
62 | unsigned long private) | |
b4b38223 | 63 | { return NULL; } |
cbae0170 YX |
64 | static inline int isolate_movable_page(struct page *page, isolate_mode_t mode) |
65 | { return -EBUSY; } | |
9bf9e89c | 66 | |
2916ecc0 JG |
67 | static inline void migrate_page_states(struct page *newpage, struct page *page) |
68 | { | |
69 | } | |
70 | ||
290408d4 NH |
71 | static inline void migrate_page_copy(struct page *newpage, |
72 | struct page *page) {} | |
73 | ||
6f39ce05 | 74 | static inline int migrate_huge_page_move_mapping(struct address_space *mapping, |
290408d4 NH |
75 | struct page *newpage, struct page *page) |
76 | { | |
77 | return -ENOSYS; | |
78 | } | |
79 | ||
b20a3503 | 80 | #endif /* CONFIG_MIGRATION */ |
7039e1db | 81 | |
dd4123f3 MK |
82 | #ifdef CONFIG_COMPACTION |
83 | extern int PageMovable(struct page *page); | |
84 | extern void __SetPageMovable(struct page *page, struct address_space *mapping); | |
85 | extern void __ClearPageMovable(struct page *page); | |
86 | #else | |
a553e3cd | 87 | static inline int PageMovable(struct page *page) { return 0; } |
dd4123f3 MK |
88 | static inline void __SetPageMovable(struct page *page, |
89 | struct address_space *mapping) | |
90 | { | |
91 | } | |
92 | static inline void __ClearPageMovable(struct page *page) | |
93 | { | |
94 | } | |
95 | #endif | |
96 | ||
7039e1db | 97 | #ifdef CONFIG_NUMA_BALANCING |
de466bd6 | 98 | extern bool pmd_trans_migrating(pmd_t pmd); |
1bc115d8 MG |
99 | extern int migrate_misplaced_page(struct page *page, |
100 | struct vm_area_struct *vma, int node); | |
7039e1db | 101 | #else |
de466bd6 MG |
102 | static inline bool pmd_trans_migrating(pmd_t pmd) |
103 | { | |
104 | return false; | |
105 | } | |
1bc115d8 MG |
106 | static inline int migrate_misplaced_page(struct page *page, |
107 | struct vm_area_struct *vma, int node) | |
7039e1db PZ |
108 | { |
109 | return -EAGAIN; /* can't migrate now */ | |
110 | } | |
220018d3 | 111 | #endif /* CONFIG_NUMA_BALANCING */ |
b32967ff | 112 | |
220018d3 MG |
113 | #if defined(CONFIG_NUMA_BALANCING) && defined(CONFIG_TRANSPARENT_HUGEPAGE) |
114 | extern int migrate_misplaced_transhuge_page(struct mm_struct *mm, | |
115 | struct vm_area_struct *vma, | |
116 | pmd_t *pmd, pmd_t entry, | |
117 | unsigned long address, | |
118 | struct page *page, int node); | |
119 | #else | |
b32967ff MG |
120 | static inline int migrate_misplaced_transhuge_page(struct mm_struct *mm, |
121 | struct vm_area_struct *vma, | |
122 | pmd_t *pmd, pmd_t entry, | |
123 | unsigned long address, | |
124 | struct page *page, int node) | |
125 | { | |
126 | return -EAGAIN; | |
127 | } | |
220018d3 | 128 | #endif /* CONFIG_NUMA_BALANCING && CONFIG_TRANSPARENT_HUGEPAGE*/ |
7039e1db | 129 | |
8763cb45 JG |
130 | |
131 | #ifdef CONFIG_MIGRATION | |
132 | ||
a5430dda JG |
133 | /* |
134 | * Watch out for PAE architecture, which has an unsigned long, and might not | |
135 | * have enough bits to store all physical address and flags. So far we have | |
136 | * enough room for all our flags. | |
137 | */ | |
8763cb45 JG |
138 | #define MIGRATE_PFN_VALID (1UL << 0) |
139 | #define MIGRATE_PFN_MIGRATE (1UL << 1) | |
140 | #define MIGRATE_PFN_LOCKED (1UL << 2) | |
141 | #define MIGRATE_PFN_WRITE (1UL << 3) | |
a5430dda | 142 | #define MIGRATE_PFN_SHIFT 6 |
8763cb45 JG |
143 | |
144 | static inline struct page *migrate_pfn_to_page(unsigned long mpfn) | |
145 | { | |
146 | if (!(mpfn & MIGRATE_PFN_VALID)) | |
147 | return NULL; | |
148 | return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT); | |
149 | } | |
150 | ||
151 | static inline unsigned long migrate_pfn(unsigned long pfn) | |
152 | { | |
153 | return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID; | |
154 | } | |
155 | ||
5143192c RC |
156 | enum migrate_vma_direction { |
157 | MIGRATE_VMA_SELECT_SYSTEM = 1 << 0, | |
158 | MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1, | |
159 | }; | |
160 | ||
a7d1f22b CH |
161 | struct migrate_vma { |
162 | struct vm_area_struct *vma; | |
163 | /* | |
164 | * Both src and dst array must be big enough for | |
165 | * (end - start) >> PAGE_SHIFT entries. | |
166 | * | |
167 | * The src array must not be modified by the caller after | |
168 | * migrate_vma_setup(), and must not change the dst array after | |
169 | * migrate_vma_pages() returns. | |
170 | */ | |
171 | unsigned long *dst; | |
172 | unsigned long *src; | |
173 | unsigned long cpages; | |
174 | unsigned long npages; | |
175 | unsigned long start; | |
176 | unsigned long end; | |
800bb1c8 CH |
177 | |
178 | /* | |
179 | * Set to the owner value also stored in page->pgmap->owner for | |
5143192c RC |
180 | * migrating out of device private memory. The flags also need to |
181 | * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE. | |
998427b3 RC |
182 | * The caller should always set this field when using mmu notifier |
183 | * callbacks to avoid device MMU invalidations for device private | |
184 | * pages that are not being migrated. | |
800bb1c8 | 185 | */ |
5143192c RC |
186 | void *pgmap_owner; |
187 | unsigned long flags; | |
8763cb45 JG |
188 | }; |
189 | ||
a7d1f22b CH |
190 | int migrate_vma_setup(struct migrate_vma *args); |
191 | void migrate_vma_pages(struct migrate_vma *migrate); | |
192 | void migrate_vma_finalize(struct migrate_vma *migrate); | |
8763cb45 JG |
193 | |
194 | #endif /* CONFIG_MIGRATION */ | |
195 | ||
b20a3503 | 196 | #endif /* _LINUX_MIGRATE_H */ |