]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
71e3aac0 AA |
2 | #ifndef _LINUX_HUGE_MM_H |
3 | #define _LINUX_HUGE_MM_H | |
4 | ||
16981d76 | 5 | #include <linux/sched/coredump.h> |
226ab561 | 6 | #include <linux/mm_types.h> |
16981d76 | 7 | |
baabda26 DW |
8 | #include <linux/fs.h> /* only for vma_is_dax() */ |
9 | ||
2b740303 | 10 | extern vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf); |
71e3aac0 AA |
11 | extern int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, |
12 | pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr, | |
13 | struct vm_area_struct *vma); | |
82b0f8c3 | 14 | extern void huge_pmd_set_accessed(struct vm_fault *vmf, pmd_t orig_pmd); |
a00cc7d9 MW |
15 | extern int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, |
16 | pud_t *dst_pud, pud_t *src_pud, unsigned long addr, | |
17 | struct vm_area_struct *vma); | |
18 | ||
19 | #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD | |
20 | extern void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud); | |
21 | #else | |
22 | static inline void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud) | |
23 | { | |
24 | } | |
25 | #endif | |
26 | ||
2b740303 | 27 | extern vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd); |
b676b293 | 28 | extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma, |
71e3aac0 AA |
29 | unsigned long addr, |
30 | pmd_t *pmd, | |
31 | unsigned int flags); | |
319904ad | 32 | extern bool madvise_free_huge_pmd(struct mmu_gather *tlb, |
b8d3c4c3 MK |
33 | struct vm_area_struct *vma, |
34 | pmd_t *pmd, unsigned long addr, unsigned long next); | |
71e3aac0 AA |
35 | extern int zap_huge_pmd(struct mmu_gather *tlb, |
36 | struct vm_area_struct *vma, | |
f21760b1 | 37 | pmd_t *pmd, unsigned long addr); |
a00cc7d9 MW |
38 | extern int zap_huge_pud(struct mmu_gather *tlb, |
39 | struct vm_area_struct *vma, | |
40 | pud_t *pud, unsigned long addr); | |
0ca1634d JW |
41 | extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
42 | unsigned long addr, unsigned long end, | |
43 | unsigned char *vec); | |
bf8616d5 | 44 | extern bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr, |
37a1c49a | 45 | unsigned long new_addr, unsigned long old_end, |
eb66ae03 | 46 | pmd_t *old_pmd, pmd_t *new_pmd); |
cd7548ab | 47 | extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
4b10e7d5 MG |
48 | unsigned long addr, pgprot_t newprot, |
49 | int prot_numa); | |
226ab561 | 50 | vm_fault_t vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr, |
a00cc7d9 | 51 | pmd_t *pmd, pfn_t pfn, bool write); |
226ab561 | 52 | vm_fault_t vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr, |
a00cc7d9 | 53 | pud_t *pud, pfn_t pfn, bool write); |
71e3aac0 AA |
54 | enum transparent_hugepage_flag { |
55 | TRANSPARENT_HUGEPAGE_FLAG, | |
56 | TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, | |
444eb2a4 MG |
57 | TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, |
58 | TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, | |
21440d7e | 59 | TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, |
71e3aac0 | 60 | TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, |
ba76149f | 61 | TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG, |
79da5407 | 62 | TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG, |
71e3aac0 AA |
63 | #ifdef CONFIG_DEBUG_VM |
64 | TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG, | |
65 | #endif | |
66 | }; | |
67 | ||
b46e756f KS |
68 | struct kobject; |
69 | struct kobj_attribute; | |
70 | ||
71 | extern ssize_t single_hugepage_flag_store(struct kobject *kobj, | |
72 | struct kobj_attribute *attr, | |
73 | const char *buf, size_t count, | |
74 | enum transparent_hugepage_flag flag); | |
75 | extern ssize_t single_hugepage_flag_show(struct kobject *kobj, | |
76 | struct kobj_attribute *attr, char *buf, | |
77 | enum transparent_hugepage_flag flag); | |
5a6e75f8 KS |
78 | extern struct kobj_attribute shmem_enabled_attr; |
79 | ||
d8c37c48 NH |
80 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) |
81 | #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER) | |
82 | ||
71e3aac0 | 83 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
fde52796 AK |
84 | #define HPAGE_PMD_SHIFT PMD_SHIFT |
85 | #define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT) | |
86 | #define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1)) | |
71e3aac0 | 87 | |
a00cc7d9 MW |
88 | #define HPAGE_PUD_SHIFT PUD_SHIFT |
89 | #define HPAGE_PUD_SIZE ((1UL) << HPAGE_PUD_SHIFT) | |
90 | #define HPAGE_PUD_MASK (~(HPAGE_PUD_SIZE - 1)) | |
91 | ||
20995974 AS |
92 | extern bool is_vma_temporary_stack(struct vm_area_struct *vma); |
93 | ||
16981d76 DW |
94 | extern unsigned long transparent_hugepage_flags; |
95 | ||
7635d9cb MH |
96 | /* |
97 | * to be used on vmas which are known to support THP. | |
98 | * Use transparent_hugepage_enabled otherwise | |
99 | */ | |
100 | static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) | |
16981d76 DW |
101 | { |
102 | if (vma->vm_flags & VM_NOHUGEPAGE) | |
103 | return false; | |
104 | ||
105 | if (is_vma_temporary_stack(vma)) | |
106 | return false; | |
107 | ||
108 | if (test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) | |
109 | return false; | |
110 | ||
111 | if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_FLAG)) | |
112 | return true; | |
113 | ||
baabda26 DW |
114 | if (vma_is_dax(vma)) |
115 | return true; | |
116 | ||
16981d76 DW |
117 | if (transparent_hugepage_flags & |
118 | (1 << TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG)) | |
119 | return !!(vma->vm_flags & VM_HUGEPAGE); | |
120 | ||
121 | return false; | |
122 | } | |
123 | ||
7635d9cb MH |
124 | bool transparent_hugepage_enabled(struct vm_area_struct *vma); |
125 | ||
79da5407 KS |
126 | #define transparent_hugepage_use_zero_page() \ |
127 | (transparent_hugepage_flags & \ | |
128 | (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG)) | |
71e3aac0 AA |
129 | #ifdef CONFIG_DEBUG_VM |
130 | #define transparent_hugepage_debug_cow() \ | |
131 | (transparent_hugepage_flags & \ | |
132 | (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG)) | |
133 | #else /* CONFIG_DEBUG_VM */ | |
134 | #define transparent_hugepage_debug_cow() 0 | |
135 | #endif /* CONFIG_DEBUG_VM */ | |
136 | ||
74d2fad1 TK |
137 | extern unsigned long thp_get_unmapped_area(struct file *filp, |
138 | unsigned long addr, unsigned long len, unsigned long pgoff, | |
139 | unsigned long flags); | |
140 | ||
9a982250 KS |
141 | extern void prep_transhuge_page(struct page *page); |
142 | extern void free_transhuge_page(struct page *page); | |
143 | ||
b8f593cd | 144 | bool can_split_huge_page(struct page *page, int *pextra_pins); |
e9b61f19 KS |
145 | int split_huge_page_to_list(struct page *page, struct list_head *list); |
146 | static inline int split_huge_page(struct page *page) | |
147 | { | |
148 | return split_huge_page_to_list(page, NULL); | |
149 | } | |
9a982250 | 150 | void deferred_split_huge_page(struct page *page); |
eef1b3ba KS |
151 | |
152 | void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, | |
33f4751e | 153 | unsigned long address, bool freeze, struct page *page); |
eef1b3ba KS |
154 | |
155 | #define split_huge_pmd(__vma, __pmd, __address) \ | |
156 | do { \ | |
157 | pmd_t *____pmd = (__pmd); \ | |
84c3fc4e | 158 | if (is_swap_pmd(*____pmd) || pmd_trans_huge(*____pmd) \ |
5c7fb56e | 159 | || pmd_devmap(*____pmd)) \ |
fec89c10 | 160 | __split_huge_pmd(__vma, __pmd, __address, \ |
33f4751e | 161 | false, NULL); \ |
eef1b3ba | 162 | } while (0) |
ad0bed24 | 163 | |
2a52bcbc | 164 | |
fec89c10 KS |
165 | void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address, |
166 | bool freeze, struct page *page); | |
2a52bcbc | 167 | |
a00cc7d9 MW |
168 | void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, |
169 | unsigned long address); | |
170 | ||
171 | #define split_huge_pud(__vma, __pud, __address) \ | |
172 | do { \ | |
173 | pud_t *____pud = (__pud); \ | |
174 | if (pud_trans_huge(*____pud) \ | |
175 | || pud_devmap(*____pud)) \ | |
176 | __split_huge_pud(__vma, __pud, __address); \ | |
177 | } while (0) | |
178 | ||
60ab3244 AA |
179 | extern int hugepage_madvise(struct vm_area_struct *vma, |
180 | unsigned long *vm_flags, int advice); | |
e1b9996b | 181 | extern void vma_adjust_trans_huge(struct vm_area_struct *vma, |
94fcc585 AA |
182 | unsigned long start, |
183 | unsigned long end, | |
184 | long adjust_next); | |
b6ec57f4 KS |
185 | extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, |
186 | struct vm_area_struct *vma); | |
a00cc7d9 MW |
187 | extern spinlock_t *__pud_trans_huge_lock(pud_t *pud, |
188 | struct vm_area_struct *vma); | |
84c3fc4e ZY |
189 | |
190 | static inline int is_swap_pmd(pmd_t pmd) | |
191 | { | |
192 | return !pmd_none(pmd) && !pmd_present(pmd); | |
193 | } | |
194 | ||
025c5b24 | 195 | /* mmap_sem must be held on entry */ |
b6ec57f4 KS |
196 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
197 | struct vm_area_struct *vma) | |
025c5b24 | 198 | { |
81d1b09c | 199 | VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma); |
84c3fc4e | 200 | if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) |
b6ec57f4 | 201 | return __pmd_trans_huge_lock(pmd, vma); |
025c5b24 | 202 | else |
969e8d7e | 203 | return NULL; |
025c5b24 | 204 | } |
a00cc7d9 MW |
205 | static inline spinlock_t *pud_trans_huge_lock(pud_t *pud, |
206 | struct vm_area_struct *vma) | |
207 | { | |
208 | VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma); | |
209 | if (pud_trans_huge(*pud) || pud_devmap(*pud)) | |
210 | return __pud_trans_huge_lock(pud, vma); | |
211 | else | |
212 | return NULL; | |
213 | } | |
2c888cfb RR |
214 | static inline int hpage_nr_pages(struct page *page) |
215 | { | |
216 | if (unlikely(PageTransHuge(page))) | |
217 | return HPAGE_PMD_NR; | |
218 | return 1; | |
219 | } | |
d10e63f2 | 220 | |
a00cc7d9 | 221 | struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr, |
df06b37f | 222 | pmd_t *pmd, int flags, struct dev_pagemap **pgmap); |
a00cc7d9 | 223 | struct page *follow_devmap_pud(struct vm_area_struct *vma, unsigned long addr, |
df06b37f | 224 | pud_t *pud, int flags, struct dev_pagemap **pgmap); |
a00cc7d9 | 225 | |
2b740303 | 226 | extern vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t orig_pmd); |
d10e63f2 | 227 | |
56873f43 WY |
228 | extern struct page *huge_zero_page; |
229 | ||
230 | static inline bool is_huge_zero_page(struct page *page) | |
231 | { | |
6aa7de05 | 232 | return READ_ONCE(huge_zero_page) == page; |
56873f43 WY |
233 | } |
234 | ||
fc437044 MW |
235 | static inline bool is_huge_zero_pmd(pmd_t pmd) |
236 | { | |
237 | return is_huge_zero_page(pmd_page(pmd)); | |
238 | } | |
239 | ||
a00cc7d9 MW |
240 | static inline bool is_huge_zero_pud(pud_t pud) |
241 | { | |
242 | return false; | |
243 | } | |
244 | ||
6fcb52a5 AL |
245 | struct page *mm_get_huge_zero_page(struct mm_struct *mm); |
246 | void mm_put_huge_zero_page(struct mm_struct *mm); | |
fc437044 | 247 | |
10102459 KS |
248 | #define mk_huge_pmd(page, prot) pmd_mkhuge(mk_pmd(page, prot)) |
249 | ||
9c670ea3 NH |
250 | static inline bool thp_migration_supported(void) |
251 | { | |
252 | return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION); | |
253 | } | |
254 | ||
71e3aac0 | 255 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
d8c37c48 NH |
256 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) |
257 | #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) | |
258 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | |
71e3aac0 | 259 | |
a00cc7d9 MW |
260 | #define HPAGE_PUD_SHIFT ({ BUILD_BUG(); 0; }) |
261 | #define HPAGE_PUD_MASK ({ BUILD_BUG(); 0; }) | |
262 | #define HPAGE_PUD_SIZE ({ BUILD_BUG(); 0; }) | |
263 | ||
2c888cfb RR |
264 | #define hpage_nr_pages(x) 1 |
265 | ||
7635d9cb MH |
266 | static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) |
267 | { | |
268 | return false; | |
269 | } | |
270 | ||
16981d76 DW |
271 | static inline bool transparent_hugepage_enabled(struct vm_area_struct *vma) |
272 | { | |
273 | return false; | |
274 | } | |
71e3aac0 | 275 | |
800d8c63 KS |
276 | static inline void prep_transhuge_page(struct page *page) {} |
277 | ||
71e3aac0 | 278 | #define transparent_hugepage_flags 0UL |
74d2fad1 TK |
279 | |
280 | #define thp_get_unmapped_area NULL | |
281 | ||
b8f593cd HY |
282 | static inline bool |
283 | can_split_huge_page(struct page *page, int *pextra_pins) | |
284 | { | |
285 | BUILD_BUG(); | |
286 | return false; | |
287 | } | |
5bc7b8ac SL |
288 | static inline int |
289 | split_huge_page_to_list(struct page *page, struct list_head *list) | |
290 | { | |
291 | return 0; | |
292 | } | |
71e3aac0 AA |
293 | static inline int split_huge_page(struct page *page) |
294 | { | |
295 | return 0; | |
296 | } | |
9a982250 | 297 | static inline void deferred_split_huge_page(struct page *page) {} |
78ddc534 | 298 | #define split_huge_pmd(__vma, __pmd, __address) \ |
e180377f | 299 | do { } while (0) |
2a52bcbc | 300 | |
fd60775a DR |
301 | static inline void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
302 | unsigned long address, bool freeze, struct page *page) {} | |
2a52bcbc | 303 | static inline void split_huge_pmd_address(struct vm_area_struct *vma, |
fec89c10 | 304 | unsigned long address, bool freeze, struct page *page) {} |
2a52bcbc | 305 | |
a00cc7d9 MW |
306 | #define split_huge_pud(__vma, __pmd, __address) \ |
307 | do { } while (0) | |
308 | ||
60ab3244 AA |
309 | static inline int hugepage_madvise(struct vm_area_struct *vma, |
310 | unsigned long *vm_flags, int advice) | |
0af4e98b AA |
311 | { |
312 | BUG(); | |
313 | return 0; | |
314 | } | |
94fcc585 AA |
315 | static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, |
316 | unsigned long start, | |
317 | unsigned long end, | |
318 | long adjust_next) | |
319 | { | |
320 | } | |
84c3fc4e ZY |
321 | static inline int is_swap_pmd(pmd_t pmd) |
322 | { | |
323 | return 0; | |
324 | } | |
b6ec57f4 KS |
325 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
326 | struct vm_area_struct *vma) | |
025c5b24 | 327 | { |
b6ec57f4 | 328 | return NULL; |
025c5b24 | 329 | } |
a00cc7d9 MW |
330 | static inline spinlock_t *pud_trans_huge_lock(pud_t *pud, |
331 | struct vm_area_struct *vma) | |
332 | { | |
333 | return NULL; | |
334 | } | |
d10e63f2 | 335 | |
2b740303 SJ |
336 | static inline vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf, |
337 | pmd_t orig_pmd) | |
d10e63f2 | 338 | { |
4daae3b4 | 339 | return 0; |
d10e63f2 MG |
340 | } |
341 | ||
56873f43 WY |
342 | static inline bool is_huge_zero_page(struct page *page) |
343 | { | |
344 | return false; | |
345 | } | |
346 | ||
a00cc7d9 MW |
347 | static inline bool is_huge_zero_pud(pud_t pud) |
348 | { | |
349 | return false; | |
350 | } | |
351 | ||
6fcb52a5 | 352 | static inline void mm_put_huge_zero_page(struct mm_struct *mm) |
aa88b68c | 353 | { |
6fcb52a5 | 354 | return; |
aa88b68c | 355 | } |
3565fce3 DW |
356 | |
357 | static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma, | |
df06b37f | 358 | unsigned long addr, pmd_t *pmd, int flags, struct dev_pagemap **pgmap) |
3565fce3 DW |
359 | { |
360 | return NULL; | |
361 | } | |
a00cc7d9 MW |
362 | |
363 | static inline struct page *follow_devmap_pud(struct vm_area_struct *vma, | |
df06b37f | 364 | unsigned long addr, pud_t *pud, int flags, struct dev_pagemap **pgmap) |
a00cc7d9 MW |
365 | { |
366 | return NULL; | |
367 | } | |
9c670ea3 NH |
368 | |
369 | static inline bool thp_migration_supported(void) | |
370 | { | |
371 | return false; | |
372 | } | |
71e3aac0 AA |
373 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
374 | ||
375 | #endif /* _LINUX_HUGE_MM_H */ |