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 #ifndef CONFIG_ARCH_HAS_HUGEPD
22 typedef struct { unsigned long pd; } hugepd_t;
23 #define is_hugepd(hugepd) (0)
24 #define __hugepd(x) ((hugepd_t) { (x) })
27 #ifdef CONFIG_HUGETLB_PAGE
29 #include <linux/mempolicy.h>
30 #include <linux/shm.h>
31 #include <asm/tlbflush.h>
34 * For HugeTLB page, there are more metadata to save in the struct page. But
35 * the head struct page cannot meet our needs, so we have to abuse other tail
36 * struct page to store the metadata. In order to avoid conflicts caused by
37 * subsequent use of more tail struct pages, we gather these discrete indexes
38 * of tail struct page here.
41 SUBPAGE_INDEX_SUBPOOL = 1, /* reuse page->private */
42 #ifdef CONFIG_CGROUP_HUGETLB
43 SUBPAGE_INDEX_CGROUP, /* reuse page->private */
44 SUBPAGE_INDEX_CGROUP_RSVD, /* reuse page->private */
45 __MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD,
47 #ifdef CONFIG_MEMORY_FAILURE
48 SUBPAGE_INDEX_HWPOISON,
53 struct hugepage_subpool {
56 long max_hpages; /* Maximum huge pages or -1 if no maximum. */
57 long used_hpages; /* Used count against maximum, includes */
58 /* both allocated and reserved pages. */
59 struct hstate *hstate;
60 long min_hpages; /* Minimum huge pages or -1 if no minimum. */
61 long rsv_hpages; /* Pages reserved against global pool to */
62 /* satisfy minimum size. */
68 struct list_head regions;
69 long adds_in_progress;
70 struct list_head region_cache;
71 long region_cache_count;
72 #ifdef CONFIG_CGROUP_HUGETLB
74 * On private mappings, the counter to uncharge reservations is stored
75 * here. If these fields are 0, then either the mapping is shared, or
76 * cgroup accounting is disabled for this resv_map.
78 struct page_counter *reservation_counter;
79 unsigned long pages_per_hpage;
80 struct cgroup_subsys_state *css;
85 * Region tracking -- allows tracking of reservations and instantiated pages
86 * across the pages in a mapping.
88 * The region data structures are embedded into a resv_map and protected
89 * by a resv_map's lock. The set of regions within the resv_map represent
90 * reservations for huge pages, or huge pages that have already been
91 * instantiated within the map. The from and to elements are huge page
92 * indices into the associated mapping. from indicates the starting index
93 * of the region. to represents the first index past the end of the region.
95 * For example, a file region structure with from == 0 and to == 4 represents
96 * four huge pages in a mapping. It is important to note that the to element
97 * represents the first element past the end of the region. This is used in
98 * arithmetic as 4(to) - 0(from) = 4 huge pages in the region.
100 * Interval notation of the form [from, to) will be used to indicate that
101 * the endpoint from is inclusive and to is exclusive.
104 struct list_head link;
107 #ifdef CONFIG_CGROUP_HUGETLB
109 * On shared mappings, each reserved region appears as a struct
110 * file_region in resv_map. These fields hold the info needed to
111 * uncharge each reservation.
113 struct page_counter *reservation_counter;
114 struct cgroup_subsys_state *css;
118 struct hugetlb_vma_lock {
120 struct rw_semaphore rw_sema;
121 struct vm_area_struct *vma;
124 extern struct resv_map *resv_map_alloc(void);
125 void resv_map_release(struct kref *ref);
127 extern spinlock_t hugetlb_lock;
128 extern int hugetlb_max_hstate __read_mostly;
129 #define for_each_hstate(h) \
130 for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++)
132 struct hugepage_subpool *hugepage_new_subpool(struct hstate *h, long max_hpages,
134 void hugepage_put_subpool(struct hugepage_subpool *spool);
136 void hugetlb_dup_vma_private(struct vm_area_struct *vma);
137 void clear_vma_resv_huge_pages(struct vm_area_struct *vma);
138 int hugetlb_sysctl_handler(struct ctl_table *, int, void *, size_t *, loff_t *);
139 int hugetlb_overcommit_handler(struct ctl_table *, int, void *, size_t *,
141 int hugetlb_treat_movable_handler(struct ctl_table *, int, void *, size_t *,
143 int hugetlb_mempolicy_sysctl_handler(struct ctl_table *, int, void *, size_t *,
146 int move_hugetlb_page_tables(struct vm_area_struct *vma,
147 struct vm_area_struct *new_vma,
148 unsigned long old_addr, unsigned long new_addr,
150 int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *,
151 struct vm_area_struct *, struct vm_area_struct *);
152 long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
153 struct page **, struct vm_area_struct **,
154 unsigned long *, unsigned long *, long, unsigned int,
156 void unmap_hugepage_range(struct vm_area_struct *,
157 unsigned long, unsigned long, struct page *,
159 void __unmap_hugepage_range_final(struct mmu_gather *tlb,
160 struct vm_area_struct *vma,
161 unsigned long start, unsigned long end,
162 struct page *ref_page, zap_flags_t zap_flags);
163 void hugetlb_report_meminfo(struct seq_file *);
164 int hugetlb_report_node_meminfo(char *buf, int len, int nid);
165 void hugetlb_show_meminfo_node(int nid);
166 unsigned long hugetlb_total_pages(void);
167 vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
168 unsigned long address, unsigned int flags);
169 #ifdef CONFIG_USERFAULTFD
170 int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte,
171 struct vm_area_struct *dst_vma,
172 unsigned long dst_addr,
173 unsigned long src_addr,
174 enum mcopy_atomic_mode mode,
177 #endif /* CONFIG_USERFAULTFD */
178 bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
179 struct vm_area_struct *vma,
180 vm_flags_t vm_flags);
181 long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
183 int isolate_hugetlb(struct page *page, struct list_head *list);
184 int get_hwpoison_huge_page(struct page *page, bool *hugetlb);
185 int get_huge_page_for_hwpoison(unsigned long pfn, int flags);
186 void putback_active_hugepage(struct page *page);
187 void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason);
188 void free_huge_page(struct page *page);
189 void hugetlb_fix_reserve_counts(struct inode *inode);
190 extern struct mutex *hugetlb_fault_mutex_table;
191 u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx);
193 pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma,
194 unsigned long addr, pud_t *pud);
196 struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage);
198 extern int sysctl_hugetlb_shm_group;
199 extern struct list_head huge_boot_pages;
203 pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
204 unsigned long addr, unsigned long sz);
205 pte_t *huge_pte_offset(struct mm_struct *mm,
206 unsigned long addr, unsigned long sz);
207 unsigned long hugetlb_mask_last_page(struct hstate *h);
208 int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma,
209 unsigned long addr, pte_t *ptep);
210 void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
211 unsigned long *start, unsigned long *end);
212 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
214 struct page *follow_huge_pd(struct vm_area_struct *vma,
215 unsigned long address, hugepd_t hpd,
216 int flags, int pdshift);
217 struct page *follow_huge_pmd_pte(struct vm_area_struct *vma, unsigned long address,
219 struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
220 pud_t *pud, int flags);
221 struct page *follow_huge_pgd(struct mm_struct *mm, unsigned long address,
222 pgd_t *pgd, int flags);
224 void hugetlb_vma_lock_read(struct vm_area_struct *vma);
225 void hugetlb_vma_unlock_read(struct vm_area_struct *vma);
226 void hugetlb_vma_lock_write(struct vm_area_struct *vma);
227 void hugetlb_vma_unlock_write(struct vm_area_struct *vma);
228 int hugetlb_vma_trylock_write(struct vm_area_struct *vma);
229 void hugetlb_vma_assert_locked(struct vm_area_struct *vma);
230 void hugetlb_vma_lock_release(struct kref *kref);
232 int pmd_huge(pmd_t pmd);
233 int pud_huge(pud_t pud);
234 unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
235 unsigned long address, unsigned long end, pgprot_t newprot,
236 unsigned long cp_flags);
238 bool is_hugetlb_entry_migration(pte_t pte);
239 void hugetlb_unshare_all_pmds(struct vm_area_struct *vma);
241 #else /* !CONFIG_HUGETLB_PAGE */
243 static inline void hugetlb_dup_vma_private(struct vm_area_struct *vma)
247 static inline void clear_vma_resv_huge_pages(struct vm_area_struct *vma)
251 static inline unsigned long hugetlb_total_pages(void)
256 static inline struct address_space *hugetlb_page_mapping_lock_write(
262 static inline int huge_pmd_unshare(struct mm_struct *mm,
263 struct vm_area_struct *vma,
264 unsigned long addr, pte_t *ptep)
269 static inline void adjust_range_if_pmd_sharing_possible(
270 struct vm_area_struct *vma,
271 unsigned long *start, unsigned long *end)
275 static inline long follow_hugetlb_page(struct mm_struct *mm,
276 struct vm_area_struct *vma, struct page **pages,
277 struct vm_area_struct **vmas, unsigned long *position,
278 unsigned long *nr_pages, long i, unsigned int flags,
285 static inline struct page *follow_huge_addr(struct mm_struct *mm,
286 unsigned long address, int write)
288 return ERR_PTR(-EINVAL);
291 static inline int copy_hugetlb_page_range(struct mm_struct *dst,
292 struct mm_struct *src,
293 struct vm_area_struct *dst_vma,
294 struct vm_area_struct *src_vma)
300 static inline int move_hugetlb_page_tables(struct vm_area_struct *vma,
301 struct vm_area_struct *new_vma,
302 unsigned long old_addr,
303 unsigned long new_addr,
310 static inline void hugetlb_report_meminfo(struct seq_file *m)
314 static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid)
319 static inline void hugetlb_show_meminfo_node(int nid)
323 static inline struct page *follow_huge_pd(struct vm_area_struct *vma,
324 unsigned long address, hugepd_t hpd, int flags,
330 static inline struct page *follow_huge_pmd_pte(struct vm_area_struct *vma,
331 unsigned long address, int flags)
336 static inline struct page *follow_huge_pud(struct mm_struct *mm,
337 unsigned long address, pud_t *pud, int flags)
342 static inline struct page *follow_huge_pgd(struct mm_struct *mm,
343 unsigned long address, pgd_t *pgd, int flags)
348 static inline int prepare_hugepage_range(struct file *file,
349 unsigned long addr, unsigned long len)
354 static inline void hugetlb_vma_lock_read(struct vm_area_struct *vma)
358 static inline void hugetlb_vma_unlock_read(struct vm_area_struct *vma)
362 static inline void hugetlb_vma_lock_write(struct vm_area_struct *vma)
366 static inline void hugetlb_vma_unlock_write(struct vm_area_struct *vma)
370 static inline int hugetlb_vma_trylock_write(struct vm_area_struct *vma)
375 static inline void hugetlb_vma_assert_locked(struct vm_area_struct *vma)
379 static inline int pmd_huge(pmd_t pmd)
384 static inline int pud_huge(pud_t pud)
389 static inline int is_hugepage_only_range(struct mm_struct *mm,
390 unsigned long addr, unsigned long len)
395 static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
396 unsigned long addr, unsigned long end,
397 unsigned long floor, unsigned long ceiling)
402 #ifdef CONFIG_USERFAULTFD
403 static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
405 struct vm_area_struct *dst_vma,
406 unsigned long dst_addr,
407 unsigned long src_addr,
408 enum mcopy_atomic_mode mode,
415 #endif /* CONFIG_USERFAULTFD */
417 static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
423 static inline int isolate_hugetlb(struct page *page, struct list_head *list)
428 static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb)
433 static inline int get_huge_page_for_hwpoison(unsigned long pfn, int flags)
438 static inline void putback_active_hugepage(struct page *page)
442 static inline void move_hugetlb_state(struct page *oldpage,
443 struct page *newpage, int reason)
447 static inline unsigned long hugetlb_change_protection(
448 struct vm_area_struct *vma, unsigned long address,
449 unsigned long end, pgprot_t newprot,
450 unsigned long cp_flags)
455 static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb,
456 struct vm_area_struct *vma, unsigned long start,
457 unsigned long end, struct page *ref_page,
458 zap_flags_t zap_flags)
463 static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,
464 struct vm_area_struct *vma, unsigned long address,
471 static inline void hugetlb_unshare_all_pmds(struct vm_area_struct *vma) { }
473 #endif /* !CONFIG_HUGETLB_PAGE */
475 * hugepages at page global directory. If arch support
476 * hugepages at pgd level, they need to define this.
479 #define pgd_huge(x) 0
482 #define p4d_huge(x) 0
486 static inline int pgd_write(pgd_t pgd)
493 #define HUGETLB_ANON_FILE "anon_hugepage"
497 * The file will be used as an shm file so shmfs accounting rules
500 HUGETLB_SHMFS_INODE = 1,
502 * The file is being created on the internal vfs mount and shmfs
503 * accounting rules do not apply
505 HUGETLB_ANONHUGE_INODE = 2,
508 #ifdef CONFIG_HUGETLBFS
509 struct hugetlbfs_sb_info {
510 long max_inodes; /* inodes allowed */
511 long free_inodes; /* inodes free */
512 spinlock_t stat_lock;
513 struct hstate *hstate;
514 struct hugepage_subpool *spool;
520 static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
522 return sb->s_fs_info;
525 struct hugetlbfs_inode_info {
526 struct shared_policy policy;
527 struct inode vfs_inode;
531 static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
533 return container_of(inode, struct hugetlbfs_inode_info, vfs_inode);
536 extern const struct file_operations hugetlbfs_file_operations;
537 extern const struct vm_operations_struct hugetlb_vm_ops;
538 struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
539 int creat_flags, int page_size_log);
541 static inline bool is_file_hugepages(struct file *file)
543 if (file->f_op == &hugetlbfs_file_operations)
546 return is_file_shm_hugepages(file);
549 static inline struct hstate *hstate_inode(struct inode *i)
551 return HUGETLBFS_SB(i->i_sb)->hstate;
553 #else /* !CONFIG_HUGETLBFS */
555 #define is_file_hugepages(file) false
556 static inline struct file *
557 hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag,
558 int creat_flags, int page_size_log)
560 return ERR_PTR(-ENOSYS);
563 static inline struct hstate *hstate_inode(struct inode *i)
567 #endif /* !CONFIG_HUGETLBFS */
569 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
570 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
571 unsigned long len, unsigned long pgoff,
572 unsigned long flags);
573 #endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
576 generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
577 unsigned long len, unsigned long pgoff,
578 unsigned long flags);
581 * huegtlb page specific state flags. These flags are located in page.private
582 * of the hugetlb head page. Functions created via the below macros should be
583 * used to manipulate these flags.
585 * HPG_restore_reserve - Set when a hugetlb page consumes a reservation at
586 * allocation time. Cleared when page is fully instantiated. Free
587 * routine checks flag to restore a reservation on error paths.
588 * Synchronization: Examined or modified by code that knows it has
589 * the only reference to page. i.e. After allocation but before use
590 * or when the page is being freed.
591 * HPG_migratable - Set after a newly allocated page is added to the page
592 * cache and/or page tables. Indicates the page is a candidate for
594 * Synchronization: Initially set after new page allocation with no
595 * locking. When examined and modified during migration processing
596 * (isolate, migrate, putback) the hugetlb_lock is held.
597 * HPG_temporary - Set on a page that is temporarily allocated from the buddy
598 * allocator. Typically used for migration target pages when no pages
599 * are available in the pool. The hugetlb free page path will
600 * immediately free pages with this flag set to the buddy allocator.
601 * Synchronization: Can be set after huge page allocation from buddy when
602 * code knows it has only reference. All other examinations and
603 * modifications require hugetlb_lock.
604 * HPG_freed - Set when page is on the free lists.
605 * Synchronization: hugetlb_lock held for examination and modification.
606 * HPG_vmemmap_optimized - Set when the vmemmap pages of the page are freed.
607 * HPG_raw_hwp_unreliable - Set when the hugetlb page has a hwpoison sub-page
608 * that is not tracked by raw_hwp_page list.
610 enum hugetlb_page_flags {
611 HPG_restore_reserve = 0,
615 HPG_vmemmap_optimized,
616 HPG_raw_hwp_unreliable,
621 * Macros to create test, set and clear function definitions for
622 * hugetlb specific page flags.
624 #ifdef CONFIG_HUGETLB_PAGE
625 #define TESTHPAGEFLAG(uname, flname) \
626 static inline int HPage##uname(struct page *page) \
627 { return test_bit(HPG_##flname, &(page->private)); }
629 #define SETHPAGEFLAG(uname, flname) \
630 static inline void SetHPage##uname(struct page *page) \
631 { set_bit(HPG_##flname, &(page->private)); }
633 #define CLEARHPAGEFLAG(uname, flname) \
634 static inline void ClearHPage##uname(struct page *page) \
635 { clear_bit(HPG_##flname, &(page->private)); }
637 #define TESTHPAGEFLAG(uname, flname) \
638 static inline int HPage##uname(struct page *page) \
641 #define SETHPAGEFLAG(uname, flname) \
642 static inline void SetHPage##uname(struct page *page) \
645 #define CLEARHPAGEFLAG(uname, flname) \
646 static inline void ClearHPage##uname(struct page *page) \
650 #define HPAGEFLAG(uname, flname) \
651 TESTHPAGEFLAG(uname, flname) \
652 SETHPAGEFLAG(uname, flname) \
653 CLEARHPAGEFLAG(uname, flname) \
656 * Create functions associated with hugetlb page flags
658 HPAGEFLAG(RestoreReserve, restore_reserve)
659 HPAGEFLAG(Migratable, migratable)
660 HPAGEFLAG(Temporary, temporary)
661 HPAGEFLAG(Freed, freed)
662 HPAGEFLAG(VmemmapOptimized, vmemmap_optimized)
663 HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable)
665 #ifdef CONFIG_HUGETLB_PAGE
667 #define HSTATE_NAME_LEN 32
668 /* Defines one hugetlb page size */
670 struct mutex resize_lock;
671 int next_nid_to_alloc;
672 int next_nid_to_free;
674 unsigned int demote_order;
676 unsigned long max_huge_pages;
677 unsigned long nr_huge_pages;
678 unsigned long free_huge_pages;
679 unsigned long resv_huge_pages;
680 unsigned long surplus_huge_pages;
681 unsigned long nr_overcommit_huge_pages;
682 struct list_head hugepage_activelist;
683 struct list_head hugepage_freelists[MAX_NUMNODES];
684 unsigned int max_huge_pages_node[MAX_NUMNODES];
685 unsigned int nr_huge_pages_node[MAX_NUMNODES];
686 unsigned int free_huge_pages_node[MAX_NUMNODES];
687 unsigned int surplus_huge_pages_node[MAX_NUMNODES];
688 #ifdef CONFIG_CGROUP_HUGETLB
689 /* cgroup control files */
690 struct cftype cgroup_files_dfl[8];
691 struct cftype cgroup_files_legacy[10];
693 char name[HSTATE_NAME_LEN];
696 struct huge_bootmem_page {
697 struct list_head list;
698 struct hstate *hstate;
701 int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list);
702 struct page *alloc_huge_page(struct vm_area_struct *vma,
703 unsigned long addr, int avoid_reserve);
704 struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
705 nodemask_t *nmask, gfp_t gfp_mask);
706 struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma,
707 unsigned long address);
708 int hugetlb_add_to_page_cache(struct page *page, struct address_space *mapping,
710 void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,
711 unsigned long address, struct page *page);
714 int __init __alloc_bootmem_huge_page(struct hstate *h, int nid);
715 int __init alloc_bootmem_huge_page(struct hstate *h, int nid);
716 bool __init hugetlb_node_alloc_supported(void);
718 void __init hugetlb_add_hstate(unsigned order);
719 bool __init arch_hugetlb_valid_size(unsigned long size);
720 struct hstate *size_to_hstate(unsigned long size);
722 #ifndef HUGE_MAX_HSTATE
723 #define HUGE_MAX_HSTATE 1
726 extern struct hstate hstates[HUGE_MAX_HSTATE];
727 extern unsigned int default_hstate_idx;
729 #define default_hstate (hstates[default_hstate_idx])
732 * hugetlb page subpool pointer located in hpage[1].private
734 static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage)
736 return (void *)page_private(hpage + SUBPAGE_INDEX_SUBPOOL);
739 static inline void hugetlb_set_page_subpool(struct page *hpage,
740 struct hugepage_subpool *subpool)
742 set_page_private(hpage + SUBPAGE_INDEX_SUBPOOL, (unsigned long)subpool);
745 static inline struct hstate *hstate_file(struct file *f)
747 return hstate_inode(file_inode(f));
750 static inline struct hstate *hstate_sizelog(int page_size_log)
753 return &default_hstate;
755 return size_to_hstate(1UL << page_size_log);
758 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
760 return hstate_file(vma->vm_file);
763 static inline unsigned long huge_page_size(const struct hstate *h)
765 return (unsigned long)PAGE_SIZE << h->order;
768 extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
770 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
772 static inline unsigned long huge_page_mask(struct hstate *h)
777 static inline unsigned int huge_page_order(struct hstate *h)
782 static inline unsigned huge_page_shift(struct hstate *h)
784 return h->order + PAGE_SHIFT;
787 static inline bool hstate_is_gigantic(struct hstate *h)
789 return huge_page_order(h) >= MAX_ORDER;
792 static inline unsigned int pages_per_huge_page(const struct hstate *h)
794 return 1 << h->order;
797 static inline unsigned int blocks_per_huge_page(struct hstate *h)
799 return huge_page_size(h) / 512;
802 #include <asm/hugetlb.h>
804 #ifndef is_hugepage_only_range
805 static inline int is_hugepage_only_range(struct mm_struct *mm,
806 unsigned long addr, unsigned long len)
810 #define is_hugepage_only_range is_hugepage_only_range
813 #ifndef arch_clear_hugepage_flags
814 static inline void arch_clear_hugepage_flags(struct page *page) { }
815 #define arch_clear_hugepage_flags arch_clear_hugepage_flags
818 #ifndef arch_make_huge_pte
819 static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift,
822 return pte_mkhuge(entry);
826 static inline struct hstate *page_hstate(struct page *page)
828 VM_BUG_ON_PAGE(!PageHuge(page), page);
829 return size_to_hstate(page_size(page));
832 static inline unsigned hstate_index_to_shift(unsigned index)
834 return hstates[index].order + PAGE_SHIFT;
837 static inline int hstate_index(struct hstate *h)
842 extern int dissolve_free_huge_page(struct page *page);
843 extern int dissolve_free_huge_pages(unsigned long start_pfn,
844 unsigned long end_pfn);
846 #ifdef CONFIG_MEMORY_FAILURE
847 extern void hugetlb_clear_page_hwpoison(struct page *hpage);
849 static inline void hugetlb_clear_page_hwpoison(struct page *hpage)
854 #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
855 #ifndef arch_hugetlb_migration_supported
856 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
858 if ((huge_page_shift(h) == PMD_SHIFT) ||
859 (huge_page_shift(h) == PUD_SHIFT) ||
860 (huge_page_shift(h) == PGDIR_SHIFT))
867 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
873 static inline bool hugepage_migration_supported(struct hstate *h)
875 return arch_hugetlb_migration_supported(h);
879 * Movability check is different as compared to migration check.
880 * It determines whether or not a huge page should be placed on
881 * movable zone or not. Movability of any huge page should be
882 * required only if huge page size is supported for migration.
883 * There won't be any reason for the huge page to be movable if
884 * it is not migratable to start with. Also the size of the huge
885 * page should be large enough to be placed under a movable zone
886 * and still feasible enough to be migratable. Just the presence
887 * in movable zone does not make the migration feasible.
889 * So even though large huge page sizes like the gigantic ones
890 * are migratable they should not be movable because its not
891 * feasible to migrate them from movable zone.
893 static inline bool hugepage_movable_supported(struct hstate *h)
895 if (!hugepage_migration_supported(h))
898 if (hstate_is_gigantic(h))
903 /* Movability of hugepages depends on migration support. */
904 static inline gfp_t htlb_alloc_mask(struct hstate *h)
906 if (hugepage_movable_supported(h))
907 return GFP_HIGHUSER_MOVABLE;
912 static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)
914 gfp_t modified_mask = htlb_alloc_mask(h);
916 /* Some callers might want to enforce node */
917 modified_mask |= (gfp_mask & __GFP_THISNODE);
919 modified_mask |= (gfp_mask & __GFP_NOWARN);
921 return modified_mask;
924 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
925 struct mm_struct *mm, pte_t *pte)
927 if (huge_page_size(h) == PMD_SIZE)
928 return pmd_lockptr(mm, (pmd_t *) pte);
929 VM_BUG_ON(huge_page_size(h) == PAGE_SIZE);
930 return &mm->page_table_lock;
933 #ifndef hugepages_supported
935 * Some platform decide whether they support huge pages at boot
936 * time. Some of them, such as powerpc, set HPAGE_SHIFT to 0
937 * when there is no such support
939 #define hugepages_supported() (HPAGE_SHIFT != 0)
942 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm);
944 static inline void hugetlb_count_init(struct mm_struct *mm)
946 atomic_long_set(&mm->hugetlb_usage, 0);
949 static inline void hugetlb_count_add(long l, struct mm_struct *mm)
951 atomic_long_add(l, &mm->hugetlb_usage);
954 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
956 atomic_long_sub(l, &mm->hugetlb_usage);
959 #ifndef huge_ptep_modify_prot_start
960 #define huge_ptep_modify_prot_start huge_ptep_modify_prot_start
961 static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
962 unsigned long addr, pte_t *ptep)
964 return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
968 #ifndef huge_ptep_modify_prot_commit
969 #define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
970 static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
971 unsigned long addr, pte_t *ptep,
972 pte_t old_pte, pte_t pte)
974 set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
979 void hugetlb_register_node(struct node *node);
980 void hugetlb_unregister_node(struct node *node);
983 #else /* CONFIG_HUGETLB_PAGE */
986 static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage)
991 static inline int isolate_or_dissolve_huge_page(struct page *page,
992 struct list_head *list)
997 static inline struct page *alloc_huge_page(struct vm_area_struct *vma,
1004 static inline struct page *
1005 alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
1006 nodemask_t *nmask, gfp_t gfp_mask)
1011 static inline struct page *alloc_huge_page_vma(struct hstate *h,
1012 struct vm_area_struct *vma,
1013 unsigned long address)
1018 static inline int __alloc_bootmem_huge_page(struct hstate *h)
1023 static inline struct hstate *hstate_file(struct file *f)
1028 static inline struct hstate *hstate_sizelog(int page_size_log)
1033 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
1038 static inline struct hstate *page_hstate(struct page *page)
1043 static inline struct hstate *size_to_hstate(unsigned long size)
1048 static inline unsigned long huge_page_size(struct hstate *h)
1053 static inline unsigned long huge_page_mask(struct hstate *h)
1058 static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
1063 static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
1068 static inline unsigned int huge_page_order(struct hstate *h)
1073 static inline unsigned int huge_page_shift(struct hstate *h)
1078 static inline bool hstate_is_gigantic(struct hstate *h)
1083 static inline unsigned int pages_per_huge_page(struct hstate *h)
1088 static inline unsigned hstate_index_to_shift(unsigned index)
1093 static inline int hstate_index(struct hstate *h)
1098 static inline int dissolve_free_huge_page(struct page *page)
1103 static inline int dissolve_free_huge_pages(unsigned long start_pfn,
1104 unsigned long end_pfn)
1109 static inline bool hugepage_migration_supported(struct hstate *h)
1114 static inline bool hugepage_movable_supported(struct hstate *h)
1119 static inline gfp_t htlb_alloc_mask(struct hstate *h)
1124 static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)
1129 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
1130 struct mm_struct *mm, pte_t *pte)
1132 return &mm->page_table_lock;
1135 static inline void hugetlb_count_init(struct mm_struct *mm)
1139 static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m)
1143 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
1147 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
1148 unsigned long addr, pte_t *ptep)
1153 static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
1154 pte_t *ptep, pte_t pte)
1158 static inline void hugetlb_register_node(struct node *node)
1162 static inline void hugetlb_unregister_node(struct node *node)
1165 #endif /* CONFIG_HUGETLB_PAGE */
1167 static inline spinlock_t *huge_pte_lock(struct hstate *h,
1168 struct mm_struct *mm, pte_t *pte)
1172 ptl = huge_pte_lockptr(h, mm, pte);
1177 #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
1178 extern void __init hugetlb_cma_reserve(int order);
1180 static inline __init void hugetlb_cma_reserve(int order)
1185 bool want_pmd_share(struct vm_area_struct *vma, unsigned long addr);
1187 #ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE
1189 * ARCHes with special requirements for evicting HUGETLB backing TLB entries can
1192 #define flush_hugetlb_tlb_range(vma, addr, end) flush_tlb_range(vma, addr, end)
1195 #endif /* _LINUX_HUGETLB_H */