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
22 /* Defined in mm/debug.c: */
23 extern const char *migrate_reason_names[MR_TYPES];
25 #ifdef CONFIG_MIGRATION
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);
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 void migration_entry_wait_on_locked(swp_entry_t entry, pte_t *ptep,
45 void folio_migrate_flags(struct folio *newfolio, struct folio *folio);
46 void folio_migrate_copy(struct folio *newfolio, struct folio *folio);
47 int folio_migrate_mapping(struct address_space *mapping,
48 struct folio *newfolio, struct folio *folio, int extra_count);
50 extern bool numa_demotion_enabled;
53 static inline void putback_movable_pages(struct list_head *l) {}
54 static inline int migrate_pages(struct list_head *l, new_page_t new,
55 free_page_t free, unsigned long private, enum migrate_mode mode,
56 int reason, unsigned int *ret_succeeded)
58 static inline struct page *alloc_migration_target(struct page *page,
59 unsigned long private)
61 static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
64 static inline void migrate_page_states(struct page *newpage, struct page *page)
68 static inline void migrate_page_copy(struct page *newpage,
71 static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
72 struct page *newpage, struct page *page)
77 #define numa_demotion_enabled false
78 #endif /* CONFIG_MIGRATION */
80 #ifdef CONFIG_COMPACTION
81 extern int PageMovable(struct page *page);
82 extern void __SetPageMovable(struct page *page, struct address_space *mapping);
83 extern void __ClearPageMovable(struct page *page);
85 static inline int PageMovable(struct page *page) { return 0; }
86 static inline void __SetPageMovable(struct page *page,
87 struct address_space *mapping)
90 static inline void __ClearPageMovable(struct page *page)
95 #ifdef CONFIG_NUMA_BALANCING
96 extern int migrate_misplaced_page(struct page *page,
97 struct vm_area_struct *vma, int node);
99 static inline int migrate_misplaced_page(struct page *page,
100 struct vm_area_struct *vma, int node)
102 return -EAGAIN; /* can't migrate now */
104 #endif /* CONFIG_NUMA_BALANCING */
106 #ifdef CONFIG_MIGRATION
109 * Watch out for PAE architecture, which has an unsigned long, and might not
110 * have enough bits to store all physical address and flags. So far we have
111 * enough room for all our flags.
113 #define MIGRATE_PFN_VALID (1UL << 0)
114 #define MIGRATE_PFN_MIGRATE (1UL << 1)
115 #define MIGRATE_PFN_WRITE (1UL << 3)
116 #define MIGRATE_PFN_SHIFT 6
118 static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
120 if (!(mpfn & MIGRATE_PFN_VALID))
122 return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
125 static inline unsigned long migrate_pfn(unsigned long pfn)
127 return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
130 enum migrate_vma_direction {
131 MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
132 MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
136 struct vm_area_struct *vma;
138 * Both src and dst array must be big enough for
139 * (end - start) >> PAGE_SHIFT entries.
141 * The src array must not be modified by the caller after
142 * migrate_vma_setup(), and must not change the dst array after
143 * migrate_vma_pages() returns.
147 unsigned long cpages;
148 unsigned long npages;
153 * Set to the owner value also stored in page->pgmap->owner for
154 * migrating out of device private memory. The flags also need to
155 * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
156 * The caller should always set this field when using mmu notifier
157 * callbacks to avoid device MMU invalidations for device private
158 * pages that are not being migrated.
164 int migrate_vma_setup(struct migrate_vma *args);
165 void migrate_vma_pages(struct migrate_vma *migrate);
166 void migrate_vma_finalize(struct migrate_vma *migrate);
167 int next_demotion_node(int node);
169 #else /* CONFIG_MIGRATION disabled: */
171 static inline int next_demotion_node(int node)
176 #endif /* CONFIG_MIGRATION */
178 #endif /* _LINUX_MIGRATE_H */