blob: 1af47755245944e9f25d794a1f18717960f49d46 [file] [log] [blame]
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -08001#ifndef _LINUX_HUGE_MM_H
2#define _LINUX_HUGE_MM_H
3
4extern int do_huge_pmd_anonymous_page(struct mm_struct *mm,
5 struct vm_area_struct *vma,
6 unsigned long address, pmd_t *pmd,
7 unsigned int flags);
8extern 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);
Will Deacona1dd4502012-12-11 16:01:27 -080011extern 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);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080015extern int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
16 unsigned long address, pmd_t *pmd,
17 pmd_t orig_pmd);
David Rientjesb676b292012-10-08 16:34:03 -070018extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080019 unsigned long addr,
20 pmd_t *pmd,
21 unsigned int flags);
22extern int zap_huge_pmd(struct mmu_gather *tlb,
23 struct vm_area_struct *vma,
Shaohua Lif21760b2012-01-12 17:19:16 -080024 pmd_t *pmd, unsigned long addr);
Johannes Weiner0ca16342011-01-13 15:47:02 -080025extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
26 unsigned long addr, unsigned long end,
27 unsigned char *vec);
Andrea Arcangeli37a1c492011-10-31 17:08:30 -070028extern 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);
Johannes Weinercd7548a2011-01-13 15:47:04 -080033extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
34 unsigned long addr, pgprot_t newprot);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080035
36enum transparent_hugepage_flag {
37 TRANSPARENT_HUGEPAGE_FLAG,
38 TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
39 TRANSPARENT_HUGEPAGE_DEFRAG_FLAG,
40 TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
Andrea Arcangeliba761492011-01-13 15:46:58 -080041 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080042#ifdef CONFIG_DEBUG_VM
43 TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG,
44#endif
45};
46
47enum page_check_address_pmd_flag {
48 PAGE_CHECK_ADDRESS_PMD_FLAG,
49 PAGE_CHECK_ADDRESS_PMD_NOTSPLITTING_FLAG,
50 PAGE_CHECK_ADDRESS_PMD_SPLITTING_FLAG,
51};
52extern pmd_t *page_check_address_pmd(struct page *page,
53 struct mm_struct *mm,
54 unsigned long address,
55 enum page_check_address_pmd_flag flag);
56
Naoya Horiguchid8c37c42012-03-21 16:34:27 -070057#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
58#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
59
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080060#ifdef CONFIG_TRANSPARENT_HUGEPAGE
61#define HPAGE_PMD_SHIFT HPAGE_SHIFT
62#define HPAGE_PMD_MASK HPAGE_MASK
63#define HPAGE_PMD_SIZE HPAGE_SIZE
64
Alex Shi20995972012-05-29 15:06:31 -070065extern bool is_vma_temporary_stack(struct vm_area_struct *vma);
66
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080067#define transparent_hugepage_enabled(__vma) \
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080068 ((transparent_hugepage_flags & \
69 (1<<TRANSPARENT_HUGEPAGE_FLAG) || \
70 (transparent_hugepage_flags & \
71 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \
72 ((__vma)->vm_flags & VM_HUGEPAGE))) && \
Andrea Arcangelia7d6e4e2011-02-15 19:02:45 +010073 !((__vma)->vm_flags & VM_NOHUGEPAGE) && \
74 !is_vma_temporary_stack(__vma))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080075#define transparent_hugepage_defrag(__vma) \
76 ((transparent_hugepage_flags & \
77 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \
78 (transparent_hugepage_flags & \
79 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \
80 (__vma)->vm_flags & VM_HUGEPAGE))
81#ifdef CONFIG_DEBUG_VM
82#define transparent_hugepage_debug_cow() \
83 (transparent_hugepage_flags & \
84 (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
85#else /* CONFIG_DEBUG_VM */
86#define transparent_hugepage_debug_cow() 0
87#endif /* CONFIG_DEBUG_VM */
88
89extern unsigned long transparent_hugepage_flags;
90extern int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
91 pmd_t *dst_pmd, pmd_t *src_pmd,
92 struct vm_area_struct *vma,
93 unsigned long addr, unsigned long end);
94extern int handle_pte_fault(struct mm_struct *mm,
95 struct vm_area_struct *vma, unsigned long address,
96 pte_t *pte, pmd_t *pmd, unsigned int flags);
97extern int split_huge_page(struct page *page);
98extern void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd);
99#define split_huge_page_pmd(__mm, __pmd) \
100 do { \
101 pmd_t *____pmd = (__pmd); \
102 if (unlikely(pmd_trans_huge(*____pmd))) \
103 __split_huge_page_pmd(__mm, ____pmd); \
104 } while (0)
105#define wait_split_huge_page(__anon_vma, __pmd) \
106 do { \
107 pmd_t *____pmd = (__pmd); \
Peter Zijlstra2b575eb2011-05-24 17:12:11 -0700108 anon_vma_lock(__anon_vma); \
109 anon_vma_unlock(__anon_vma); \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800110 BUG_ON(pmd_trans_splitting(*____pmd) || \
111 pmd_trans_huge(*____pmd)); \
112 } while (0)
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800113#if HPAGE_PMD_ORDER > MAX_ORDER
114#error "hugepages can't be allocated by the buddy allocator"
115#endif
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800116extern int hugepage_madvise(struct vm_area_struct *vma,
117 unsigned long *vm_flags, int advice);
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800118extern void __vma_adjust_trans_huge(struct vm_area_struct *vma,
119 unsigned long start,
120 unsigned long end,
121 long adjust_next);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700122extern int __pmd_trans_huge_lock(pmd_t *pmd,
123 struct vm_area_struct *vma);
124/* mmap_sem must be held on entry */
125static inline int pmd_trans_huge_lock(pmd_t *pmd,
126 struct vm_area_struct *vma)
127{
128 VM_BUG_ON(!rwsem_is_locked(&vma->vm_mm->mmap_sem));
129 if (pmd_trans_huge(*pmd))
130 return __pmd_trans_huge_lock(pmd, vma);
131 else
132 return 0;
133}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800134static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
135 unsigned long start,
136 unsigned long end,
137 long adjust_next)
138{
Andrea Arcangeli78f11a22011-04-27 15:26:45 -0700139 if (!vma->anon_vma || vma->vm_ops)
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800140 return;
141 __vma_adjust_trans_huge(vma, start, end, adjust_next);
142}
Rik van Riel2c888cf2011-01-13 15:47:13 -0800143static inline int hpage_nr_pages(struct page *page)
144{
145 if (unlikely(PageTransHuge(page)))
146 return HPAGE_PMD_NR;
147 return 1;
148}
Andrea Arcangeli22e5c472011-01-13 15:47:20 -0800149static inline struct page *compound_trans_head(struct page *page)
150{
151 if (PageTail(page)) {
152 struct page *head;
153 head = page->first_page;
154 smp_rmb();
155 /*
156 * head may be a dangling pointer.
157 * __split_huge_page_refcount clears PageTail before
158 * overwriting first_page, so if PageTail is still
159 * there it means the head pointer isn't dangling.
160 */
161 if (PageTail(page))
162 return head;
163 }
164 return page;
165}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800166#else /* CONFIG_TRANSPARENT_HUGEPAGE */
Naoya Horiguchid8c37c42012-03-21 16:34:27 -0700167#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
168#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
169#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800170
Rik van Riel2c888cf2011-01-13 15:47:13 -0800171#define hpage_nr_pages(x) 1
172
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800173#define transparent_hugepage_enabled(__vma) 0
174
175#define transparent_hugepage_flags 0UL
176static inline int split_huge_page(struct page *page)
177{
178 return 0;
179}
180#define split_huge_page_pmd(__mm, __pmd) \
181 do { } while (0)
182#define wait_split_huge_page(__anon_vma, __pmd) \
183 do { } while (0)
Andrea Arcangeli22e5c472011-01-13 15:47:20 -0800184#define compound_trans_head(page) compound_head(page)
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800185static inline int hugepage_madvise(struct vm_area_struct *vma,
186 unsigned long *vm_flags, int advice)
Andrea Arcangeli0af4e982011-01-13 15:46:55 -0800187{
188 BUG();
189 return 0;
190}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800191static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
192 unsigned long start,
193 unsigned long end,
194 long adjust_next)
195{
196}
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700197static inline int pmd_trans_huge_lock(pmd_t *pmd,
198 struct vm_area_struct *vma)
199{
200 return 0;
201}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800202#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
203
204#endif /* _LINUX_HUGE_MM_H */