blob: b826239bdce0b26a614ae0802782860348dd6fc6 [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,
Kirill A. Shutemov117b0792013-11-14 14:30:56 -080057 enum page_check_address_pmd_flag flag,
58 spinlock_t **ptl);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080059
Naoya Horiguchid8c37c42012-03-21 16:34:27 -070060#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
61#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
62
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080063#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Aneesh Kumar K.Vfde52792013-06-05 17:14:05 -070064#define HPAGE_PMD_SHIFT PMD_SHIFT
65#define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
66#define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080067
Alex Shi20995972012-05-29 15:06:31 -070068extern bool is_vma_temporary_stack(struct vm_area_struct *vma);
69
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080070#define transparent_hugepage_enabled(__vma) \
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080071 ((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))) && \
Andrea Arcangelia7d6e4e2011-02-15 19:02:45 +010076 !((__vma)->vm_flags & VM_NOHUGEPAGE) && \
77 !is_vma_temporary_stack(__vma))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080078#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))
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080084#define transparent_hugepage_use_zero_page() \
85 (transparent_hugepage_flags & \
86 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080087#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 */
94
95extern unsigned long transparent_hugepage_flags;
96extern int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
97 pmd_t *dst_pmd, pmd_t *src_pmd,
98 struct vm_area_struct *vma,
99 unsigned long addr, unsigned long end);
Shaohua Li5bc7b8a2013-04-29 15:08:36 -0700100extern int split_huge_page_to_list(struct page *page, struct list_head *list);
101static inline int split_huge_page(struct page *page)
102{
103 return split_huge_page_to_list(page, NULL);
104}
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800105extern void __split_huge_page_pmd(struct vm_area_struct *vma,
106 unsigned long address, pmd_t *pmd);
107#define split_huge_page_pmd(__vma, __address, __pmd) \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800108 do { \
109 pmd_t *____pmd = (__pmd); \
110 if (unlikely(pmd_trans_huge(*____pmd))) \
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800111 __split_huge_page_pmd(__vma, __address, \
112 ____pmd); \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800113 } while (0)
114#define wait_split_huge_page(__anon_vma, __pmd) \
115 do { \
116 pmd_t *____pmd = (__pmd); \
Ingo Molnar4fc3f1d2012-12-02 19:56:50 +0000117 anon_vma_lock_write(__anon_vma); \
Konstantin Khlebnikov08b52702013-02-22 16:34:40 -0800118 anon_vma_unlock_write(__anon_vma); \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800119 BUG_ON(pmd_trans_splitting(*____pmd) || \
120 pmd_trans_huge(*____pmd)); \
121 } while (0)
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800122extern void split_huge_page_pmd_mm(struct mm_struct *mm, unsigned long address,
123 pmd_t *pmd);
Steve Capperdfa5e232013-05-07 14:46:03 +0100124#if HPAGE_PMD_ORDER >= MAX_ORDER
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800125#error "hugepages can't be allocated by the buddy allocator"
126#endif
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800127extern int hugepage_madvise(struct vm_area_struct *vma,
128 unsigned long *vm_flags, int advice);
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800129extern void __vma_adjust_trans_huge(struct vm_area_struct *vma,
130 unsigned long start,
131 unsigned long end,
132 long adjust_next);
Kirill A. Shutemovbf929152013-11-14 14:30:54 -0800133extern int __pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma,
134 spinlock_t **ptl);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700135/* mmap_sem must be held on entry */
Kirill A. Shutemovbf929152013-11-14 14:30:54 -0800136static inline int pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma,
137 spinlock_t **ptl)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700138{
139 VM_BUG_ON(!rwsem_is_locked(&vma->vm_mm->mmap_sem));
140 if (pmd_trans_huge(*pmd))
Kirill A. Shutemovbf929152013-11-14 14:30:54 -0800141 return __pmd_trans_huge_lock(pmd, vma, ptl);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700142 else
143 return 0;
144}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800145static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
146 unsigned long start,
147 unsigned long end,
148 long adjust_next)
149{
Andrea Arcangeli78f11a22011-04-27 15:26:45 -0700150 if (!vma->anon_vma || vma->vm_ops)
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800151 return;
152 __vma_adjust_trans_huge(vma, start, end, adjust_next);
153}
Rik van Riel2c888cf2011-01-13 15:47:13 -0800154static inline int hpage_nr_pages(struct page *page)
155{
156 if (unlikely(PageTransHuge(page)))
157 return HPAGE_PMD_NR;
158 return 1;
159}
Mel Gormand10e63f2012-10-25 14:16:31 +0200160
Mel Gorman4daae3b2012-11-02 11:33:45 +0000161extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
162 unsigned long addr, pmd_t pmd, pmd_t *pmdp);
Mel Gormand10e63f2012-10-25 14:16:31 +0200163
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800164#else /* CONFIG_TRANSPARENT_HUGEPAGE */
Naoya Horiguchid8c37c42012-03-21 16:34:27 -0700165#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
166#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
167#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800168
Rik van Riel2c888cf2011-01-13 15:47:13 -0800169#define hpage_nr_pages(x) 1
170
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800171#define transparent_hugepage_enabled(__vma) 0
172
173#define transparent_hugepage_flags 0UL
Shaohua Li5bc7b8a2013-04-29 15:08:36 -0700174static inline int
175split_huge_page_to_list(struct page *page, struct list_head *list)
176{
177 return 0;
178}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800179static inline int split_huge_page(struct page *page)
180{
181 return 0;
182}
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800183#define split_huge_page_pmd(__vma, __address, __pmd) \
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800184 do { } while (0)
185#define wait_split_huge_page(__anon_vma, __pmd) \
186 do { } while (0)
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800187#define split_huge_page_pmd_mm(__mm, __address, __pmd) \
188 do { } while (0)
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800189static inline int hugepage_madvise(struct vm_area_struct *vma,
190 unsigned long *vm_flags, int advice)
Andrea Arcangeli0af4e982011-01-13 15:46:55 -0800191{
192 BUG();
193 return 0;
194}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800195static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
196 unsigned long start,
197 unsigned long end,
198 long adjust_next)
199{
200}
Kirill A. Shutemovbf929152013-11-14 14:30:54 -0800201static inline int pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma,
202 spinlock_t **ptl)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700203{
204 return 0;
205}
Mel Gormand10e63f2012-10-25 14:16:31 +0200206
Mel Gorman4daae3b2012-11-02 11:33:45 +0000207static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
208 unsigned long addr, pmd_t pmd, pmd_t *pmdp)
Mel Gormand10e63f2012-10-25 14:16:31 +0200209{
Mel Gorman4daae3b2012-11-02 11:33:45 +0000210 return 0;
Mel Gormand10e63f2012-10-25 14:16:31 +0200211}
212
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800213#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
214
215#endif /* _LINUX_HUGE_MM_H */