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);
54 extern void copy_huge_page(struct page *dst, struct page *src);
57 static inline void putback_movable_pages(struct list_head *l) {}
58 static inline int migrate_pages(struct list_head *l, new_page_t new,
59 free_page_t free, unsigned long private, enum migrate_mode mode,
62 static inline struct page *alloc_migration_target(struct page *page,
63 unsigned long private)
65 static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
68 static inline void migrate_page_states(struct page *newpage, struct page *page)
72 static inline void migrate_page_copy(struct page *newpage,
75 static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
76 struct page *newpage, struct page *page)
81 static inline void copy_huge_page(struct page *dst, struct page *src)
84 #endif /* CONFIG_MIGRATION */
86 #ifdef CONFIG_COMPACTION
87 extern int PageMovable(struct page *page);
88 extern void __SetPageMovable(struct page *page, struct address_space *mapping);
89 extern void __ClearPageMovable(struct page *page);
91 static inline int PageMovable(struct page *page) { return 0; }
92 static inline void __SetPageMovable(struct page *page,
93 struct address_space *mapping)
96 static inline void __ClearPageMovable(struct page *page)
101 #ifdef CONFIG_NUMA_BALANCING
102 extern int migrate_misplaced_page(struct page *page,
103 struct vm_area_struct *vma, int node);
105 static inline int migrate_misplaced_page(struct page *page,
106 struct vm_area_struct *vma, int node)
108 return -EAGAIN; /* can't migrate now */
110 #endif /* CONFIG_NUMA_BALANCING */
112 #ifdef CONFIG_MIGRATION
115 * Watch out for PAE architecture, which has an unsigned long, and might not
116 * have enough bits to store all physical address and flags. So far we have
117 * enough room for all our flags.
119 #define MIGRATE_PFN_VALID (1UL << 0)
120 #define MIGRATE_PFN_MIGRATE (1UL << 1)
121 #define MIGRATE_PFN_LOCKED (1UL << 2)
122 #define MIGRATE_PFN_WRITE (1UL << 3)
123 #define MIGRATE_PFN_SHIFT 6
125 static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
127 if (!(mpfn & MIGRATE_PFN_VALID))
129 return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
132 static inline unsigned long migrate_pfn(unsigned long pfn)
134 return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
137 enum migrate_vma_direction {
138 MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
139 MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
143 struct vm_area_struct *vma;
145 * Both src and dst array must be big enough for
146 * (end - start) >> PAGE_SHIFT entries.
148 * The src array must not be modified by the caller after
149 * migrate_vma_setup(), and must not change the dst array after
150 * migrate_vma_pages() returns.
154 unsigned long cpages;
155 unsigned long npages;
160 * Set to the owner value also stored in page->pgmap->owner for
161 * migrating out of device private memory. The flags also need to
162 * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
163 * The caller should always set this field when using mmu notifier
164 * callbacks to avoid device MMU invalidations for device private
165 * pages that are not being migrated.
171 int migrate_vma_setup(struct migrate_vma *args);
172 void migrate_vma_pages(struct migrate_vma *migrate);
173 void migrate_vma_finalize(struct migrate_vma *migrate);
175 #endif /* CONFIG_MIGRATION */
177 #endif /* _LINUX_MIGRATE_H */