Merge tag 'pull-18-rc1-work.fd' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / include / linux / migrate.h
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 page *new_page_t(struct page *page, unsigned long private);
11 typedef void free_page_t(struct page *page, unsigned long private);
12
13 struct migration_target_control;
14
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
21
22 /* Defined in mm/debug.c: */
23 extern const char *migrate_reason_names[MR_TYPES];
24
25 #ifdef CONFIG_MIGRATION
26
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);
36
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,
44                                 spinlock_t *ptl);
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);
49
50 #else
51
52 static inline void putback_movable_pages(struct list_head *l) {}
53 static inline int migrate_pages(struct list_head *l, new_page_t new,
54                 free_page_t free, unsigned long private, enum migrate_mode mode,
55                 int reason, unsigned int *ret_succeeded)
56         { return -ENOSYS; }
57 static inline struct page *alloc_migration_target(struct page *page,
58                 unsigned long private)
59         { return NULL; }
60 static inline int isolate_movable_page(struct page *page, isolate_mode_t mode)
61         { return -EBUSY; }
62
63 static inline void migrate_page_states(struct page *newpage, struct page *page)
64 {
65 }
66
67 static inline void migrate_page_copy(struct page *newpage,
68                                      struct page *page) {}
69
70 static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
71                                   struct page *newpage, struct page *page)
72 {
73         return -ENOSYS;
74 }
75
76 #endif /* CONFIG_MIGRATION */
77
78 #if defined(CONFIG_MIGRATION) && defined(CONFIG_NUMA)
79 extern void set_migration_target_nodes(void);
80 extern void migrate_on_reclaim_init(void);
81 extern bool numa_demotion_enabled;
82 extern int next_demotion_node(int node);
83 #else
84 static inline void set_migration_target_nodes(void) {}
85 static inline void migrate_on_reclaim_init(void) {}
86 static inline int next_demotion_node(int node)
87 {
88         return NUMA_NO_NODE;
89 }
90 #define numa_demotion_enabled  false
91 #endif
92
93 #ifdef CONFIG_COMPACTION
94 extern int PageMovable(struct page *page);
95 extern void __SetPageMovable(struct page *page, struct address_space *mapping);
96 extern void __ClearPageMovable(struct page *page);
97 #else
98 static inline int PageMovable(struct page *page) { return 0; }
99 static inline void __SetPageMovable(struct page *page,
100                                 struct address_space *mapping)
101 {
102 }
103 static inline void __ClearPageMovable(struct page *page)
104 {
105 }
106 #endif
107
108 static inline bool folio_test_movable(struct folio *folio)
109 {
110         return PageMovable(&folio->page);
111 }
112
113 #ifdef CONFIG_NUMA_BALANCING
114 extern int migrate_misplaced_page(struct page *page,
115                                   struct vm_area_struct *vma, int node);
116 #else
117 static inline int migrate_misplaced_page(struct page *page,
118                                          struct vm_area_struct *vma, int node)
119 {
120         return -EAGAIN; /* can't migrate now */
121 }
122 #endif /* CONFIG_NUMA_BALANCING */
123
124 #ifdef CONFIG_MIGRATION
125
126 /*
127  * Watch out for PAE architecture, which has an unsigned long, and might not
128  * have enough bits to store all physical address and flags. So far we have
129  * enough room for all our flags.
130  */
131 #define MIGRATE_PFN_VALID       (1UL << 0)
132 #define MIGRATE_PFN_MIGRATE     (1UL << 1)
133 #define MIGRATE_PFN_WRITE       (1UL << 3)
134 #define MIGRATE_PFN_SHIFT       6
135
136 static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
137 {
138         if (!(mpfn & MIGRATE_PFN_VALID))
139                 return NULL;
140         return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
141 }
142
143 static inline unsigned long migrate_pfn(unsigned long pfn)
144 {
145         return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;
146 }
147
148 enum migrate_vma_direction {
149         MIGRATE_VMA_SELECT_SYSTEM = 1 << 0,
150         MIGRATE_VMA_SELECT_DEVICE_PRIVATE = 1 << 1,
151 };
152
153 struct migrate_vma {
154         struct vm_area_struct   *vma;
155         /*
156          * Both src and dst array must be big enough for
157          * (end - start) >> PAGE_SHIFT entries.
158          *
159          * The src array must not be modified by the caller after
160          * migrate_vma_setup(), and must not change the dst array after
161          * migrate_vma_pages() returns.
162          */
163         unsigned long           *dst;
164         unsigned long           *src;
165         unsigned long           cpages;
166         unsigned long           npages;
167         unsigned long           start;
168         unsigned long           end;
169
170         /*
171          * Set to the owner value also stored in page->pgmap->owner for
172          * migrating out of device private memory. The flags also need to
173          * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE.
174          * The caller should always set this field when using mmu notifier
175          * callbacks to avoid device MMU invalidations for device private
176          * pages that are not being migrated.
177          */
178         void                    *pgmap_owner;
179         unsigned long           flags;
180 };
181
182 int migrate_vma_setup(struct migrate_vma *args);
183 void migrate_vma_pages(struct migrate_vma *migrate);
184 void migrate_vma_finalize(struct migrate_vma *migrate);
185 #endif /* CONFIG_MIGRATION */
186
187 #endif /* _LINUX_MIGRATE_H */