at commit 709ba1c5
| 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 folio *new_folio_t(struct folio *folio, unsigned long private); |
| 11 | typedef void free_folio_t(struct folio *folio, unsigned long private); |
| 12 | |
| 13 | struct migration_target_control; |
| 14 | |
| 15 | /** |
| 16 | * struct movable_operations - Driver page migration |
| 17 | * @isolate_page: |
| 18 | * The VM calls this function to prepare the page to be moved. The page |
| 19 | * is locked and the driver should not unlock it. The driver should |
| 20 | * return ``true`` if the page is movable and ``false`` if it is not |
| 21 | * currently movable. After this function returns, the VM uses the |
| 22 | * page->lru field, so the driver must preserve any information which |
| 23 | * is usually stored here. |
| 24 | * |
| 25 | * @migrate_page: |
| 26 | * After isolation, the VM calls this function with the isolated |
| 27 | * @src page. The driver should copy the contents of the |
| 28 | * @src page to the @dst page and set up the fields of @dst page. |
| 29 | * Both pages are locked. |
| 30 | * If page migration is successful, the driver should return 0. |
| 31 | * If the driver cannot migrate the page at the moment, it can return |
| 32 | * -EAGAIN. The VM interprets this as a temporary migration failure and |
| 33 | * will retry it later. Any other error value is a permanent migration |
| 34 | * failure and migration will not be retried. |
| 35 | * The driver shouldn't touch the @src->lru field while in the |
| 36 | * migrate_page() function. It may write to @dst->lru. |
| 37 | * |
| 38 | * @putback_page: |
| 39 | * If migration fails on the isolated page, the VM informs the driver |
| 40 | * that the page is no longer a candidate for migration by calling |
| 41 | * this function. The driver should put the isolated page back into |
| 42 | * its own data structure. |
| 43 | */ |
| 44 | struct movable_operations { |
| 45 | bool (*isolate_page)(struct page *, isolate_mode_t); |
| 46 | int (*migrate_page)(struct page *dst, struct page *src, |
| 47 | enum migrate_mode); |
| 48 | void (*putback_page)(struct page *); |
| 49 | }; |
| 50 | |
| 51 | /* Defined in mm/debug.c: */ |
| 52 | extern const char *migrate_reason_names[MR_TYPES]; |
| 53 | |
| 54 | #ifdef CONFIG_MIGRATION |
| 55 | |
| 56 | void putback_movable_pages(struct list_head *l); |
| 57 | int migrate_folio(struct address_space *mapping, struct folio *dst, |
| 58 | struct folio *src, enum migrate_mode mode); |
| 59 | int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free, |
| 60 | unsigned long private, enum migrate_mode mode, |
| 61 | enum migrate_reason reason, |
| 62 | unsigned int *ret_succeeded); |
| 63 | struct folio *alloc_migration_target(struct folio *src, unsigned long private); |
| 64 | bool isolate_movable_ops_page(struct page *page, isolate_mode_t mode); |
| 65 | bool isolate_folio_to_list(struct folio *folio, struct list_head *list); |
| 66 | |
| 67 | int migrate_huge_page_move_mapping(struct address_space *mapping, |
| 68 | struct folio *dst, struct folio *src); |
| 69 | void softleaf_entry_wait_on_locked(softleaf_t entry, spinlock_t *ptl) |
| 70 | __releases(ptl); |
| 71 | void folio_migrate_flags(struct folio *newfolio, struct folio *folio); |
| 72 | int folio_migrate_mapping(struct address_space *mapping, |
| 73 | struct folio *newfolio, struct folio *folio, int extra_count); |
| 74 | int set_movable_ops(const struct movable_operations *ops, enum pagetype type); |
| 75 | |
| 76 | #else |
| 77 | |
| 78 | static inline void putback_movable_pages(struct list_head *l) {} |
| 79 | static inline int migrate_pages(struct list_head *l, new_folio_t new, |
| 80 | free_folio_t free, unsigned long private, |
| 81 | enum migrate_mode mode, enum migrate_reason reason, |
| 82 | unsigned int *ret_succeeded) |
| 83 | { return -ENOSYS; } |
| 84 | static inline struct folio *alloc_migration_target(struct folio *src, |
| 85 | unsigned long private) |
| 86 | { return NULL; } |
| 87 | static inline bool isolate_movable_ops_page(struct page *page, isolate_mode_t mode) |
| 88 | { return false; } |
| 89 | static inline bool isolate_folio_to_list(struct folio *folio, struct list_head *list) |
| 90 | { return false; } |
| 91 | |
| 92 | static inline int migrate_huge_page_move_mapping(struct address_space *mapping, |
| 93 | struct folio *dst, struct folio *src) |
| 94 | { |
| 95 | return -ENOSYS; |
| 96 | } |
| 97 | static inline int set_movable_ops(const struct movable_operations *ops, enum pagetype type) |
| 98 | { |
| 99 | return -ENOSYS; |
| 100 | } |
| 101 | |
| 102 | static inline void softleaf_entry_wait_on_locked(softleaf_t entry, spinlock_t *ptl) |
| 103 | __releases(ptl) |
| 104 | { |
| 105 | WARN_ON_ONCE(1); |
| 106 | |
| 107 | spin_unlock(ptl); |
| 108 | } |
| 109 | |
| 110 | #endif /* CONFIG_MIGRATION */ |
| 111 | |
| 112 | #ifdef CONFIG_NUMA_BALANCING |
| 113 | int migrate_misplaced_folio_prepare(struct folio *folio, |
| 114 | struct vm_area_struct *vma, int node); |
| 115 | int migrate_misplaced_folio(struct folio *folio, int node); |
| 116 | #else |
| 117 | static inline int migrate_misplaced_folio_prepare(struct folio *folio, |
| 118 | struct vm_area_struct *vma, int node) |
| 119 | { |
| 120 | return -EAGAIN; /* can't migrate now */ |
| 121 | } |
| 122 | static inline int migrate_misplaced_folio(struct folio *folio, int node) |
| 123 | { |
| 124 | return -EAGAIN; /* can't migrate now */ |
| 125 | } |
| 126 | #endif /* CONFIG_NUMA_BALANCING */ |
| 127 | |
| 128 | #ifdef CONFIG_MIGRATION |
| 129 | |
| 130 | /* |
| 131 | * Watch out for PAE architecture, which has an unsigned long, and might not |
| 132 | * have enough bits to store all physical address and flags. So far we have |
| 133 | * enough room for all our flags. |
| 134 | */ |
| 135 | #define MIGRATE_PFN_VALID (1UL << 0) |
| 136 | #define MIGRATE_PFN_MIGRATE (1UL << 1) |
| 137 | #define MIGRATE_PFN_WRITE (1UL << 3) |
| 138 | #define MIGRATE_PFN_COMPOUND (1UL << 4) |
| 139 | #define MIGRATE_PFN_SHIFT 6 |
| 140 | |
| 141 | static inline struct page *migrate_pfn_to_page(unsigned long mpfn) |
| 142 | { |
| 143 | if (!(mpfn & MIGRATE_PFN_VALID)) |
| 144 | return NULL; |
| 145 | return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT); |
| 146 | } |
| 147 | |
| 148 | static inline unsigned long migrate_pfn(unsigned long pfn) |
| 149 | { |
| 150 | return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID; |
| 151 | } |
| 152 | |
| 153 | enum migrate_vma_direction { |
| 154 | MIGRATE_VMA_SELECT_SYSTEM = 1 << 0, |
| 155 | MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1, |
| 156 | MIGRATE_VMA_SELECT_DEVICE_COHERENT = 1 << 2, |
| 157 | MIGRATE_VMA_SELECT_COMPOUND = 1 << 3, |
| 158 | }; |
| 159 | |
| 160 | struct migrate_vma { |
| 161 | struct vm_area_struct *vma; |
| 162 | /* |
| 163 | * Both src and dst array must be big enough for |
| 164 | * (end - start) >> PAGE_SHIFT entries. |
| 165 | * |
| 166 | * The src array must not be modified by the caller after |
| 167 | * migrate_vma_setup(), and must not change the dst array after |
| 168 | * migrate_vma_pages() returns. |
| 169 | */ |
| 170 | unsigned long *dst; |
| 171 | unsigned long *src; |
| 172 | unsigned long cpages; |
| 173 | unsigned long npages; |
| 174 | unsigned long start; |
| 175 | unsigned long end; |
| 176 | |
| 177 | /* |
| 178 | * Set to the owner value also stored in page_pgmap(page)->owner |
| 179 | * for migrating out of device private memory. The flags also need to |
| 180 | * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE. |
| 181 | * The caller should always set this field when using mmu notifier |
| 182 | * callbacks to avoid device MMU invalidations for device private |
| 183 | * pages that are not being migrated. |
| 184 | */ |
| 185 | void *pgmap_owner; |
| 186 | unsigned long flags; |
| 187 | |
| 188 | /* |
| 189 | * Set to vmf->page if this is being called to migrate a page as part of |
| 190 | * a migrate_to_ram() callback. |
| 191 | */ |
| 192 | struct page *fault_page; |
| 193 | }; |
| 194 | |
| 195 | int migrate_vma_setup(struct migrate_vma *args); |
| 196 | void migrate_vma_pages(struct migrate_vma *migrate); |
| 197 | void migrate_vma_finalize(struct migrate_vma *migrate); |
| 198 | int migrate_device_range(unsigned long *src_pfns, unsigned long start, |
| 199 | unsigned long npages); |
| 200 | int migrate_device_pfns(unsigned long *src_pfns, unsigned long npages); |
| 201 | void migrate_device_pages(unsigned long *src_pfns, unsigned long *dst_pfns, |
| 202 | unsigned long npages); |
| 203 | void migrate_device_finalize(unsigned long *src_pfns, |
| 204 | unsigned long *dst_pfns, unsigned long npages); |
| 205 | |
| 206 | #endif /* CONFIG_MIGRATION */ |
| 207 | |
| 208 | #endif /* _LINUX_MIGRATE_H */ |