1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_HUGE_MM_H
3 #define _LINUX_HUGE_MM_H
4
5 #include <linux/mm_types.h>
6
7 #include <linux/fs.h> /* only for vma_is_dax() */
8 #include <linux/kobject.h>
9
10 vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf);
11 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 *dst_vma, struct vm_area_struct *src_vma);
14 void huge_pmd_set_accessed(struct vm_fault *vmf);
15 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 void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud);
21 #else
huge_pud_set_accessed(struct vm_fault * vmf,pud_t orig_pud)22 static inline void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
23 {
24 }
25 #endif
26
27 vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf);
28 bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
29 pmd_t *pmd, unsigned long addr, unsigned long next);
30 int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, pmd_t *pmd,
31 unsigned long addr);
32 int zap_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma, pud_t *pud,
33 unsigned long addr);
34 bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
35 unsigned long new_addr, pmd_t *old_pmd, pmd_t *new_pmd);
36 int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
37 pmd_t *pmd, unsigned long addr, pgprot_t newprot,
38 unsigned long cp_flags);
39
40 vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn,
41 bool write);
42 vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, unsigned long pfn,
43 bool write);
44 vm_fault_t vmf_insert_folio_pmd(struct vm_fault *vmf, struct folio *folio,
45 bool write);
46 vm_fault_t vmf_insert_folio_pud(struct vm_fault *vmf, struct folio *folio,
47 bool write);
48
49 enum transparent_hugepage_flag {
50 TRANSPARENT_HUGEPAGE_UNSUPPORTED,
51 TRANSPARENT_HUGEPAGE_FLAG,
52 TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
53 TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
54 TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
55 TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG,
56 TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
57 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
58 TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG,
59 };
60
61 struct kobject;
62 struct kobj_attribute;
63
64 ssize_t single_hugepage_flag_store(struct kobject *kobj,
65 struct kobj_attribute *attr,
66 const char *buf, size_t count,
67 enum transparent_hugepage_flag flag);
68 ssize_t single_hugepage_flag_show(struct kobject *kobj,
69 struct kobj_attribute *attr, char *buf,
70 enum transparent_hugepage_flag flag);
71 extern struct kobj_attribute shmem_enabled_attr;
72 extern struct kobj_attribute thpsize_shmem_enabled_attr;
73
74 /*
75 * Mask of all large folio orders supported for anonymous THP; all orders up to
76 * and including PMD_ORDER, except order-0 (which is not "huge") and order-1
77 * (which is a limitation of the THP implementation).
78 */
79 #define THP_ORDERS_ALL_ANON ((BIT(PMD_ORDER + 1) - 1) & ~(BIT(0) | BIT(1)))
80
81 /*
82 * Mask of all large folio orders supported for file THP. Folios in a DAX
83 * file is never split and the MAX_PAGECACHE_ORDER limit does not apply to
84 * it. Same to PFNMAPs where there's neither page* nor pagecache.
85 */
86 #define THP_ORDERS_ALL_SPECIAL \
87 (BIT(PMD_ORDER) | BIT(PUD_ORDER))
88 #define THP_ORDERS_ALL_FILE_DEFAULT \
89 ((BIT(MAX_PAGECACHE_ORDER + 1) - 1) & ~BIT(0))
90
91 /*
92 * Mask of all large folio orders supported for THP.
93 */
94 #define THP_ORDERS_ALL \
95 (THP_ORDERS_ALL_ANON | THP_ORDERS_ALL_SPECIAL | THP_ORDERS_ALL_FILE_DEFAULT)
96
97 enum tva_type {
98 TVA_SMAPS, /* Exposing "THPeligible:" in smaps. */
99 TVA_PAGEFAULT, /* Serving a page fault. */
100 TVA_KHUGEPAGED, /* Khugepaged collapse. */
101 TVA_FORCED_COLLAPSE, /* Forced collapse (e.g. MADV_COLLAPSE). */
102 };
103
104 #define thp_vma_allowable_order(vma, vm_flags, type, order) \
105 (!!thp_vma_allowable_orders(vma, vm_flags, type, BIT(order)))
106
107 #define split_folio(f) split_folio_to_list(f, NULL)
108
109 #ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES
110 #define HPAGE_PMD_SHIFT PMD_SHIFT
111 #define HPAGE_PUD_SHIFT PUD_SHIFT
112 #else
113 #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
114 #define HPAGE_PUD_SHIFT ({ BUILD_BUG(); 0; })
115 #endif
116
117 #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
118 #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
119 #define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1))
120 #define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
121
122 #define HPAGE_PUD_ORDER (HPAGE_PUD_SHIFT-PAGE_SHIFT)
123 #define HPAGE_PUD_NR (1<<HPAGE_PUD_ORDER)
124 #define HPAGE_PUD_MASK (~(HPAGE_PUD_SIZE - 1))
125 #define HPAGE_PUD_SIZE ((1UL) << HPAGE_PUD_SHIFT)
126
127 enum mthp_stat_item {
128 MTHP_STAT_ANON_FAULT_ALLOC,
129 MTHP_STAT_ANON_FAULT_FALLBACK,
130 MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE,
131 MTHP_STAT_ZSWPOUT,
132 MTHP_STAT_SWPIN,
133 MTHP_STAT_SWPIN_FALLBACK,
134 MTHP_STAT_SWPIN_FALLBACK_CHARGE,
135 MTHP_STAT_SWPOUT,
136 MTHP_STAT_SWPOUT_FALLBACK,
137 MTHP_STAT_SHMEM_ALLOC,
138 MTHP_STAT_SHMEM_FALLBACK,
139 MTHP_STAT_SHMEM_FALLBACK_CHARGE,
140 MTHP_STAT_SPLIT,
141 MTHP_STAT_SPLIT_FAILED,
142 MTHP_STAT_SPLIT_DEFERRED,
143 MTHP_STAT_NR_ANON,
144 MTHP_STAT_NR_ANON_PARTIALLY_MAPPED,
145 __MTHP_STAT_COUNT
146 };
147
148 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && defined(CONFIG_SYSFS)
149 struct mthp_stat {
150 unsigned long stats[ilog2(MAX_PTRS_PER_PTE) + 1][__MTHP_STAT_COUNT];
151 };
152
153 DECLARE_PER_CPU(struct mthp_stat, mthp_stats);
154
mod_mthp_stat(int order,enum mthp_stat_item item,int delta)155 static inline void mod_mthp_stat(int order, enum mthp_stat_item item, int delta)
156 {
157 if (order <= 0 || order > PMD_ORDER)
158 return;
159
160 this_cpu_add(mthp_stats.stats[order][item], delta);
161 }
162
count_mthp_stat(int order,enum mthp_stat_item item)163 static inline void count_mthp_stat(int order, enum mthp_stat_item item)
164 {
165 mod_mthp_stat(order, item, 1);
166 }
167
168 #else
mod_mthp_stat(int order,enum mthp_stat_item item,int delta)169 static inline void mod_mthp_stat(int order, enum mthp_stat_item item, int delta)
170 {
171 }
172
count_mthp_stat(int order,enum mthp_stat_item item)173 static inline void count_mthp_stat(int order, enum mthp_stat_item item)
174 {
175 }
176 #endif
177
178 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
179
180 extern unsigned long transparent_hugepage_flags;
181 extern unsigned long huge_anon_orders_always;
182 extern unsigned long huge_anon_orders_madvise;
183 extern unsigned long huge_anon_orders_inherit;
184
hugepage_global_enabled(void)185 static inline bool hugepage_global_enabled(void)
186 {
187 return transparent_hugepage_flags &
188 ((1<<TRANSPARENT_HUGEPAGE_FLAG) |
189 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG));
190 }
191
hugepage_global_always(void)192 static inline bool hugepage_global_always(void)
193 {
194 return transparent_hugepage_flags &
195 (1<<TRANSPARENT_HUGEPAGE_FLAG);
196 }
197
highest_order(unsigned long orders)198 static inline int highest_order(unsigned long orders)
199 {
200 return fls_long(orders) - 1;
201 }
202
next_order(unsigned long * orders,int prev)203 static inline int next_order(unsigned long *orders, int prev)
204 {
205 *orders &= ~BIT(prev);
206 return highest_order(*orders);
207 }
208
209 /*
210 * Do the below checks:
211 * - For file vma, check if the linear page offset of vma is
212 * order-aligned within the file. The hugepage is
213 * guaranteed to be order-aligned within the file, but we must
214 * check that the order-aligned addresses in the VMA map to
215 * order-aligned offsets within the file, else the hugepage will
216 * not be mappable.
217 * - For all vmas, check if the haddr is in an aligned hugepage
218 * area.
219 */
thp_vma_suitable_order(struct vm_area_struct * vma,unsigned long addr,int order)220 static inline bool thp_vma_suitable_order(struct vm_area_struct *vma,
221 unsigned long addr, int order)
222 {
223 unsigned long hpage_size = PAGE_SIZE << order;
224 unsigned long haddr;
225
226 /* Don't have to check pgoff for anonymous vma */
227 if (!vma_is_anonymous(vma)) {
228 if (!IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff,
229 hpage_size >> PAGE_SHIFT))
230 return false;
231 }
232
233 haddr = ALIGN_DOWN(addr, hpage_size);
234
235 if (haddr < vma->vm_start || haddr + hpage_size > vma->vm_end)
236 return false;
237 return true;
238 }
239
240 /*
241 * Filter the bitfield of input orders to the ones suitable for use in the vma.
242 * See thp_vma_suitable_order().
243 * All orders that pass the checks are returned as a bitfield.
244 */
thp_vma_suitable_orders(struct vm_area_struct * vma,unsigned long addr,unsigned long orders)245 static inline unsigned long thp_vma_suitable_orders(struct vm_area_struct *vma,
246 unsigned long addr, unsigned long orders)
247 {
248 int order;
249
250 /*
251 * Iterate over orders, highest to lowest, removing orders that don't
252 * meet alignment requirements from the set. Exit loop at first order
253 * that meets requirements, since all lower orders must also meet
254 * requirements.
255 */
256
257 order = highest_order(orders);
258
259 while (orders) {
260 if (thp_vma_suitable_order(vma, addr, order))
261 break;
262 order = next_order(&orders, order);
263 }
264
265 return orders;
266 }
267
268 unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
269 vm_flags_t vm_flags,
270 enum tva_type type,
271 unsigned long orders);
272
273 /**
274 * thp_vma_allowable_orders - determine hugepage orders that are allowed for vma
275 * @vma: the vm area to check
276 * @vm_flags: use these vm_flags instead of vma->vm_flags
277 * @type: TVA type
278 * @orders: bitfield of all orders to consider
279 *
280 * Calculates the intersection of the requested hugepage orders and the allowed
281 * hugepage orders for the provided vma. Permitted orders are encoded as a set
282 * bit at the corresponding bit position (bit-2 corresponds to order-2, bit-3
283 * corresponds to order-3, etc). Order-0 is never considered a hugepage order.
284 *
285 * Return: bitfield of orders allowed for hugepage in the vma. 0 if no hugepage
286 * orders are allowed.
287 */
288 static inline
thp_vma_allowable_orders(struct vm_area_struct * vma,vm_flags_t vm_flags,enum tva_type type,unsigned long orders)289 unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma,
290 vm_flags_t vm_flags,
291 enum tva_type type,
292 unsigned long orders)
293 {
294 /*
295 * Optimization to check if required orders are enabled early. Only
296 * forced collapse ignores sysfs configs.
297 */
298 if (type != TVA_FORCED_COLLAPSE && vma_is_anonymous(vma)) {
299 unsigned long mask = READ_ONCE(huge_anon_orders_always);
300
301 if (vm_flags & VM_HUGEPAGE)
302 mask |= READ_ONCE(huge_anon_orders_madvise);
303 if (hugepage_global_always() ||
304 ((vm_flags & VM_HUGEPAGE) && hugepage_global_enabled()))
305 mask |= READ_ONCE(huge_anon_orders_inherit);
306
307 orders &= mask;
308 if (!orders)
309 return 0;
310 }
311
312 return __thp_vma_allowable_orders(vma, vm_flags, type, orders);
313 }
314
315 struct thpsize {
316 struct kobject kobj;
317 struct list_head node;
318 int order;
319 };
320
321 #define to_thpsize(kobj) container_of(kobj, struct thpsize, kobj)
322
323 #define transparent_hugepage_use_zero_page() \
324 (transparent_hugepage_flags & \
325 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
326
327 /*
328 * Check whether THPs are explicitly disabled for this VMA, for example,
329 * through madvise or prctl.
330 */
vma_thp_disabled(struct vm_area_struct * vma,vm_flags_t vm_flags,bool forced_collapse)331 static inline bool vma_thp_disabled(struct vm_area_struct *vma,
332 vm_flags_t vm_flags, bool forced_collapse)
333 {
334 /* Are THPs disabled for this VMA? */
335 if (vm_flags & VM_NOHUGEPAGE)
336 return true;
337 /* Are THPs disabled for all VMAs in the whole process? */
338 if (mm_flags_test(MMF_DISABLE_THP_COMPLETELY, vma->vm_mm))
339 return true;
340 /*
341 * Are THPs disabled only for VMAs where we didn't get an explicit
342 * advise to use them?
343 */
344 if (vm_flags & VM_HUGEPAGE)
345 return false;
346 /*
347 * Forcing a collapse (e.g., madv_collapse), is a clear advice to
348 * use THPs.
349 */
350 if (forced_collapse)
351 return false;
352 return mm_flags_test(MMF_DISABLE_THP_EXCEPT_ADVISED, vma->vm_mm);
353 }
354
thp_disabled_by_hw(void)355 static inline bool thp_disabled_by_hw(void)
356 {
357 /* If the hardware/firmware marked hugepage support disabled. */
358 return transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED);
359 }
360
361 unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr,
362 unsigned long len, unsigned long pgoff, unsigned long flags);
363 unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr,
364 unsigned long len, unsigned long pgoff, unsigned long flags,
365 vm_flags_t vm_flags);
366
367 bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins);
368 int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
369 unsigned int new_order);
370 int min_order_for_split(struct folio *folio);
371 int split_folio_to_list(struct folio *folio, struct list_head *list);
372 bool uniform_split_supported(struct folio *folio, unsigned int new_order,
373 bool warns);
374 bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
375 bool warns);
376 int folio_split(struct folio *folio, unsigned int new_order, struct page *page,
377 struct list_head *list);
378 /*
379 * try_folio_split - try to split a @folio at @page using non uniform split.
380 * @folio: folio to be split
381 * @page: split to order-0 at the given page
382 * @list: store the after-split folios
383 *
384 * Try to split a @folio at @page using non uniform split to order-0, if
385 * non uniform split is not supported, fall back to uniform split.
386 *
387 * Return: 0: split is successful, otherwise split failed.
388 */
try_folio_split(struct folio * folio,struct page * page,struct list_head * list)389 static inline int try_folio_split(struct folio *folio, struct page *page,
390 struct list_head *list)
391 {
392 int ret = min_order_for_split(folio);
393
394 if (ret < 0)
395 return ret;
396
397 if (!non_uniform_split_supported(folio, 0, false))
398 return split_huge_page_to_list_to_order(&folio->page, list,
399 ret);
400 return folio_split(folio, ret, page, list);
401 }
split_huge_page(struct page * page)402 static inline int split_huge_page(struct page *page)
403 {
404 struct folio *folio = page_folio(page);
405 int ret = min_order_for_split(folio);
406
407 if (ret < 0)
408 return ret;
409
410 /*
411 * split_huge_page() locks the page before splitting and
412 * expects the same page that has been split to be locked when
413 * returned. split_folio(page_folio(page)) cannot be used here
414 * because it converts the page to folio and passes the head
415 * page to be split.
416 */
417 return split_huge_page_to_list_to_order(page, NULL, ret);
418 }
419 void deferred_split_folio(struct folio *folio, bool partially_mapped);
420
421 void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
422 unsigned long address, bool freeze);
423
424 #define split_huge_pmd(__vma, __pmd, __address) \
425 do { \
426 pmd_t *____pmd = (__pmd); \
427 if (is_swap_pmd(*____pmd) || pmd_trans_huge(*____pmd)) \
428 __split_huge_pmd(__vma, __pmd, __address, \
429 false); \
430 } while (0)
431
432 void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address,
433 bool freeze);
434
435 void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud,
436 unsigned long address);
437
438 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
439 int change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma,
440 pud_t *pudp, unsigned long addr, pgprot_t newprot,
441 unsigned long cp_flags);
442 #else
443 static inline int
change_huge_pud(struct mmu_gather * tlb,struct vm_area_struct * vma,pud_t * pudp,unsigned long addr,pgprot_t newprot,unsigned long cp_flags)444 change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma,
445 pud_t *pudp, unsigned long addr, pgprot_t newprot,
446 unsigned long cp_flags) { return 0; }
447 #endif
448
449 #define split_huge_pud(__vma, __pud, __address) \
450 do { \
451 pud_t *____pud = (__pud); \
452 if (pud_trans_huge(*____pud)) \
453 __split_huge_pud(__vma, __pud, __address); \
454 } while (0)
455
456 int hugepage_madvise(struct vm_area_struct *vma, vm_flags_t *vm_flags,
457 int advice);
458 int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
459 unsigned long end, bool *lock_dropped);
460 void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start,
461 unsigned long end, struct vm_area_struct *next);
462 spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma);
463 spinlock_t *__pud_trans_huge_lock(pud_t *pud, struct vm_area_struct *vma);
464
is_swap_pmd(pmd_t pmd)465 static inline int is_swap_pmd(pmd_t pmd)
466 {
467 return !pmd_none(pmd) && !pmd_present(pmd);
468 }
469
470 /* mmap_lock must be held on entry */
pmd_trans_huge_lock(pmd_t * pmd,struct vm_area_struct * vma)471 static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
472 struct vm_area_struct *vma)
473 {
474 if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd))
475 return __pmd_trans_huge_lock(pmd, vma);
476 else
477 return NULL;
478 }
pud_trans_huge_lock(pud_t * pud,struct vm_area_struct * vma)479 static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
480 struct vm_area_struct *vma)
481 {
482 if (pud_trans_huge(*pud))
483 return __pud_trans_huge_lock(pud, vma);
484 else
485 return NULL;
486 }
487
488 /**
489 * folio_test_pmd_mappable - Can we map this folio with a PMD?
490 * @folio: The folio to test
491 */
folio_test_pmd_mappable(struct folio * folio)492 static inline bool folio_test_pmd_mappable(struct folio *folio)
493 {
494 return folio_order(folio) >= HPAGE_PMD_ORDER;
495 }
496
497 vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf);
498
499 extern struct folio *huge_zero_folio;
500 extern unsigned long huge_zero_pfn;
501
is_huge_zero_folio(const struct folio * folio)502 static inline bool is_huge_zero_folio(const struct folio *folio)
503 {
504 VM_WARN_ON_ONCE(!folio);
505
506 return READ_ONCE(huge_zero_folio) == folio;
507 }
508
is_huge_zero_pfn(unsigned long pfn)509 static inline bool is_huge_zero_pfn(unsigned long pfn)
510 {
511 return READ_ONCE(huge_zero_pfn) == (pfn & ~(HPAGE_PMD_NR - 1));
512 }
513
is_huge_zero_pmd(pmd_t pmd)514 static inline bool is_huge_zero_pmd(pmd_t pmd)
515 {
516 return pmd_present(pmd) && is_huge_zero_pfn(pmd_pfn(pmd));
517 }
518
519 struct folio *mm_get_huge_zero_folio(struct mm_struct *mm);
520 void mm_put_huge_zero_folio(struct mm_struct *mm);
521
get_persistent_huge_zero_folio(void)522 static inline struct folio *get_persistent_huge_zero_folio(void)
523 {
524 if (!IS_ENABLED(CONFIG_PERSISTENT_HUGE_ZERO_FOLIO))
525 return NULL;
526
527 if (unlikely(!huge_zero_folio))
528 return NULL;
529
530 return huge_zero_folio;
531 }
532
thp_migration_supported(void)533 static inline bool thp_migration_supported(void)
534 {
535 return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
536 }
537
538 void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address,
539 pmd_t *pmd, bool freeze);
540 bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,
541 pmd_t *pmdp, struct folio *folio);
542
543 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
544
folio_test_pmd_mappable(struct folio * folio)545 static inline bool folio_test_pmd_mappable(struct folio *folio)
546 {
547 return false;
548 }
549
thp_vma_suitable_order(struct vm_area_struct * vma,unsigned long addr,int order)550 static inline bool thp_vma_suitable_order(struct vm_area_struct *vma,
551 unsigned long addr, int order)
552 {
553 return false;
554 }
555
thp_vma_suitable_orders(struct vm_area_struct * vma,unsigned long addr,unsigned long orders)556 static inline unsigned long thp_vma_suitable_orders(struct vm_area_struct *vma,
557 unsigned long addr, unsigned long orders)
558 {
559 return 0;
560 }
561
thp_vma_allowable_orders(struct vm_area_struct * vma,vm_flags_t vm_flags,enum tva_type type,unsigned long orders)562 static inline unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma,
563 vm_flags_t vm_flags,
564 enum tva_type type,
565 unsigned long orders)
566 {
567 return 0;
568 }
569
570 #define transparent_hugepage_flags 0UL
571
572 #define thp_get_unmapped_area NULL
573
574 static inline unsigned long
thp_get_unmapped_area_vmflags(struct file * filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags,vm_flags_t vm_flags)575 thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr,
576 unsigned long len, unsigned long pgoff,
577 unsigned long flags, vm_flags_t vm_flags)
578 {
579 return 0;
580 }
581
582 static inline bool
can_split_folio(struct folio * folio,int caller_pins,int * pextra_pins)583 can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins)
584 {
585 return false;
586 }
587 static inline int
split_huge_page_to_list_to_order(struct page * page,struct list_head * list,unsigned int new_order)588 split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
589 unsigned int new_order)
590 {
591 VM_WARN_ON_ONCE_PAGE(1, page);
592 return -EINVAL;
593 }
split_huge_page(struct page * page)594 static inline int split_huge_page(struct page *page)
595 {
596 VM_WARN_ON_ONCE_PAGE(1, page);
597 return -EINVAL;
598 }
599
split_folio_to_list(struct folio * folio,struct list_head * list)600 static inline int split_folio_to_list(struct folio *folio, struct list_head *list)
601 {
602 VM_WARN_ON_ONCE_FOLIO(1, folio);
603 return -EINVAL;
604 }
605
try_folio_split(struct folio * folio,struct page * page,struct list_head * list)606 static inline int try_folio_split(struct folio *folio, struct page *page,
607 struct list_head *list)
608 {
609 VM_WARN_ON_ONCE_FOLIO(1, folio);
610 return -EINVAL;
611 }
612
deferred_split_folio(struct folio * folio,bool partially_mapped)613 static inline void deferred_split_folio(struct folio *folio, bool partially_mapped) {}
614 #define split_huge_pmd(__vma, __pmd, __address) \
615 do { } while (0)
616
__split_huge_pmd(struct vm_area_struct * vma,pmd_t * pmd,unsigned long address,bool freeze)617 static inline void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
618 unsigned long address, bool freeze) {}
split_huge_pmd_address(struct vm_area_struct * vma,unsigned long address,bool freeze)619 static inline void split_huge_pmd_address(struct vm_area_struct *vma,
620 unsigned long address, bool freeze) {}
split_huge_pmd_locked(struct vm_area_struct * vma,unsigned long address,pmd_t * pmd,bool freeze)621 static inline void split_huge_pmd_locked(struct vm_area_struct *vma,
622 unsigned long address, pmd_t *pmd,
623 bool freeze) {}
624
unmap_huge_pmd_locked(struct vm_area_struct * vma,unsigned long addr,pmd_t * pmdp,struct folio * folio)625 static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma,
626 unsigned long addr, pmd_t *pmdp,
627 struct folio *folio)
628 {
629 return false;
630 }
631
632 #define split_huge_pud(__vma, __pmd, __address) \
633 do { } while (0)
634
hugepage_madvise(struct vm_area_struct * vma,vm_flags_t * vm_flags,int advice)635 static inline int hugepage_madvise(struct vm_area_struct *vma,
636 vm_flags_t *vm_flags, int advice)
637 {
638 return -EINVAL;
639 }
640
madvise_collapse(struct vm_area_struct * vma,unsigned long start,unsigned long end,bool * lock_dropped)641 static inline int madvise_collapse(struct vm_area_struct *vma,
642 unsigned long start,
643 unsigned long end, bool *lock_dropped)
644 {
645 return -EINVAL;
646 }
647
vma_adjust_trans_huge(struct vm_area_struct * vma,unsigned long start,unsigned long end,struct vm_area_struct * next)648 static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
649 unsigned long start,
650 unsigned long end,
651 struct vm_area_struct *next)
652 {
653 }
is_swap_pmd(pmd_t pmd)654 static inline int is_swap_pmd(pmd_t pmd)
655 {
656 return 0;
657 }
pmd_trans_huge_lock(pmd_t * pmd,struct vm_area_struct * vma)658 static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
659 struct vm_area_struct *vma)
660 {
661 return NULL;
662 }
pud_trans_huge_lock(pud_t * pud,struct vm_area_struct * vma)663 static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
664 struct vm_area_struct *vma)
665 {
666 return NULL;
667 }
668
do_huge_pmd_numa_page(struct vm_fault * vmf)669 static inline vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)
670 {
671 return 0;
672 }
673
is_huge_zero_folio(const struct folio * folio)674 static inline bool is_huge_zero_folio(const struct folio *folio)
675 {
676 return false;
677 }
678
is_huge_zero_pfn(unsigned long pfn)679 static inline bool is_huge_zero_pfn(unsigned long pfn)
680 {
681 return false;
682 }
683
is_huge_zero_pmd(pmd_t pmd)684 static inline bool is_huge_zero_pmd(pmd_t pmd)
685 {
686 return false;
687 }
688
mm_put_huge_zero_folio(struct mm_struct * mm)689 static inline void mm_put_huge_zero_folio(struct mm_struct *mm)
690 {
691 return;
692 }
693
follow_devmap_pmd(struct vm_area_struct * vma,unsigned long addr,pmd_t * pmd,int flags,struct dev_pagemap ** pgmap)694 static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma,
695 unsigned long addr, pmd_t *pmd, int flags, struct dev_pagemap **pgmap)
696 {
697 return NULL;
698 }
699
thp_migration_supported(void)700 static inline bool thp_migration_supported(void)
701 {
702 return false;
703 }
704
highest_order(unsigned long orders)705 static inline int highest_order(unsigned long orders)
706 {
707 return 0;
708 }
709
next_order(unsigned long * orders,int prev)710 static inline int next_order(unsigned long *orders, int prev)
711 {
712 return 0;
713 }
714
__split_huge_pud(struct vm_area_struct * vma,pud_t * pud,unsigned long address)715 static inline void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud,
716 unsigned long address)
717 {
718 }
719
change_huge_pud(struct mmu_gather * tlb,struct vm_area_struct * vma,pud_t * pudp,unsigned long addr,pgprot_t newprot,unsigned long cp_flags)720 static inline int change_huge_pud(struct mmu_gather *tlb,
721 struct vm_area_struct *vma, pud_t *pudp,
722 unsigned long addr, pgprot_t newprot,
723 unsigned long cp_flags)
724 {
725 return 0;
726 }
727
get_persistent_huge_zero_folio(void)728 static inline struct folio *get_persistent_huge_zero_folio(void)
729 {
730 return NULL;
731 }
732 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
733
split_folio_to_list_to_order(struct folio * folio,struct list_head * list,int new_order)734 static inline int split_folio_to_list_to_order(struct folio *folio,
735 struct list_head *list, int new_order)
736 {
737 return split_huge_page_to_list_to_order(&folio->page, list, new_order);
738 }
739
split_folio_to_order(struct folio * folio,int new_order)740 static inline int split_folio_to_order(struct folio *folio, int new_order)
741 {
742 return split_folio_to_list_to_order(folio, NULL, new_order);
743 }
744
745 /**
746 * largest_zero_folio - Get the largest zero size folio available
747 *
748 * This function shall be used when mm_get_huge_zero_folio() cannot be
749 * used as there is no appropriate mm lifetime to tie the huge zero folio
750 * from the caller.
751 *
752 * Deduce the size of the folio with folio_size instead of assuming the
753 * folio size.
754 *
755 * Return: pointer to PMD sized zero folio if CONFIG_PERSISTENT_HUGE_ZERO_FOLIO
756 * is enabled or a single page sized zero folio
757 */
largest_zero_folio(void)758 static inline struct folio *largest_zero_folio(void)
759 {
760 struct folio *folio = get_persistent_huge_zero_folio();
761
762 if (folio)
763 return folio;
764
765 return page_folio(ZERO_PAGE(0));
766 }
767 #endif /* _LINUX_HUGE_MM_H */
768