blob: 3935428c57cff80d01236428fdea979d7a9f911b [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,
Mel Gorman4b10e7d2012-10-25 14:16:32 +020034 unsigned long addr, pgprot_t newprot,
35 int prot_numa);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080036
37enum 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,
Andrea Arcangeliba761492011-01-13 15:46:58 -080042 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080043 TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080044#ifdef CONFIG_DEBUG_VM
45 TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG,
46#endif
47};
48
49enum 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,
53};
54extern pmd_t *page_check_address_pmd(struct page *page,
55 struct mm_struct *mm,
56 unsigned long address,
57 enum page_check_address_pmd_flag flag);
58
Naoya Horiguchid8c37c42012-03-21 16:34:27 -070059#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
60#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
61
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080062#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Aneesh Kumar K.Vfde52792013-06-05 17:14:05 -070063#define HPAGE_PMD_SHIFT PMD_SHIFT
64#define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
65#define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080066
Alex Shi20995972012-05-29 15:06:31 -070067extern bool is_vma_temporary_stack(struct vm_area_struct *vma);
68
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080069#define transparent_hugepage_enabled(__vma) \
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080070 ((transparent_hugepage_flags & \
71 (1<<TRANSPARENT_HUGEPAGE_FLAG) || \
72 (transparent_hugepage_flags & \
73 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \
74 ((__vma)->vm_flags & VM_HUGEPAGE))) && \
Andrea Arcangelia7d6e4e2011-02-15 19:02:45 +010075 !((__vma)->vm_flags & VM_NOHUGEPAGE) && \
76 !is_vma_temporary_stack(__vma))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080077#define transparent_hugepage_defrag(__vma) \
78 ((transparent_hugepage_flags & \
79 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \
80 (transparent_hugepage_flags & \
81 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \
82 (__vma)->vm_flags & VM_HUGEPAGE))
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080083#define transparent_hugepage_use_zero_page() \
84 (transparent_hugepage_flags & \
85 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080086#ifdef CONFIG_DEBUG_VM
87#define transparent_hugepage_debug_cow() \
88 (transparent_hugepage_flags & \
89 (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
90#else /* CONFIG_DEBUG_VM */
91#define transparent_hugepage_debug_cow() 0
92#endif /* CONFIG_DEBUG_VM */
93
94extern unsigned long transparent_hugepage_flags;
95extern int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
96 pmd_t *dst_pmd, pmd_t *src_pmd,
97 struct vm_area_struct *vma,
98 unsigned long addr, unsigned long end);
Shaohua Li5bc7b8a2013-04-29 15:08:36 -070099extern int split_huge_page_to_list(struct page *page, struct list_head *list);
100static inline int split_huge_page(struct page *page)
101{
102 return split_huge_page_to_list(page, NULL);
103}
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800104extern void __split_huge_page_pmd(struct vm_area_struct *vma,
105 unsigned long address, pmd_t *pmd);
106#define split_huge_page_pmd(__vma, __address, __pmd) \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800107 do { \
108 pmd_t *____pmd = (__pmd); \
109 if (unlikely(pmd_trans_huge(*____pmd))) \
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800110 __split_huge_page_pmd(__vma, __address, \
111 ____pmd); \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800112 } while (0)
113#define wait_split_huge_page(__anon_vma, __pmd) \
114 do { \
115 pmd_t *____pmd = (__pmd); \
Ingo Molnar4fc3f1d2012-12-02 19:56:50 +0000116 anon_vma_lock_write(__anon_vma); \
Konstantin Khlebnikov08b52702013-02-22 16:34:40 -0800117 anon_vma_unlock_write(__anon_vma); \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800118 BUG_ON(pmd_trans_splitting(*____pmd) || \
119 pmd_trans_huge(*____pmd)); \
120 } while (0)
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800121extern void split_huge_page_pmd_mm(struct mm_struct *mm, unsigned long address,
122 pmd_t *pmd);
Steve Capperdfa5e232013-05-07 14:46:03 +0100123#if HPAGE_PMD_ORDER >= MAX_ORDER
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800124#error "hugepages can't be allocated by the buddy allocator"
125#endif
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800126extern int hugepage_madvise(struct vm_area_struct *vma,
127 unsigned long *vm_flags, int advice);
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800128extern void __vma_adjust_trans_huge(struct vm_area_struct *vma,
129 unsigned long start,
130 unsigned long end,
131 long adjust_next);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700132extern int __pmd_trans_huge_lock(pmd_t *pmd,
133 struct vm_area_struct *vma);
134/* mmap_sem must be held on entry */
135static inline int pmd_trans_huge_lock(pmd_t *pmd,
136 struct vm_area_struct *vma)
137{
138 VM_BUG_ON(!rwsem_is_locked(&vma->vm_mm->mmap_sem));
139 if (pmd_trans_huge(*pmd))
140 return __pmd_trans_huge_lock(pmd, vma);
141 else
142 return 0;
143}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800144static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
145 unsigned long start,
146 unsigned long end,
147 long adjust_next)
148{
Andrea Arcangeli78f11a22011-04-27 15:26:45 -0700149 if (!vma->anon_vma || vma->vm_ops)
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800150 return;
151 __vma_adjust_trans_huge(vma, start, end, adjust_next);
152}
Rik van Riel2c888cf2011-01-13 15:47:13 -0800153static inline int hpage_nr_pages(struct page *page)
154{
155 if (unlikely(PageTransHuge(page)))
156 return HPAGE_PMD_NR;
157 return 1;
158}
Andrea Arcangeli22e5c472011-01-13 15:47:20 -0800159static inline struct page *compound_trans_head(struct page *page)
160{
161 if (PageTail(page)) {
162 struct page *head;
163 head = page->first_page;
164 smp_rmb();
165 /*
166 * head may be a dangling pointer.
167 * __split_huge_page_refcount clears PageTail before
168 * overwriting first_page, so if PageTail is still
169 * there it means the head pointer isn't dangling.
170 */
171 if (PageTail(page))
172 return head;
173 }
174 return page;
175}
Mel Gormand10e63f2012-10-25 14:16:31 +0200176
Mel Gorman4daae3b2012-11-02 11:33:45 +0000177extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
178 unsigned long addr, pmd_t pmd, pmd_t *pmdp);
Mel Gormand10e63f2012-10-25 14:16:31 +0200179
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800180#else /* CONFIG_TRANSPARENT_HUGEPAGE */
Naoya Horiguchid8c37c42012-03-21 16:34:27 -0700181#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
182#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
183#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800184
Rik van Riel2c888cf2011-01-13 15:47:13 -0800185#define hpage_nr_pages(x) 1
186
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800187#define transparent_hugepage_enabled(__vma) 0
188
189#define transparent_hugepage_flags 0UL
Shaohua Li5bc7b8a2013-04-29 15:08:36 -0700190static inline int
191split_huge_page_to_list(struct page *page, struct list_head *list)
192{
193 return 0;
194}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800195static inline int split_huge_page(struct page *page)
196{
197 return 0;
198}
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800199#define split_huge_page_pmd(__vma, __address, __pmd) \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800200 do { } while (0)
201#define wait_split_huge_page(__anon_vma, __pmd) \
202 do { } while (0)
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800203#define split_huge_page_pmd_mm(__mm, __address, __pmd) \
204 do { } while (0)
Andrea Arcangeli22e5c472011-01-13 15:47:20 -0800205#define compound_trans_head(page) compound_head(page)
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800206static inline int hugepage_madvise(struct vm_area_struct *vma,
207 unsigned long *vm_flags, int advice)
Andrea Arcangeli0af4e982011-01-13 15:46:55 -0800208{
209 BUG();
210 return 0;
211}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800212static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
213 unsigned long start,
214 unsigned long end,
215 long adjust_next)
216{
217}
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700218static inline int pmd_trans_huge_lock(pmd_t *pmd,
219 struct vm_area_struct *vma)
220{
221 return 0;
222}
Mel Gormand10e63f2012-10-25 14:16:31 +0200223
Mel Gorman4daae3b2012-11-02 11:33:45 +0000224static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
225 unsigned long addr, pmd_t pmd, pmd_t *pmdp)
Mel Gormand10e63f2012-10-25 14:16:31 +0200226{
Mel Gorman4daae3b2012-11-02 11:33:45 +0000227 return 0;
Mel Gormand10e63f2012-10-25 14:16:31 +0200228}
229
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800230#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
231
232#endif /* _LINUX_HUGE_MM_H */