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>
20 typedef struct { unsigned long pd; } hugepd_t;
21 #define is_hugepd(hugepd) (0)
22 #define __hugepd(x) ((hugepd_t) { (x) })
25 #ifdef CONFIG_HUGETLB_PAGE
27 #include <linux/mempolicy.h>
28 #include <linux/shm.h>
29 #include <asm/tlbflush.h>
31 struct hugepage_subpool {
34 long max_hpages; /* Maximum huge pages or -1 if no maximum. */
35 long used_hpages; /* Used count against maximum, includes */
36 /* both alloced and reserved pages. */
37 struct hstate *hstate;
38 long min_hpages; /* Minimum huge pages or -1 if no minimum. */
39 long rsv_hpages; /* Pages reserved against global pool to */
40 /* satisfy minimum size. */
46 struct list_head regions;
47 long adds_in_progress;
48 struct list_head region_cache;
49 long region_cache_count;
50 #ifdef CONFIG_CGROUP_HUGETLB
52 * On private mappings, the counter to uncharge reservations is stored
53 * here. If these fields are 0, then either the mapping is shared, or
54 * cgroup accounting is disabled for this resv_map.
56 struct page_counter *reservation_counter;
57 unsigned long pages_per_hpage;
58 struct cgroup_subsys_state *css;
63 * Region tracking -- allows tracking of reservations and instantiated pages
64 * across the pages in a mapping.
66 * The region data structures are embedded into a resv_map and protected
67 * by a resv_map's lock. The set of regions within the resv_map represent
68 * reservations for huge pages, or huge pages that have already been
69 * instantiated within the map. The from and to elements are huge page
70 * indicies into the associated mapping. from indicates the starting index
71 * of the region. to represents the first index past the end of the region.
73 * For example, a file region structure with from == 0 and to == 4 represents
74 * four huge pages in a mapping. It is important to note that the to element
75 * represents the first element past the end of the region. This is used in
76 * arithmetic as 4(to) - 0(from) = 4 huge pages in the region.
78 * Interval notation of the form [from, to) will be used to indicate that
79 * the endpoint from is inclusive and to is exclusive.
82 struct list_head link;
85 #ifdef CONFIG_CGROUP_HUGETLB
87 * On shared mappings, each reserved region appears as a struct
88 * file_region in resv_map. These fields hold the info needed to
89 * uncharge each reservation.
91 struct page_counter *reservation_counter;
92 struct cgroup_subsys_state *css;
96 extern struct resv_map *resv_map_alloc(void);
97 void resv_map_release(struct kref *ref);
99 extern spinlock_t hugetlb_lock;
100 extern int hugetlb_max_hstate __read_mostly;
101 #define for_each_hstate(h) \
102 for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++)
104 struct hugepage_subpool *hugepage_new_subpool(struct hstate *h, long max_hpages,
106 void hugepage_put_subpool(struct hugepage_subpool *spool);
108 void reset_vma_resv_huge_pages(struct vm_area_struct *vma);
109 int hugetlb_sysctl_handler(struct ctl_table *, int, void *, size_t *, loff_t *);
110 int hugetlb_overcommit_handler(struct ctl_table *, int, void *, size_t *,
112 int hugetlb_treat_movable_handler(struct ctl_table *, int, void *, size_t *,
114 int hugetlb_mempolicy_sysctl_handler(struct ctl_table *, int, void *, size_t *,
117 int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *);
118 long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
119 struct page **, struct vm_area_struct **,
120 unsigned long *, unsigned long *, long, unsigned int,
122 void unmap_hugepage_range(struct vm_area_struct *,
123 unsigned long, unsigned long, struct page *);
124 void __unmap_hugepage_range_final(struct mmu_gather *tlb,
125 struct vm_area_struct *vma,
126 unsigned long start, unsigned long end,
127 struct page *ref_page);
128 void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
129 unsigned long start, unsigned long end,
130 struct page *ref_page);
131 void hugetlb_report_meminfo(struct seq_file *);
132 int hugetlb_report_node_meminfo(char *buf, int len, int nid);
133 void hugetlb_show_meminfo(void);
134 unsigned long hugetlb_total_pages(void);
135 vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
136 unsigned long address, unsigned int flags);
137 int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte,
138 struct vm_area_struct *dst_vma,
139 unsigned long dst_addr,
140 unsigned long src_addr,
141 struct page **pagep);
142 bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
143 struct vm_area_struct *vma,
144 vm_flags_t vm_flags);
145 long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
147 bool isolate_huge_page(struct page *page, struct list_head *list);
148 void putback_active_hugepage(struct page *page);
149 void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason);
150 void free_huge_page(struct page *page);
151 void hugetlb_fix_reserve_counts(struct inode *inode);
152 extern struct mutex *hugetlb_fault_mutex_table;
153 u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx);
155 pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud);
157 struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage);
159 extern int sysctl_hugetlb_shm_group;
160 extern struct list_head huge_boot_pages;
164 pte_t *huge_pte_alloc(struct mm_struct *mm,
165 unsigned long addr, unsigned long sz);
166 pte_t *huge_pte_offset(struct mm_struct *mm,
167 unsigned long addr, unsigned long sz);
168 int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma,
169 unsigned long *addr, pte_t *ptep);
170 void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
171 unsigned long *start, unsigned long *end);
172 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
174 struct page *follow_huge_pd(struct vm_area_struct *vma,
175 unsigned long address, hugepd_t hpd,
176 int flags, int pdshift);
177 struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
178 pmd_t *pmd, int flags);
179 struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
180 pud_t *pud, int flags);
181 struct page *follow_huge_pgd(struct mm_struct *mm, unsigned long address,
182 pgd_t *pgd, int flags);
184 int pmd_huge(pmd_t pmd);
185 int pud_huge(pud_t pud);
186 unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
187 unsigned long address, unsigned long end, pgprot_t newprot);
189 bool is_hugetlb_entry_migration(pte_t pte);
191 #else /* !CONFIG_HUGETLB_PAGE */
193 static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
197 static inline unsigned long hugetlb_total_pages(void)
202 static inline struct address_space *hugetlb_page_mapping_lock_write(
208 static inline int huge_pmd_unshare(struct mm_struct *mm,
209 struct vm_area_struct *vma,
210 unsigned long *addr, pte_t *ptep)
215 static inline void adjust_range_if_pmd_sharing_possible(
216 struct vm_area_struct *vma,
217 unsigned long *start, unsigned long *end)
221 static inline long follow_hugetlb_page(struct mm_struct *mm,
222 struct vm_area_struct *vma, struct page **pages,
223 struct vm_area_struct **vmas, unsigned long *position,
224 unsigned long *nr_pages, long i, unsigned int flags,
231 static inline struct page *follow_huge_addr(struct mm_struct *mm,
232 unsigned long address, int write)
234 return ERR_PTR(-EINVAL);
237 static inline int copy_hugetlb_page_range(struct mm_struct *dst,
238 struct mm_struct *src, struct vm_area_struct *vma)
244 static inline void hugetlb_report_meminfo(struct seq_file *m)
248 static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid)
253 static inline void hugetlb_show_meminfo(void)
257 static inline struct page *follow_huge_pd(struct vm_area_struct *vma,
258 unsigned long address, hugepd_t hpd, int flags,
264 static inline struct page *follow_huge_pmd(struct mm_struct *mm,
265 unsigned long address, pmd_t *pmd, int flags)
270 static inline struct page *follow_huge_pud(struct mm_struct *mm,
271 unsigned long address, pud_t *pud, int flags)
276 static inline struct page *follow_huge_pgd(struct mm_struct *mm,
277 unsigned long address, pgd_t *pgd, int flags)
282 static inline int prepare_hugepage_range(struct file *file,
283 unsigned long addr, unsigned long len)
288 static inline int pmd_huge(pmd_t pmd)
293 static inline int pud_huge(pud_t pud)
298 static inline int is_hugepage_only_range(struct mm_struct *mm,
299 unsigned long addr, unsigned long len)
304 static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
305 unsigned long addr, unsigned long end,
306 unsigned long floor, unsigned long ceiling)
311 static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
313 struct vm_area_struct *dst_vma,
314 unsigned long dst_addr,
315 unsigned long src_addr,
322 static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
328 static inline bool isolate_huge_page(struct page *page, struct list_head *list)
333 static inline void putback_active_hugepage(struct page *page)
337 static inline void move_hugetlb_state(struct page *oldpage,
338 struct page *newpage, int reason)
342 static inline unsigned long hugetlb_change_protection(
343 struct vm_area_struct *vma, unsigned long address,
344 unsigned long end, pgprot_t newprot)
349 static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb,
350 struct vm_area_struct *vma, unsigned long start,
351 unsigned long end, struct page *ref_page)
356 static inline void __unmap_hugepage_range(struct mmu_gather *tlb,
357 struct vm_area_struct *vma, unsigned long start,
358 unsigned long end, struct page *ref_page)
363 static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,
364 struct vm_area_struct *vma, unsigned long address,
371 #endif /* !CONFIG_HUGETLB_PAGE */
373 * hugepages at page global directory. If arch support
374 * hugepages at pgd level, they need to define this.
377 #define pgd_huge(x) 0
380 #define p4d_huge(x) 0
384 static inline int pgd_write(pgd_t pgd)
391 #define HUGETLB_ANON_FILE "anon_hugepage"
395 * The file will be used as an shm file so shmfs accounting rules
398 HUGETLB_SHMFS_INODE = 1,
400 * The file is being created on the internal vfs mount and shmfs
401 * accounting rules do not apply
403 HUGETLB_ANONHUGE_INODE = 2,
406 #ifdef CONFIG_HUGETLBFS
407 struct hugetlbfs_sb_info {
408 long max_inodes; /* inodes allowed */
409 long free_inodes; /* inodes free */
410 spinlock_t stat_lock;
411 struct hstate *hstate;
412 struct hugepage_subpool *spool;
418 static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
420 return sb->s_fs_info;
423 struct hugetlbfs_inode_info {
424 struct shared_policy policy;
425 struct inode vfs_inode;
429 static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
431 return container_of(inode, struct hugetlbfs_inode_info, vfs_inode);
434 extern const struct file_operations hugetlbfs_file_operations;
435 extern const struct vm_operations_struct hugetlb_vm_ops;
436 struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
437 struct user_struct **user, int creat_flags,
440 static inline bool is_file_hugepages(struct file *file)
442 if (file->f_op == &hugetlbfs_file_operations)
445 return is_file_shm_hugepages(file);
448 static inline struct hstate *hstate_inode(struct inode *i)
450 return HUGETLBFS_SB(i->i_sb)->hstate;
452 #else /* !CONFIG_HUGETLBFS */
454 #define is_file_hugepages(file) false
455 static inline struct file *
456 hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag,
457 struct user_struct **user, int creat_flags,
460 return ERR_PTR(-ENOSYS);
463 static inline struct hstate *hstate_inode(struct inode *i)
467 #endif /* !CONFIG_HUGETLBFS */
469 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
470 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
471 unsigned long len, unsigned long pgoff,
472 unsigned long flags);
473 #endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
476 * huegtlb page specific state flags. These flags are located in page.private
477 * of the hugetlb head page. Functions created via the below macros should be
478 * used to manipulate these flags.
480 * HPG_restore_reserve - Set when a hugetlb page consumes a reservation at
481 * allocation time. Cleared when page is fully instantiated. Free
482 * routine checks flag to restore a reservation on error paths.
483 * Synchronization: Examined or modified by code that knows it has
484 * the only reference to page. i.e. After allocation but before use
485 * or when the page is being freed.
486 * HPG_migratable - Set after a newly allocated page is added to the page
487 * cache and/or page tables. Indicates the page is a candidate for
489 * Synchronization: Initially set after new page allocation with no
490 * locking. When examined and modified during migration processing
491 * (isolate, migrate, putback) the hugetlb_lock is held.
492 * HPG_temporary - - Set on a page that is temporarily allocated from the buddy
493 * allocator. Typically used for migration target pages when no pages
494 * are available in the pool. The hugetlb free page path will
495 * immediately free pages with this flag set to the buddy allocator.
496 * Synchronization: Can be set after huge page allocation from buddy when
497 * code knows it has only reference. All other examinations and
498 * modifications require hugetlb_lock.
499 * HPG_freed - Set when page is on the free lists.
500 * Synchronization: hugetlb_lock held for examination and modification.
502 enum hugetlb_page_flags {
503 HPG_restore_reserve = 0,
511 * Macros to create test, set and clear function definitions for
512 * hugetlb specific page flags.
514 #ifdef CONFIG_HUGETLB_PAGE
515 #define TESTHPAGEFLAG(uname, flname) \
516 static inline int HPage##uname(struct page *page) \
517 { return test_bit(HPG_##flname, &(page->private)); }
519 #define SETHPAGEFLAG(uname, flname) \
520 static inline void SetHPage##uname(struct page *page) \
521 { set_bit(HPG_##flname, &(page->private)); }
523 #define CLEARHPAGEFLAG(uname, flname) \
524 static inline void ClearHPage##uname(struct page *page) \
525 { clear_bit(HPG_##flname, &(page->private)); }
527 #define TESTHPAGEFLAG(uname, flname) \
528 static inline int HPage##uname(struct page *page) \
531 #define SETHPAGEFLAG(uname, flname) \
532 static inline void SetHPage##uname(struct page *page) \
535 #define CLEARHPAGEFLAG(uname, flname) \
536 static inline void ClearHPage##uname(struct page *page) \
540 #define HPAGEFLAG(uname, flname) \
541 TESTHPAGEFLAG(uname, flname) \
542 SETHPAGEFLAG(uname, flname) \
543 CLEARHPAGEFLAG(uname, flname) \
546 * Create functions associated with hugetlb page flags
548 HPAGEFLAG(RestoreReserve, restore_reserve)
549 HPAGEFLAG(Migratable, migratable)
550 HPAGEFLAG(Temporary, temporary)
551 HPAGEFLAG(Freed, freed)
553 #ifdef CONFIG_HUGETLB_PAGE
555 #define HSTATE_NAME_LEN 32
556 /* Defines one hugetlb page size */
558 int next_nid_to_alloc;
559 int next_nid_to_free;
562 unsigned long max_huge_pages;
563 unsigned long nr_huge_pages;
564 unsigned long free_huge_pages;
565 unsigned long resv_huge_pages;
566 unsigned long surplus_huge_pages;
567 unsigned long nr_overcommit_huge_pages;
568 struct list_head hugepage_activelist;
569 struct list_head hugepage_freelists[MAX_NUMNODES];
570 unsigned int nr_huge_pages_node[MAX_NUMNODES];
571 unsigned int free_huge_pages_node[MAX_NUMNODES];
572 unsigned int surplus_huge_pages_node[MAX_NUMNODES];
573 #ifdef CONFIG_CGROUP_HUGETLB
574 /* cgroup control files */
575 struct cftype cgroup_files_dfl[7];
576 struct cftype cgroup_files_legacy[9];
578 char name[HSTATE_NAME_LEN];
581 struct huge_bootmem_page {
582 struct list_head list;
583 struct hstate *hstate;
586 struct page *alloc_huge_page(struct vm_area_struct *vma,
587 unsigned long addr, int avoid_reserve);
588 struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
589 nodemask_t *nmask, gfp_t gfp_mask);
590 struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma,
591 unsigned long address);
592 int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
596 int __init __alloc_bootmem_huge_page(struct hstate *h);
597 int __init alloc_bootmem_huge_page(struct hstate *h);
599 void __init hugetlb_add_hstate(unsigned order);
600 bool __init arch_hugetlb_valid_size(unsigned long size);
601 struct hstate *size_to_hstate(unsigned long size);
603 #ifndef HUGE_MAX_HSTATE
604 #define HUGE_MAX_HSTATE 1
607 extern struct hstate hstates[HUGE_MAX_HSTATE];
608 extern unsigned int default_hstate_idx;
610 #define default_hstate (hstates[default_hstate_idx])
613 * hugetlb page subpool pointer located in hpage[1].private
615 static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage)
617 return (struct hugepage_subpool *)(hpage+1)->private;
620 static inline void hugetlb_set_page_subpool(struct page *hpage,
621 struct hugepage_subpool *subpool)
623 set_page_private(hpage+1, (unsigned long)subpool);
626 static inline struct hstate *hstate_file(struct file *f)
628 return hstate_inode(file_inode(f));
631 static inline struct hstate *hstate_sizelog(int page_size_log)
634 return &default_hstate;
636 return size_to_hstate(1UL << page_size_log);
639 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
641 return hstate_file(vma->vm_file);
644 static inline unsigned long huge_page_size(struct hstate *h)
646 return (unsigned long)PAGE_SIZE << h->order;
649 extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
651 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
653 static inline unsigned long huge_page_mask(struct hstate *h)
658 static inline unsigned int huge_page_order(struct hstate *h)
663 static inline unsigned huge_page_shift(struct hstate *h)
665 return h->order + PAGE_SHIFT;
668 static inline bool hstate_is_gigantic(struct hstate *h)
670 return huge_page_order(h) >= MAX_ORDER;
673 static inline unsigned int pages_per_huge_page(struct hstate *h)
675 return 1 << h->order;
678 static inline unsigned int blocks_per_huge_page(struct hstate *h)
680 return huge_page_size(h) / 512;
683 #include <asm/hugetlb.h>
685 #ifndef is_hugepage_only_range
686 static inline int is_hugepage_only_range(struct mm_struct *mm,
687 unsigned long addr, unsigned long len)
691 #define is_hugepage_only_range is_hugepage_only_range
694 #ifndef arch_clear_hugepage_flags
695 static inline void arch_clear_hugepage_flags(struct page *page) { }
696 #define arch_clear_hugepage_flags arch_clear_hugepage_flags
699 #ifndef arch_make_huge_pte
700 static inline pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
701 struct page *page, int writable)
707 static inline struct hstate *page_hstate(struct page *page)
709 VM_BUG_ON_PAGE(!PageHuge(page), page);
710 return size_to_hstate(page_size(page));
713 static inline unsigned hstate_index_to_shift(unsigned index)
715 return hstates[index].order + PAGE_SHIFT;
718 static inline int hstate_index(struct hstate *h)
723 pgoff_t __basepage_index(struct page *page);
725 /* Return page->index in PAGE_SIZE units */
726 static inline pgoff_t basepage_index(struct page *page)
728 if (!PageCompound(page))
731 return __basepage_index(page);
734 extern int dissolve_free_huge_page(struct page *page);
735 extern int dissolve_free_huge_pages(unsigned long start_pfn,
736 unsigned long end_pfn);
738 #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
739 #ifndef arch_hugetlb_migration_supported
740 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
742 if ((huge_page_shift(h) == PMD_SHIFT) ||
743 (huge_page_shift(h) == PUD_SHIFT) ||
744 (huge_page_shift(h) == PGDIR_SHIFT))
751 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
757 static inline bool hugepage_migration_supported(struct hstate *h)
759 return arch_hugetlb_migration_supported(h);
763 * Movability check is different as compared to migration check.
764 * It determines whether or not a huge page should be placed on
765 * movable zone or not. Movability of any huge page should be
766 * required only if huge page size is supported for migration.
767 * There wont be any reason for the huge page to be movable if
768 * it is not migratable to start with. Also the size of the huge
769 * page should be large enough to be placed under a movable zone
770 * and still feasible enough to be migratable. Just the presence
771 * in movable zone does not make the migration feasible.
773 * So even though large huge page sizes like the gigantic ones
774 * are migratable they should not be movable because its not
775 * feasible to migrate them from movable zone.
777 static inline bool hugepage_movable_supported(struct hstate *h)
779 if (!hugepage_migration_supported(h))
782 if (hstate_is_gigantic(h))
787 /* Movability of hugepages depends on migration support. */
788 static inline gfp_t htlb_alloc_mask(struct hstate *h)
790 if (hugepage_movable_supported(h))
791 return GFP_HIGHUSER_MOVABLE;
796 static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)
798 gfp_t modified_mask = htlb_alloc_mask(h);
800 /* Some callers might want to enforce node */
801 modified_mask |= (gfp_mask & __GFP_THISNODE);
803 modified_mask |= (gfp_mask & __GFP_NOWARN);
805 return modified_mask;
808 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
809 struct mm_struct *mm, pte_t *pte)
811 if (huge_page_size(h) == PMD_SIZE)
812 return pmd_lockptr(mm, (pmd_t *) pte);
813 VM_BUG_ON(huge_page_size(h) == PAGE_SIZE);
814 return &mm->page_table_lock;
817 #ifndef hugepages_supported
819 * Some platform decide whether they support huge pages at boot
820 * time. Some of them, such as powerpc, set HPAGE_SHIFT to 0
821 * when there is no such support
823 #define hugepages_supported() (HPAGE_SHIFT != 0)
826 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm);
828 static inline void hugetlb_count_add(long l, struct mm_struct *mm)
830 atomic_long_add(l, &mm->hugetlb_usage);
833 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
835 atomic_long_sub(l, &mm->hugetlb_usage);
838 #ifndef set_huge_swap_pte_at
839 static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
840 pte_t *ptep, pte_t pte, unsigned long sz)
842 set_huge_pte_at(mm, addr, ptep, pte);
846 #ifndef huge_ptep_modify_prot_start
847 #define huge_ptep_modify_prot_start huge_ptep_modify_prot_start
848 static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
849 unsigned long addr, pte_t *ptep)
851 return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
855 #ifndef huge_ptep_modify_prot_commit
856 #define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
857 static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
858 unsigned long addr, pte_t *ptep,
859 pte_t old_pte, pte_t pte)
861 set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
865 #else /* CONFIG_HUGETLB_PAGE */
868 static inline struct page *alloc_huge_page(struct vm_area_struct *vma,
875 static inline struct page *
876 alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
877 nodemask_t *nmask, gfp_t gfp_mask)
882 static inline struct page *alloc_huge_page_vma(struct hstate *h,
883 struct vm_area_struct *vma,
884 unsigned long address)
889 static inline int __alloc_bootmem_huge_page(struct hstate *h)
894 static inline struct hstate *hstate_file(struct file *f)
899 static inline struct hstate *hstate_sizelog(int page_size_log)
904 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
909 static inline struct hstate *page_hstate(struct page *page)
914 static inline unsigned long huge_page_size(struct hstate *h)
919 static inline unsigned long huge_page_mask(struct hstate *h)
924 static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
929 static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
934 static inline unsigned int huge_page_order(struct hstate *h)
939 static inline unsigned int huge_page_shift(struct hstate *h)
944 static inline bool hstate_is_gigantic(struct hstate *h)
949 static inline unsigned int pages_per_huge_page(struct hstate *h)
954 static inline unsigned hstate_index_to_shift(unsigned index)
959 static inline int hstate_index(struct hstate *h)
964 static inline pgoff_t basepage_index(struct page *page)
969 static inline int dissolve_free_huge_page(struct page *page)
974 static inline int dissolve_free_huge_pages(unsigned long start_pfn,
975 unsigned long end_pfn)
980 static inline bool hugepage_migration_supported(struct hstate *h)
985 static inline bool hugepage_movable_supported(struct hstate *h)
990 static inline gfp_t htlb_alloc_mask(struct hstate *h)
995 static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)
1000 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
1001 struct mm_struct *mm, pte_t *pte)
1003 return &mm->page_table_lock;
1006 static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m)
1010 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
1014 static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
1015 pte_t *ptep, pte_t pte, unsigned long sz)
1018 #endif /* CONFIG_HUGETLB_PAGE */
1020 static inline spinlock_t *huge_pte_lock(struct hstate *h,
1021 struct mm_struct *mm, pte_t *pte)
1025 ptl = huge_pte_lockptr(h, mm, pte);
1030 #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
1031 extern void __init hugetlb_cma_reserve(int order);
1032 extern void __init hugetlb_cma_check(void);
1034 static inline __init void hugetlb_cma_reserve(int order)
1037 static inline __init void hugetlb_cma_check(void)
1042 #endif /* _LINUX_HUGETLB_H */