Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
10vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf);
11int 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);
14void huge_pmd_set_accessed(struct vm_fault *vmf);
15int 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
20void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud);
21#else
22static inline void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
23{
24}
25#endif
26
27vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf);
28bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
29 pmd_t *pmd, unsigned long addr, unsigned long next);
30int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, pmd_t *pmd,
31 unsigned long addr);
32int zap_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma, pud_t *pud,
33 unsigned long addr);
34bool 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);
36int 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
40vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn,
41 bool write);
42vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, unsigned long pfn,
43 bool write);
44vm_fault_t vmf_insert_folio_pmd(struct vm_fault *vmf, struct folio *folio,
45 bool write);
46vm_fault_t vmf_insert_folio_pud(struct vm_fault *vmf, struct folio *folio,
47 bool write);
48
49enum 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
61struct kobject;
62struct kobj_attribute;
63
64ssize_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);
68ssize_t single_hugepage_flag_show(struct kobject *kobj,
69 struct kobj_attribute *attr, char *buf,
70 enum transparent_hugepage_flag flag);
71extern struct kobj_attribute shmem_enabled_attr;
72extern 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
97enum 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
127enum 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)
149struct mthp_stat {
150 unsigned long stats[ilog2(MAX_PTRS_PER_PTE) + 1][__MTHP_STAT_COUNT];
151};
152
153DECLARE_PER_CPU(struct mthp_stat, mthp_stats);
154
155static 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
163static inline void count_mthp_stat(int order, enum mthp_stat_item item)
164{
165 mod_mthp_stat(order, item, 1);
166}
167
168#else
169static inline void mod_mthp_stat(int order, enum mthp_stat_item item, int delta)
170{
171}
172
173static inline void count_mthp_stat(int order, enum mthp_stat_item item)
174{
175}
176#endif
177
178#ifdef CONFIG_TRANSPARENT_HUGEPAGE
179
180extern unsigned long transparent_hugepage_flags;
181extern unsigned long huge_anon_orders_always;
182extern unsigned long huge_anon_orders_madvise;
183extern unsigned long huge_anon_orders_inherit;
184
185static 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
192static inline bool hugepage_global_always(void)
193{
194 return transparent_hugepage_flags &
195 (1<<TRANSPARENT_HUGEPAGE_FLAG);
196}
197
198static inline int highest_order(unsigned long orders)
199{
200 return fls_long(orders) - 1;
201}
202
203static 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 */
220static 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 */
245static 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
268unsigned 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 */
288static inline
289unsigned 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
315struct 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 */
331static 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
355static 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
361unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr,
362 unsigned long len, unsigned long pgoff, unsigned long flags);
363unsigned 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
367bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins);
368int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
369 unsigned int new_order);
370int min_order_for_split(struct folio *folio);
371int split_folio_to_list(struct folio *folio, struct list_head *list);
372bool uniform_split_supported(struct folio *folio, unsigned int new_order,
373 bool warns);
374bool non_uniform_split_supported(struct folio *folio, unsigned int new_order,
375 bool warns);
376int folio_split(struct folio *folio, unsigned int new_order, struct page *page,
377 struct list_head *list);
378/*
379 * try_folio_split_to_order - try to split a @folio at @page to @new_order using
380 * non uniform split.
381 * @folio: folio to be split
382 * @page: split to @new_order at the given page
383 * @new_order: the target split order
384 *
385 * Try to split a @folio at @page using non uniform split to @new_order, if
386 * non uniform split is not supported, fall back to uniform split. After-split
387 * folios are put back to LRU list. Use min_order_for_split() to get the lower
388 * bound of @new_order.
389 *
390 * Return: 0: split is successful, otherwise split failed.
391 */
392static inline int try_folio_split_to_order(struct folio *folio,
393 struct page *page, unsigned int new_order)
394{
395 if (!non_uniform_split_supported(folio, new_order, /* warns= */ false))
396 return split_huge_page_to_list_to_order(&folio->page, NULL,
397 new_order);
398 return folio_split(folio, new_order, page, NULL);
399}
400static inline int split_huge_page(struct page *page)
401{
402 return split_huge_page_to_list_to_order(page, NULL, 0);
403}
404void deferred_split_folio(struct folio *folio, bool partially_mapped);
405
406void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
407 unsigned long address, bool freeze);
408
409#define split_huge_pmd(__vma, __pmd, __address) \
410 do { \
411 pmd_t *____pmd = (__pmd); \
412 if (is_swap_pmd(*____pmd) || pmd_trans_huge(*____pmd)) \
413 __split_huge_pmd(__vma, __pmd, __address, \
414 false); \
415 } while (0)
416
417void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address,
418 bool freeze);
419
420void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud,
421 unsigned long address);
422
423#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
424int change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma,
425 pud_t *pudp, unsigned long addr, pgprot_t newprot,
426 unsigned long cp_flags);
427#else
428static inline int
429change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma,
430 pud_t *pudp, unsigned long addr, pgprot_t newprot,
431 unsigned long cp_flags) { return 0; }
432#endif
433
434#define split_huge_pud(__vma, __pud, __address) \
435 do { \
436 pud_t *____pud = (__pud); \
437 if (pud_trans_huge(*____pud)) \
438 __split_huge_pud(__vma, __pud, __address); \
439 } while (0)
440
441int hugepage_madvise(struct vm_area_struct *vma, vm_flags_t *vm_flags,
442 int advice);
443int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
444 unsigned long end, bool *lock_dropped);
445void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start,
446 unsigned long end, struct vm_area_struct *next);
447spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma);
448spinlock_t *__pud_trans_huge_lock(pud_t *pud, struct vm_area_struct *vma);
449
450static inline int is_swap_pmd(pmd_t pmd)
451{
452 return !pmd_none(pmd) && !pmd_present(pmd);
453}
454
455/* mmap_lock must be held on entry */
456static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
457 struct vm_area_struct *vma)
458{
459 if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd))
460 return __pmd_trans_huge_lock(pmd, vma);
461 else
462 return NULL;
463}
464static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
465 struct vm_area_struct *vma)
466{
467 if (pud_trans_huge(*pud))
468 return __pud_trans_huge_lock(pud, vma);
469 else
470 return NULL;
471}
472
473/**
474 * folio_test_pmd_mappable - Can we map this folio with a PMD?
475 * @folio: The folio to test
476 */
477static inline bool folio_test_pmd_mappable(struct folio *folio)
478{
479 return folio_order(folio) >= HPAGE_PMD_ORDER;
480}
481
482vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf);
483
484extern struct folio *huge_zero_folio;
485extern unsigned long huge_zero_pfn;
486
487static inline bool is_huge_zero_folio(const struct folio *folio)
488{
489 VM_WARN_ON_ONCE(!folio);
490
491 return READ_ONCE(huge_zero_folio) == folio;
492}
493
494static inline bool is_huge_zero_pfn(unsigned long pfn)
495{
496 return READ_ONCE(huge_zero_pfn) == (pfn & ~(HPAGE_PMD_NR - 1));
497}
498
499static inline bool is_huge_zero_pmd(pmd_t pmd)
500{
501 return pmd_present(pmd) && is_huge_zero_pfn(pmd_pfn(pmd));
502}
503
504struct folio *mm_get_huge_zero_folio(struct mm_struct *mm);
505void mm_put_huge_zero_folio(struct mm_struct *mm);
506
507static inline struct folio *get_persistent_huge_zero_folio(void)
508{
509 if (!IS_ENABLED(CONFIG_PERSISTENT_HUGE_ZERO_FOLIO))
510 return NULL;
511
512 if (unlikely(!huge_zero_folio))
513 return NULL;
514
515 return huge_zero_folio;
516}
517
518static inline bool thp_migration_supported(void)
519{
520 return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
521}
522
523void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address,
524 pmd_t *pmd, bool freeze);
525bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,
526 pmd_t *pmdp, struct folio *folio);
527
528#else /* CONFIG_TRANSPARENT_HUGEPAGE */
529
530static inline bool folio_test_pmd_mappable(struct folio *folio)
531{
532 return false;
533}
534
535static inline bool thp_vma_suitable_order(struct vm_area_struct *vma,
536 unsigned long addr, int order)
537{
538 return false;
539}
540
541static inline unsigned long thp_vma_suitable_orders(struct vm_area_struct *vma,
542 unsigned long addr, unsigned long orders)
543{
544 return 0;
545}
546
547static inline unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma,
548 vm_flags_t vm_flags,
549 enum tva_type type,
550 unsigned long orders)
551{
552 return 0;
553}
554
555#define transparent_hugepage_flags 0UL
556
557#define thp_get_unmapped_area NULL
558
559static inline unsigned long
560thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr,
561 unsigned long len, unsigned long pgoff,
562 unsigned long flags, vm_flags_t vm_flags)
563{
564 return 0;
565}
566
567static inline bool
568can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins)
569{
570 return false;
571}
572static inline int
573split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
574 unsigned int new_order)
575{
576 VM_WARN_ON_ONCE_PAGE(1, page);
577 return -EINVAL;
578}
579static inline int split_huge_page(struct page *page)
580{
581 VM_WARN_ON_ONCE_PAGE(1, page);
582 return -EINVAL;
583}
584
585static inline int min_order_for_split(struct folio *folio)
586{
587 VM_WARN_ON_ONCE_FOLIO(1, folio);
588 return -EINVAL;
589}
590
591static inline int split_folio_to_list(struct folio *folio, struct list_head *list)
592{
593 VM_WARN_ON_ONCE_FOLIO(1, folio);
594 return -EINVAL;
595}
596
597static inline int try_folio_split_to_order(struct folio *folio,
598 struct page *page, unsigned int new_order)
599{
600 VM_WARN_ON_ONCE_FOLIO(1, folio);
601 return -EINVAL;
602}
603
604static inline void deferred_split_folio(struct folio *folio, bool partially_mapped) {}
605#define split_huge_pmd(__vma, __pmd, __address) \
606 do { } while (0)
607
608static inline void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
609 unsigned long address, bool freeze) {}
610static inline void split_huge_pmd_address(struct vm_area_struct *vma,
611 unsigned long address, bool freeze) {}
612static inline void split_huge_pmd_locked(struct vm_area_struct *vma,
613 unsigned long address, pmd_t *pmd,
614 bool freeze) {}
615
616static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma,
617 unsigned long addr, pmd_t *pmdp,
618 struct folio *folio)
619{
620 return false;
621}
622
623#define split_huge_pud(__vma, __pmd, __address) \
624 do { } while (0)
625
626static inline int hugepage_madvise(struct vm_area_struct *vma,
627 vm_flags_t *vm_flags, int advice)
628{
629 return -EINVAL;
630}
631
632static inline int madvise_collapse(struct vm_area_struct *vma,
633 unsigned long start,
634 unsigned long end, bool *lock_dropped)
635{
636 return -EINVAL;
637}
638
639static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
640 unsigned long start,
641 unsigned long end,
642 struct vm_area_struct *next)
643{
644}
645static inline int is_swap_pmd(pmd_t pmd)
646{
647 return 0;
648}
649static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
650 struct vm_area_struct *vma)
651{
652 return NULL;
653}
654static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
655 struct vm_area_struct *vma)
656{
657 return NULL;
658}
659
660static inline vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)
661{
662 return 0;
663}
664
665static inline bool is_huge_zero_folio(const struct folio *folio)
666{
667 return false;
668}
669
670static inline bool is_huge_zero_pfn(unsigned long pfn)
671{
672 return false;
673}
674
675static inline bool is_huge_zero_pmd(pmd_t pmd)
676{
677 return false;
678}
679
680static inline void mm_put_huge_zero_folio(struct mm_struct *mm)
681{
682 return;
683}
684
685static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma,
686 unsigned long addr, pmd_t *pmd, int flags, struct dev_pagemap **pgmap)
687{
688 return NULL;
689}
690
691static inline bool thp_migration_supported(void)
692{
693 return false;
694}
695
696static inline int highest_order(unsigned long orders)
697{
698 return 0;
699}
700
701static inline int next_order(unsigned long *orders, int prev)
702{
703 return 0;
704}
705
706static inline void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud,
707 unsigned long address)
708{
709}
710
711static inline int change_huge_pud(struct mmu_gather *tlb,
712 struct vm_area_struct *vma, pud_t *pudp,
713 unsigned long addr, pgprot_t newprot,
714 unsigned long cp_flags)
715{
716 return 0;
717}
718
719static inline struct folio *get_persistent_huge_zero_folio(void)
720{
721 return NULL;
722}
723#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
724
725static inline int split_folio_to_list_to_order(struct folio *folio,
726 struct list_head *list, int new_order)
727{
728 return split_huge_page_to_list_to_order(&folio->page, list, new_order);
729}
730
731static inline int split_folio_to_order(struct folio *folio, int new_order)
732{
733 return split_folio_to_list_to_order(folio, NULL, new_order);
734}
735
736/**
737 * largest_zero_folio - Get the largest zero size folio available
738 *
739 * This function shall be used when mm_get_huge_zero_folio() cannot be
740 * used as there is no appropriate mm lifetime to tie the huge zero folio
741 * from the caller.
742 *
743 * Deduce the size of the folio with folio_size instead of assuming the
744 * folio size.
745 *
746 * Return: pointer to PMD sized zero folio if CONFIG_PERSISTENT_HUGE_ZERO_FOLIO
747 * is enabled or a single page sized zero folio
748 */
749static inline struct folio *largest_zero_folio(void)
750{
751 struct folio *folio = get_persistent_huge_zero_folio();
752
753 if (folio)
754 return folio;
755
756 return page_folio(ZERO_PAGE(0));
757}
758#endif /* _LINUX_HUGE_MM_H */