1 #ifndef _LINUX_HUGE_MM_H
2 #define _LINUX_HUGE_MM_H
4 extern int do_huge_pmd_anonymous_page(struct mm_struct
*mm
,
5 struct vm_area_struct
*vma
,
6 unsigned long address
, pmd_t
*pmd
,
8 extern int copy_huge_pmd(struct mm_struct
*dst_mm
, struct mm_struct
*src_mm
,
9 pmd_t
*dst_pmd
, pmd_t
*src_pmd
, unsigned long addr
,
10 struct vm_area_struct
*vma
);
11 extern void huge_pmd_set_accessed(struct mm_struct
*mm
,
12 struct vm_area_struct
*vma
,
13 unsigned long address
, pmd_t
*pmd
,
14 pmd_t orig_pmd
, int dirty
);
15 extern int do_huge_pmd_wp_page(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
16 unsigned long address
, pmd_t
*pmd
,
18 extern struct page
*follow_trans_huge_pmd(struct vm_area_struct
*vma
,
22 extern int zap_huge_pmd(struct mmu_gather
*tlb
,
23 struct vm_area_struct
*vma
,
24 pmd_t
*pmd
, unsigned long addr
);
25 extern int mincore_huge_pmd(struct vm_area_struct
*vma
, pmd_t
*pmd
,
26 unsigned long addr
, unsigned long end
,
28 extern int move_huge_pmd(struct vm_area_struct
*vma
,
29 struct vm_area_struct
*new_vma
,
30 unsigned long old_addr
,
31 unsigned long new_addr
, unsigned long old_end
,
32 pmd_t
*old_pmd
, pmd_t
*new_pmd
);
33 extern int change_huge_pmd(struct vm_area_struct
*vma
, pmd_t
*pmd
,
34 unsigned long addr
, pgprot_t newprot
,
37 enum transparent_hugepage_flag
{
38 TRANSPARENT_HUGEPAGE_FLAG
,
39 TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG
,
40 TRANSPARENT_HUGEPAGE_DEFRAG_FLAG
,
41 TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG
,
42 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG
,
43 TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG
,
44 #ifdef CONFIG_DEBUG_VM
45 TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG
,
49 enum page_check_address_pmd_flag
{
50 PAGE_CHECK_ADDRESS_PMD_FLAG
,
51 PAGE_CHECK_ADDRESS_PMD_NOTSPLITTING_FLAG
,
52 PAGE_CHECK_ADDRESS_PMD_SPLITTING_FLAG
,
54 extern pmd_t
*page_check_address_pmd(struct page
*page
,
56 unsigned long address
,
57 enum page_check_address_pmd_flag flag
,
60 #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
61 #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
63 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64 #define HPAGE_PMD_SHIFT PMD_SHIFT
65 #define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
66 #define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1))
68 extern bool is_vma_temporary_stack(struct vm_area_struct
*vma
);
70 #define transparent_hugepage_enabled(__vma) \
71 ((transparent_hugepage_flags & \
72 (1<<TRANSPARENT_HUGEPAGE_FLAG) || \
73 (transparent_hugepage_flags & \
74 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \
75 ((__vma)->vm_flags & VM_HUGEPAGE))) && \
76 !((__vma)->vm_flags & VM_NOHUGEPAGE) && \
77 !is_vma_temporary_stack(__vma))
78 #define transparent_hugepage_defrag(__vma) \
79 ((transparent_hugepage_flags & \
80 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \
81 (transparent_hugepage_flags & \
82 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \
83 (__vma)->vm_flags & VM_HUGEPAGE))
84 #define transparent_hugepage_use_zero_page() \
85 (transparent_hugepage_flags & \
86 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
87 #ifdef CONFIG_DEBUG_VM
88 #define transparent_hugepage_debug_cow() \
89 (transparent_hugepage_flags & \
90 (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
91 #else /* CONFIG_DEBUG_VM */
92 #define transparent_hugepage_debug_cow() 0
93 #endif /* CONFIG_DEBUG_VM */
95 extern unsigned long transparent_hugepage_flags
;
96 extern int split_huge_page_to_list(struct page
*page
, struct list_head
*list
);
97 static inline int split_huge_page(struct page
*page
)
99 return split_huge_page_to_list(page
, NULL
);
101 extern void __split_huge_page_pmd(struct vm_area_struct
*vma
,
102 unsigned long address
, pmd_t
*pmd
);
103 #define split_huge_page_pmd(__vma, __address, __pmd) \
105 pmd_t *____pmd = (__pmd); \
106 if (unlikely(pmd_trans_huge(*____pmd))) \
107 __split_huge_page_pmd(__vma, __address, \
110 #define wait_split_huge_page(__anon_vma, __pmd) \
112 pmd_t *____pmd = (__pmd); \
113 anon_vma_lock_write(__anon_vma); \
114 anon_vma_unlock_write(__anon_vma); \
115 BUG_ON(pmd_trans_splitting(*____pmd) || \
116 pmd_trans_huge(*____pmd)); \
118 extern void split_huge_page_pmd_mm(struct mm_struct
*mm
, unsigned long address
,
120 #if HPAGE_PMD_ORDER >= MAX_ORDER
121 #error "hugepages can't be allocated by the buddy allocator"
123 extern int hugepage_madvise(struct vm_area_struct
*vma
,
124 unsigned long *vm_flags
, int advice
);
125 extern void __vma_adjust_trans_huge(struct vm_area_struct
*vma
,
129 extern int __pmd_trans_huge_lock(pmd_t
*pmd
, struct vm_area_struct
*vma
,
131 /* mmap_sem must be held on entry */
132 static inline int pmd_trans_huge_lock(pmd_t
*pmd
, struct vm_area_struct
*vma
,
135 VM_BUG_ON_VMA(!rwsem_is_locked(&vma
->vm_mm
->mmap_sem
), vma
);
136 if (pmd_trans_huge(*pmd
))
137 return __pmd_trans_huge_lock(pmd
, vma
, ptl
);
141 static inline void vma_adjust_trans_huge(struct vm_area_struct
*vma
,
146 if (!vma
->anon_vma
|| vma
->vm_ops
)
148 __vma_adjust_trans_huge(vma
, start
, end
, adjust_next
);
150 static inline int hpage_nr_pages(struct page
*page
)
152 if (unlikely(PageTransHuge(page
)))
157 extern int do_huge_pmd_numa_page(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
158 unsigned long addr
, pmd_t pmd
, pmd_t
*pmdp
);
160 extern struct page
*huge_zero_page
;
162 static inline bool is_huge_zero_page(struct page
*page
)
164 return ACCESS_ONCE(huge_zero_page
) == page
;
167 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
168 #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
169 #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
170 #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
172 #define hpage_nr_pages(x) 1
174 #define transparent_hugepage_enabled(__vma) 0
176 #define transparent_hugepage_flags 0UL
178 split_huge_page_to_list(struct page
*page
, struct list_head
*list
)
182 static inline int split_huge_page(struct page
*page
)
186 #define split_huge_page_pmd(__vma, __address, __pmd) \
188 #define wait_split_huge_page(__anon_vma, __pmd) \
190 #define split_huge_page_pmd_mm(__mm, __address, __pmd) \
192 static inline int hugepage_madvise(struct vm_area_struct
*vma
,
193 unsigned long *vm_flags
, int advice
)
198 static inline void vma_adjust_trans_huge(struct vm_area_struct
*vma
,
204 static inline int pmd_trans_huge_lock(pmd_t
*pmd
, struct vm_area_struct
*vma
,
210 static inline int do_huge_pmd_numa_page(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
211 unsigned long addr
, pmd_t pmd
, pmd_t
*pmdp
)
216 static inline bool is_huge_zero_page(struct page
*page
)
221 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
223 #endif /* _LINUX_HUGE_MM_H */