1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MIGRATE_H
3 #define _LINUX_MIGRATE_H
6 #include <linux/mempolicy.h>
7 #include <linux/migrate_mode.h>
8 #include <linux/hugetlb.h>
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);
13 struct migration_target_control;
16 * Return values from addresss_space_operations.migratepage():
17 * - negative errno on page migration failure;
18 * - zero on page migration success;
20 #define MIGRATEPAGE_SUCCESS 0
26 MR_SYSCALL, /* also applies to cpusets */
34 /* In mm/debug.c; also keep sync with include/trace/events/migrate.h */
35 extern const char *migrate_reason_names[MR_TYPES];
37 #ifdef CONFIG_MIGRATION
39 extern void putback_movable_pages(struct list_head *l);
40 extern int migrate_page(struct address_space *mapping,
41 struct page *newpage, struct page *page,
42 enum migrate_mode mode);
43 extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free,
44 unsigned long private, enum migrate_mode mode, int reason);
45 extern struct page *alloc_migration_target(struct page *page, unsigned long private);
46 extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
48 extern void migrate_page_states(struct page *newpage, struct page *page);
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);
52 extern int migrate_page_move_mapping(struct address_space *mapping,
53 struct page *newpage, struct page *page, int extra_count);
56 static inline void putback_movable_pages(struct list_head *l) {}
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,
61 static inline struct page *alloc_migration_target(struct page *page,
62 unsigned long private)
64 static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
67 static inline void migrate_page_states(struct page *newpage, struct page *page)
71 static inline void migrate_page_copy(struct page *newpage,
74 static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
75 struct page *newpage, struct page *page)
79 #endif /* CONFIG_MIGRATION */
81 #ifdef CONFIG_COMPACTION
82 extern int PageMovable(struct page *page);
83 extern void __SetPageMovable(struct page *page, struct address_space *mapping);
84 extern void __ClearPageMovable(struct page *page);
86 static inline int PageMovable(struct page *page) { return 0; }
87 static inline void __SetPageMovable(struct page *page,
88 struct address_space *mapping)
91 static inline void __ClearPageMovable(struct page *page)
96 #ifdef CONFIG_NUMA_BALANCING
97 extern int migrate_misplaced_page(struct page *page,
98 struct vm_area_struct *vma, int node);
100 static inline int migrate_misplaced_page(struct page *page,
101 struct vm_area_struct *vma, int node)
103 return -EAGAIN; /* can't migrate now */
105 #endif /* CONFIG_NUMA_BALANCING */
107 #ifdef CONFIG_MIGRATION
110 * Watch out for PAE architecture, which has an unsigned long, and might not
111 * have enough bits to store all physical address and flags. So far we have
112 * enough room for all our flags.
114 #define MIGRATE_PFN_VALID (1UL << 0)
115 #define MIGRATE_PFN_MIGRATE (1UL << 1)
116 #define MIGRATE_PFN_LOCKED (1UL << 2)
117 #define MIGRATE_PFN_WRITE (1UL << 3)
118 #define MIGRATE_PFN_SHIFT 6
120 static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
122 if (!(mpfn & MIGRATE_PFN_VALID))
124 return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
127 static inline unsigned long migrate_pfn(unsigned long pfn)
129 return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
132 enum migrate_vma_direction {
133 MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
134 MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
138 struct vm_area_struct *vma;
140 * Both src and dst array must be big enough for
141 * (end - start) >> PAGE_SHIFT entries.
143 * The src array must not be modified by the caller after
144 * migrate_vma_setup(), and must not change the dst array after
145 * migrate_vma_pages() returns.
149 unsigned long cpages;
150 unsigned long npages;
155 * Set to the owner value also stored in page->pgmap->owner for
156 * migrating out of device private memory. The flags also need to
157 * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
158 * The caller should always set this field when using mmu notifier
159 * callbacks to avoid device MMU invalidations for device private
160 * pages that are not being migrated.
166 int migrate_vma_setup(struct migrate_vma *args);
167 void migrate_vma_pages(struct migrate_vma *migrate);
168 void migrate_vma_finalize(struct migrate_vma *migrate);
170 #endif /* CONFIG_MIGRATION */
172 #endif /* _LINUX_MIGRATE_H */