1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_HUGETLB_H
3 #define _LINUX_HUGETLB_H
5 #include <linux/mm_types.h>
6 #include <linux/mmdebug.h>
8 #include <linux/hugetlb_inline.h>
9 #include <linux/cgroup.h>
10 #include <linux/list.h>
11 #include <linux/kref.h>
12 #include <linux/pgtable.h>
13 #include <linux/gfp.h>
14 #include <linux/userfaultfd_k.h>
21 typedef struct { unsigned long pd; } hugepd_t;
22 #define is_hugepd(hugepd) (0)
23 #define __hugepd(x) ((hugepd_t) { (x) })
26 #ifdef CONFIG_HUGETLB_PAGE
28 #include <linux/mempolicy.h>
29 #include <linux/shm.h>
30 #include <asm/tlbflush.h>
33 * For HugeTLB page, there are more metadata to save in the struct page. But
34 * the head struct page cannot meet our needs, so we have to abuse other tail
35 * struct page to store the metadata. In order to avoid conflicts caused by
36 * subsequent use of more tail struct pages, we gather these discrete indexes
37 * of tail struct page here.
40 SUBPAGE_INDEX_SUBPOOL = 1, /* reuse page->private */
41 #ifdef CONFIG_CGROUP_HUGETLB
42 SUBPAGE_INDEX_CGROUP, /* reuse page->private */
43 SUBPAGE_INDEX_CGROUP_RSVD, /* reuse page->private */
44 __MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD,
46 #ifdef CONFIG_MEMORY_FAILURE
47 SUBPAGE_INDEX_HWPOISON,
52 struct hugepage_subpool {
55 long max_hpages; /* Maximum huge pages or -1 if no maximum. */
56 long used_hpages; /* Used count against maximum, includes */
57 /* both allocated and reserved pages. */
58 struct hstate *hstate;
59 long min_hpages; /* Minimum huge pages or -1 if no minimum. */
60 long rsv_hpages; /* Pages reserved against global pool to */
61 /* satisfy minimum size. */
67 struct list_head regions;
68 long adds_in_progress;
69 struct list_head region_cache;
70 long region_cache_count;
71 #ifdef CONFIG_CGROUP_HUGETLB
73 * On private mappings, the counter to uncharge reservations is stored
74 * here. If these fields are 0, then either the mapping is shared, or
75 * cgroup accounting is disabled for this resv_map.
77 struct page_counter *reservation_counter;
78 unsigned long pages_per_hpage;
79 struct cgroup_subsys_state *css;
84 * Region tracking -- allows tracking of reservations and instantiated pages
85 * across the pages in a mapping.
87 * The region data structures are embedded into a resv_map and protected
88 * by a resv_map's lock. The set of regions within the resv_map represent
89 * reservations for huge pages, or huge pages that have already been
90 * instantiated within the map. The from and to elements are huge page
91 * indices into the associated mapping. from indicates the starting index
92 * of the region. to represents the first index past the end of the region.
94 * For example, a file region structure with from == 0 and to == 4 represents
95 * four huge pages in a mapping. It is important to note that the to element
96 * represents the first element past the end of the region. This is used in
97 * arithmetic as 4(to) - 0(from) = 4 huge pages in the region.
99 * Interval notation of the form [from, to) will be used to indicate that
100 * the endpoint from is inclusive and to is exclusive.
103 struct list_head link;
106 #ifdef CONFIG_CGROUP_HUGETLB
108 * On shared mappings, each reserved region appears as a struct
109 * file_region in resv_map. These fields hold the info needed to
110 * uncharge each reservation.
112 struct page_counter *reservation_counter;
113 struct cgroup_subsys_state *css;
117 extern struct resv_map *resv_map_alloc(void);
118 void resv_map_release(struct kref *ref);
120 extern spinlock_t hugetlb_lock;
121 extern int hugetlb_max_hstate __read_mostly;
122 #define for_each_hstate(h) \
123 for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++)
125 struct hugepage_subpool *hugepage_new_subpool(struct hstate *h, long max_hpages,
127 void hugepage_put_subpool(struct hugepage_subpool *spool);
129 void reset_vma_resv_huge_pages(struct vm_area_struct *vma);
130 void clear_vma_resv_huge_pages(struct vm_area_struct *vma);
131 int hugetlb_sysctl_handler(struct ctl_table *, int, void *, size_t *, loff_t *);
132 int hugetlb_overcommit_handler(struct ctl_table *, int, void *, size_t *,
134 int hugetlb_treat_movable_handler(struct ctl_table *, int, void *, size_t *,
136 int hugetlb_mempolicy_sysctl_handler(struct ctl_table *, int, void *, size_t *,
139 int move_hugetlb_page_tables(struct vm_area_struct *vma,
140 struct vm_area_struct *new_vma,
141 unsigned long old_addr, unsigned long new_addr,
143 int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *,
144 struct vm_area_struct *, struct vm_area_struct *);
145 long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
146 struct page **, struct vm_area_struct **,
147 unsigned long *, unsigned long *, long, unsigned int,
149 void unmap_hugepage_range(struct vm_area_struct *,
150 unsigned long, unsigned long, struct page *,
152 void __unmap_hugepage_range_final(struct mmu_gather *tlb,
153 struct vm_area_struct *vma,
154 unsigned long start, unsigned long end,
155 struct page *ref_page, zap_flags_t zap_flags);
156 void hugetlb_report_meminfo(struct seq_file *);
157 int hugetlb_report_node_meminfo(char *buf, int len, int nid);
158 void hugetlb_show_meminfo_node(int nid);
159 unsigned long hugetlb_total_pages(void);
160 vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
161 unsigned long address, unsigned int flags);
162 #ifdef CONFIG_USERFAULTFD
163 int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte,
164 struct vm_area_struct *dst_vma,
165 unsigned long dst_addr,
166 unsigned long src_addr,
167 enum mcopy_atomic_mode mode,
170 #endif /* CONFIG_USERFAULTFD */
171 bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
172 struct vm_area_struct *vma,
173 vm_flags_t vm_flags);
174 long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
176 int isolate_hugetlb(struct page *page, struct list_head *list);
177 int get_hwpoison_huge_page(struct page *page, bool *hugetlb);
178 int get_huge_page_for_hwpoison(unsigned long pfn, int flags);
179 void putback_active_hugepage(struct page *page);
180 void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason);
181 void free_huge_page(struct page *page);
182 void hugetlb_fix_reserve_counts(struct inode *inode);
183 extern struct mutex *hugetlb_fault_mutex_table;
184 u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx);
186 pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma,
187 unsigned long addr, pud_t *pud);
189 struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage);
191 extern int sysctl_hugetlb_shm_group;
192 extern struct list_head huge_boot_pages;
196 pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
197 unsigned long addr, unsigned long sz);
198 pte_t *huge_pte_offset(struct mm_struct *mm,
199 unsigned long addr, unsigned long sz);
200 unsigned long hugetlb_mask_last_page(struct hstate *h);
201 int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma,
202 unsigned long addr, pte_t *ptep);
203 void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
204 unsigned long *start, unsigned long *end);
205 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
207 struct page *follow_huge_pd(struct vm_area_struct *vma,
208 unsigned long address, hugepd_t hpd,
209 int flags, int pdshift);
210 struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
211 pmd_t *pmd, int flags);
212 struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
213 pud_t *pud, int flags);
214 struct page *follow_huge_pgd(struct mm_struct *mm, unsigned long address,
215 pgd_t *pgd, int flags);
217 int pmd_huge(pmd_t pmd);
218 int pud_huge(pud_t pud);
219 unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
220 unsigned long address, unsigned long end, pgprot_t newprot,
221 unsigned long cp_flags);
223 bool is_hugetlb_entry_migration(pte_t pte);
224 void hugetlb_unshare_all_pmds(struct vm_area_struct *vma);
226 #else /* !CONFIG_HUGETLB_PAGE */
228 static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
232 static inline void clear_vma_resv_huge_pages(struct vm_area_struct *vma)
236 static inline unsigned long hugetlb_total_pages(void)
241 static inline struct address_space *hugetlb_page_mapping_lock_write(
247 static inline int huge_pmd_unshare(struct mm_struct *mm,
248 struct vm_area_struct *vma,
249 unsigned long addr, pte_t *ptep)
254 static inline void adjust_range_if_pmd_sharing_possible(
255 struct vm_area_struct *vma,
256 unsigned long *start, unsigned long *end)
260 static inline long follow_hugetlb_page(struct mm_struct *mm,
261 struct vm_area_struct *vma, struct page **pages,
262 struct vm_area_struct **vmas, unsigned long *position,
263 unsigned long *nr_pages, long i, unsigned int flags,
270 static inline struct page *follow_huge_addr(struct mm_struct *mm,
271 unsigned long address, int write)
273 return ERR_PTR(-EINVAL);
276 static inline int copy_hugetlb_page_range(struct mm_struct *dst,
277 struct mm_struct *src,
278 struct vm_area_struct *dst_vma,
279 struct vm_area_struct *src_vma)
285 static inline int move_hugetlb_page_tables(struct vm_area_struct *vma,
286 struct vm_area_struct *new_vma,
287 unsigned long old_addr,
288 unsigned long new_addr,
295 static inline void hugetlb_report_meminfo(struct seq_file *m)
299 static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid)
304 static inline void hugetlb_show_meminfo_node(int nid)
308 static inline struct page *follow_huge_pd(struct vm_area_struct *vma,
309 unsigned long address, hugepd_t hpd, int flags,
315 static inline struct page *follow_huge_pmd(struct mm_struct *mm,
316 unsigned long address, pmd_t *pmd, int flags)
321 static inline struct page *follow_huge_pud(struct mm_struct *mm,
322 unsigned long address, pud_t *pud, int flags)
327 static inline struct page *follow_huge_pgd(struct mm_struct *mm,
328 unsigned long address, pgd_t *pgd, int flags)
333 static inline int prepare_hugepage_range(struct file *file,
334 unsigned long addr, unsigned long len)
339 static inline int pmd_huge(pmd_t pmd)
344 static inline int pud_huge(pud_t pud)
349 static inline int is_hugepage_only_range(struct mm_struct *mm,
350 unsigned long addr, unsigned long len)
355 static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
356 unsigned long addr, unsigned long end,
357 unsigned long floor, unsigned long ceiling)
362 #ifdef CONFIG_USERFAULTFD
363 static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
365 struct vm_area_struct *dst_vma,
366 unsigned long dst_addr,
367 unsigned long src_addr,
368 enum mcopy_atomic_mode mode,
375 #endif /* CONFIG_USERFAULTFD */
377 static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
383 static inline int isolate_hugetlb(struct page *page, struct list_head *list)
388 static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb)
393 static inline int get_huge_page_for_hwpoison(unsigned long pfn, int flags)
398 static inline void putback_active_hugepage(struct page *page)
402 static inline void move_hugetlb_state(struct page *oldpage,
403 struct page *newpage, int reason)
407 static inline unsigned long hugetlb_change_protection(
408 struct vm_area_struct *vma, unsigned long address,
409 unsigned long end, pgprot_t newprot,
410 unsigned long cp_flags)
415 static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb,
416 struct vm_area_struct *vma, unsigned long start,
417 unsigned long end, struct page *ref_page,
418 zap_flags_t zap_flags)
423 static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,
424 struct vm_area_struct *vma, unsigned long address,
431 static inline void hugetlb_unshare_all_pmds(struct vm_area_struct *vma) { }
433 #endif /* !CONFIG_HUGETLB_PAGE */
435 * hugepages at page global directory. If arch support
436 * hugepages at pgd level, they need to define this.
439 #define pgd_huge(x) 0
442 #define p4d_huge(x) 0
446 static inline int pgd_write(pgd_t pgd)
453 #define HUGETLB_ANON_FILE "anon_hugepage"
457 * The file will be used as an shm file so shmfs accounting rules
460 HUGETLB_SHMFS_INODE = 1,
462 * The file is being created on the internal vfs mount and shmfs
463 * accounting rules do not apply
465 HUGETLB_ANONHUGE_INODE = 2,
468 #ifdef CONFIG_HUGETLBFS
469 struct hugetlbfs_sb_info {
470 long max_inodes; /* inodes allowed */
471 long free_inodes; /* inodes free */
472 spinlock_t stat_lock;
473 struct hstate *hstate;
474 struct hugepage_subpool *spool;
480 static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
482 return sb->s_fs_info;
485 struct hugetlbfs_inode_info {
486 struct shared_policy policy;
487 struct inode vfs_inode;
491 static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
493 return container_of(inode, struct hugetlbfs_inode_info, vfs_inode);
496 extern const struct file_operations hugetlbfs_file_operations;
497 extern const struct vm_operations_struct hugetlb_vm_ops;
498 struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
499 int creat_flags, int page_size_log);
501 static inline bool is_file_hugepages(struct file *file)
503 if (file->f_op == &hugetlbfs_file_operations)
506 return is_file_shm_hugepages(file);
509 static inline struct hstate *hstate_inode(struct inode *i)
511 return HUGETLBFS_SB(i->i_sb)->hstate;
513 #else /* !CONFIG_HUGETLBFS */
515 #define is_file_hugepages(file) false
516 static inline struct file *
517 hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag,
518 int creat_flags, int page_size_log)
520 return ERR_PTR(-ENOSYS);
523 static inline struct hstate *hstate_inode(struct inode *i)
527 #endif /* !CONFIG_HUGETLBFS */
529 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
530 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
531 unsigned long len, unsigned long pgoff,
532 unsigned long flags);
533 #endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
536 generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
537 unsigned long len, unsigned long pgoff,
538 unsigned long flags);
541 * huegtlb page specific state flags. These flags are located in page.private
542 * of the hugetlb head page. Functions created via the below macros should be
543 * used to manipulate these flags.
545 * HPG_restore_reserve - Set when a hugetlb page consumes a reservation at
546 * allocation time. Cleared when page is fully instantiated. Free
547 * routine checks flag to restore a reservation on error paths.
548 * Synchronization: Examined or modified by code that knows it has
549 * the only reference to page. i.e. After allocation but before use
550 * or when the page is being freed.
551 * HPG_migratable - Set after a newly allocated page is added to the page
552 * cache and/or page tables. Indicates the page is a candidate for
554 * Synchronization: Initially set after new page allocation with no
555 * locking. When examined and modified during migration processing
556 * (isolate, migrate, putback) the hugetlb_lock is held.
557 * HPG_temporary - Set on a page that is temporarily allocated from the buddy
558 * allocator. Typically used for migration target pages when no pages
559 * are available in the pool. The hugetlb free page path will
560 * immediately free pages with this flag set to the buddy allocator.
561 * Synchronization: Can be set after huge page allocation from buddy when
562 * code knows it has only reference. All other examinations and
563 * modifications require hugetlb_lock.
564 * HPG_freed - Set when page is on the free lists.
565 * Synchronization: hugetlb_lock held for examination and modification.
566 * HPG_vmemmap_optimized - Set when the vmemmap pages of the page are freed.
567 * HPG_raw_hwp_unreliable - Set when the hugetlb page has a hwpoison sub-page
568 * that is not tracked by raw_hwp_page list.
570 enum hugetlb_page_flags {
571 HPG_restore_reserve = 0,
575 HPG_vmemmap_optimized,
576 HPG_raw_hwp_unreliable,
581 * Macros to create test, set and clear function definitions for
582 * hugetlb specific page flags.
584 #ifdef CONFIG_HUGETLB_PAGE
585 #define TESTHPAGEFLAG(uname, flname) \
586 static inline int HPage##uname(struct page *page) \
587 { return test_bit(HPG_##flname, &(page->private)); }
589 #define SETHPAGEFLAG(uname, flname) \
590 static inline void SetHPage##uname(struct page *page) \
591 { set_bit(HPG_##flname, &(page->private)); }
593 #define CLEARHPAGEFLAG(uname, flname) \
594 static inline void ClearHPage##uname(struct page *page) \
595 { clear_bit(HPG_##flname, &(page->private)); }
597 #define TESTHPAGEFLAG(uname, flname) \
598 static inline int HPage##uname(struct page *page) \
601 #define SETHPAGEFLAG(uname, flname) \
602 static inline void SetHPage##uname(struct page *page) \
605 #define CLEARHPAGEFLAG(uname, flname) \
606 static inline void ClearHPage##uname(struct page *page) \
610 #define HPAGEFLAG(uname, flname) \
611 TESTHPAGEFLAG(uname, flname) \
612 SETHPAGEFLAG(uname, flname) \
613 CLEARHPAGEFLAG(uname, flname) \
616 * Create functions associated with hugetlb page flags
618 HPAGEFLAG(RestoreReserve, restore_reserve)
619 HPAGEFLAG(Migratable, migratable)
620 HPAGEFLAG(Temporary, temporary)
621 HPAGEFLAG(Freed, freed)
622 HPAGEFLAG(VmemmapOptimized, vmemmap_optimized)
623 HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable)
625 #ifdef CONFIG_HUGETLB_PAGE
627 #define HSTATE_NAME_LEN 32
628 /* Defines one hugetlb page size */
630 struct mutex resize_lock;
631 int next_nid_to_alloc;
632 int next_nid_to_free;
634 unsigned int demote_order;
636 unsigned long max_huge_pages;
637 unsigned long nr_huge_pages;
638 unsigned long free_huge_pages;
639 unsigned long resv_huge_pages;
640 unsigned long surplus_huge_pages;
641 unsigned long nr_overcommit_huge_pages;
642 struct list_head hugepage_activelist;
643 struct list_head hugepage_freelists[MAX_NUMNODES];
644 unsigned int max_huge_pages_node[MAX_NUMNODES];
645 unsigned int nr_huge_pages_node[MAX_NUMNODES];
646 unsigned int free_huge_pages_node[MAX_NUMNODES];
647 unsigned int surplus_huge_pages_node[MAX_NUMNODES];
648 #ifdef CONFIG_CGROUP_HUGETLB
649 /* cgroup control files */
650 struct cftype cgroup_files_dfl[8];
651 struct cftype cgroup_files_legacy[10];
653 char name[HSTATE_NAME_LEN];
656 struct huge_bootmem_page {
657 struct list_head list;
658 struct hstate *hstate;
661 int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list);
662 struct page *alloc_huge_page(struct vm_area_struct *vma,
663 unsigned long addr, int avoid_reserve);
664 struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
665 nodemask_t *nmask, gfp_t gfp_mask);
666 struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma,
667 unsigned long address);
668 int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
670 void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,
671 unsigned long address, struct page *page);
674 int __init __alloc_bootmem_huge_page(struct hstate *h, int nid);
675 int __init alloc_bootmem_huge_page(struct hstate *h, int nid);
676 bool __init hugetlb_node_alloc_supported(void);
678 void __init hugetlb_add_hstate(unsigned order);
679 bool __init arch_hugetlb_valid_size(unsigned long size);
680 struct hstate *size_to_hstate(unsigned long size);
682 #ifndef HUGE_MAX_HSTATE
683 #define HUGE_MAX_HSTATE 1
686 extern struct hstate hstates[HUGE_MAX_HSTATE];
687 extern unsigned int default_hstate_idx;
689 #define default_hstate (hstates[default_hstate_idx])
692 * hugetlb page subpool pointer located in hpage[1].private
694 static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage)
696 return (void *)page_private(hpage + SUBPAGE_INDEX_SUBPOOL);
699 static inline void hugetlb_set_page_subpool(struct page *hpage,
700 struct hugepage_subpool *subpool)
702 set_page_private(hpage + SUBPAGE_INDEX_SUBPOOL, (unsigned long)subpool);
705 static inline struct hstate *hstate_file(struct file *f)
707 return hstate_inode(file_inode(f));
710 static inline struct hstate *hstate_sizelog(int page_size_log)
713 return &default_hstate;
715 return size_to_hstate(1UL << page_size_log);
718 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
720 return hstate_file(vma->vm_file);
723 static inline unsigned long huge_page_size(const struct hstate *h)
725 return (unsigned long)PAGE_SIZE << h->order;
728 extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
730 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
732 static inline unsigned long huge_page_mask(struct hstate *h)
737 static inline unsigned int huge_page_order(struct hstate *h)
742 static inline unsigned huge_page_shift(struct hstate *h)
744 return h->order + PAGE_SHIFT;
747 static inline bool hstate_is_gigantic(struct hstate *h)
749 return huge_page_order(h) >= MAX_ORDER;
752 static inline unsigned int pages_per_huge_page(const struct hstate *h)
754 return 1 << h->order;
757 static inline unsigned int blocks_per_huge_page(struct hstate *h)
759 return huge_page_size(h) / 512;
762 #include <asm/hugetlb.h>
764 #ifndef is_hugepage_only_range
765 static inline int is_hugepage_only_range(struct mm_struct *mm,
766 unsigned long addr, unsigned long len)
770 #define is_hugepage_only_range is_hugepage_only_range
773 #ifndef arch_clear_hugepage_flags
774 static inline void arch_clear_hugepage_flags(struct page *page) { }
775 #define arch_clear_hugepage_flags arch_clear_hugepage_flags
778 #ifndef arch_make_huge_pte
779 static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift,
782 return pte_mkhuge(entry);
786 static inline struct hstate *page_hstate(struct page *page)
788 VM_BUG_ON_PAGE(!PageHuge(page), page);
789 return size_to_hstate(page_size(page));
792 static inline unsigned hstate_index_to_shift(unsigned index)
794 return hstates[index].order + PAGE_SHIFT;
797 static inline int hstate_index(struct hstate *h)
802 extern int dissolve_free_huge_page(struct page *page);
803 extern int dissolve_free_huge_pages(unsigned long start_pfn,
804 unsigned long end_pfn);
806 #ifdef CONFIG_MEMORY_FAILURE
807 extern void hugetlb_clear_page_hwpoison(struct page *hpage);
809 static inline void hugetlb_clear_page_hwpoison(struct page *hpage)
814 #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
815 #ifndef arch_hugetlb_migration_supported
816 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
818 if ((huge_page_shift(h) == PMD_SHIFT) ||
819 (huge_page_shift(h) == PUD_SHIFT) ||
820 (huge_page_shift(h) == PGDIR_SHIFT))
827 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
833 static inline bool hugepage_migration_supported(struct hstate *h)
835 return arch_hugetlb_migration_supported(h);
839 * Movability check is different as compared to migration check.
840 * It determines whether or not a huge page should be placed on
841 * movable zone or not. Movability of any huge page should be
842 * required only if huge page size is supported for migration.
843 * There won't be any reason for the huge page to be movable if
844 * it is not migratable to start with. Also the size of the huge
845 * page should be large enough to be placed under a movable zone
846 * and still feasible enough to be migratable. Just the presence
847 * in movable zone does not make the migration feasible.
849 * So even though large huge page sizes like the gigantic ones
850 * are migratable they should not be movable because its not
851 * feasible to migrate them from movable zone.
853 static inline bool hugepage_movable_supported(struct hstate *h)
855 if (!hugepage_migration_supported(h))
858 if (hstate_is_gigantic(h))
863 /* Movability of hugepages depends on migration support. */
864 static inline gfp_t htlb_alloc_mask(struct hstate *h)
866 if (hugepage_movable_supported(h))
867 return GFP_HIGHUSER_MOVABLE;
872 static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)
874 gfp_t modified_mask = htlb_alloc_mask(h);
876 /* Some callers might want to enforce node */
877 modified_mask |= (gfp_mask & __GFP_THISNODE);
879 modified_mask |= (gfp_mask & __GFP_NOWARN);
881 return modified_mask;
884 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
885 struct mm_struct *mm, pte_t *pte)
887 if (huge_page_size(h) == PMD_SIZE)
888 return pmd_lockptr(mm, (pmd_t *) pte);
889 VM_BUG_ON(huge_page_size(h) == PAGE_SIZE);
890 return &mm->page_table_lock;
893 #ifndef hugepages_supported
895 * Some platform decide whether they support huge pages at boot
896 * time. Some of them, such as powerpc, set HPAGE_SHIFT to 0
897 * when there is no such support
899 #define hugepages_supported() (HPAGE_SHIFT != 0)
902 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm);
904 static inline void hugetlb_count_init(struct mm_struct *mm)
906 atomic_long_set(&mm->hugetlb_usage, 0);
909 static inline void hugetlb_count_add(long l, struct mm_struct *mm)
911 atomic_long_add(l, &mm->hugetlb_usage);
914 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
916 atomic_long_sub(l, &mm->hugetlb_usage);
919 #ifndef huge_ptep_modify_prot_start
920 #define huge_ptep_modify_prot_start huge_ptep_modify_prot_start
921 static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
922 unsigned long addr, pte_t *ptep)
924 return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
928 #ifndef huge_ptep_modify_prot_commit
929 #define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
930 static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
931 unsigned long addr, pte_t *ptep,
932 pte_t old_pte, pte_t pte)
934 set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
938 #else /* CONFIG_HUGETLB_PAGE */
941 static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage)
946 static inline int isolate_or_dissolve_huge_page(struct page *page,
947 struct list_head *list)
952 static inline struct page *alloc_huge_page(struct vm_area_struct *vma,
959 static inline struct page *
960 alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
961 nodemask_t *nmask, gfp_t gfp_mask)
966 static inline struct page *alloc_huge_page_vma(struct hstate *h,
967 struct vm_area_struct *vma,
968 unsigned long address)
973 static inline int __alloc_bootmem_huge_page(struct hstate *h)
978 static inline struct hstate *hstate_file(struct file *f)
983 static inline struct hstate *hstate_sizelog(int page_size_log)
988 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
993 static inline struct hstate *page_hstate(struct page *page)
998 static inline struct hstate *size_to_hstate(unsigned long size)
1003 static inline unsigned long huge_page_size(struct hstate *h)
1008 static inline unsigned long huge_page_mask(struct hstate *h)
1013 static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
1018 static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
1023 static inline unsigned int huge_page_order(struct hstate *h)
1028 static inline unsigned int huge_page_shift(struct hstate *h)
1033 static inline bool hstate_is_gigantic(struct hstate *h)
1038 static inline unsigned int pages_per_huge_page(struct hstate *h)
1043 static inline unsigned hstate_index_to_shift(unsigned index)
1048 static inline int hstate_index(struct hstate *h)
1053 static inline int dissolve_free_huge_page(struct page *page)
1058 static inline int dissolve_free_huge_pages(unsigned long start_pfn,
1059 unsigned long end_pfn)
1064 static inline bool hugepage_migration_supported(struct hstate *h)
1069 static inline bool hugepage_movable_supported(struct hstate *h)
1074 static inline gfp_t htlb_alloc_mask(struct hstate *h)
1079 static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)
1084 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
1085 struct mm_struct *mm, pte_t *pte)
1087 return &mm->page_table_lock;
1090 static inline void hugetlb_count_init(struct mm_struct *mm)
1094 static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m)
1098 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
1102 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
1103 unsigned long addr, pte_t *ptep)
1108 static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
1109 pte_t *ptep, pte_t pte)
1112 #endif /* CONFIG_HUGETLB_PAGE */
1114 static inline spinlock_t *huge_pte_lock(struct hstate *h,
1115 struct mm_struct *mm, pte_t *pte)
1119 ptl = huge_pte_lockptr(h, mm, pte);
1124 #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
1125 extern void __init hugetlb_cma_reserve(int order);
1126 extern void __init hugetlb_cma_check(void);
1128 static inline __init void hugetlb_cma_reserve(int order)
1131 static inline __init void hugetlb_cma_check(void)
1136 bool want_pmd_share(struct vm_area_struct *vma, unsigned long addr);
1138 #ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE
1140 * ARCHes with special requirements for evicting HUGETLB backing TLB entries can
1143 #define flush_hugetlb_tlb_range(vma, addr, end) flush_tlb_range(vma, addr, end)
1146 #endif /* _LINUX_HUGETLB_H */