blob: 459fd25b378e73cfd2e911761ad845076be547de [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);
Minchan Kimb8d3c4c2016-01-15 16:55:42 -080022extern int madvise_free_huge_pmd(struct mmu_gather *tlb,
23 struct vm_area_struct *vma,
24 pmd_t *pmd, unsigned long addr, unsigned long next);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080025extern int zap_huge_pmd(struct mmu_gather *tlb,
26 struct vm_area_struct *vma,
Shaohua Lif21760b2012-01-12 17:19:16 -080027 pmd_t *pmd, unsigned long addr);
Johannes Weiner0ca16342011-01-13 15:47:02 -080028extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
29 unsigned long addr, unsigned long end,
30 unsigned char *vec);
Kirill A. Shutemov4b471e82016-01-15 16:53:39 -080031extern bool move_huge_pmd(struct vm_area_struct *vma,
Andrea Arcangeli37a1c492011-10-31 17:08:30 -070032 struct vm_area_struct *new_vma,
33 unsigned long old_addr,
34 unsigned long new_addr, unsigned long old_end,
35 pmd_t *old_pmd, pmd_t *new_pmd);
Johannes Weinercd7548a2011-01-13 15:47:04 -080036extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
Mel Gorman4b10e7d2012-10-25 14:16:32 +020037 unsigned long addr, pgprot_t newprot,
38 int prot_numa);
Matthew Wilcox5cad4652015-09-08 14:58:54 -070039int vmf_insert_pfn_pmd(struct vm_area_struct *, unsigned long addr, pmd_t *,
Dan Williamsf25748e32016-01-15 16:56:43 -080040 pfn_t pfn, bool write);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080041enum transparent_hugepage_flag {
42 TRANSPARENT_HUGEPAGE_FLAG,
43 TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
44 TRANSPARENT_HUGEPAGE_DEFRAG_FLAG,
45 TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
Andrea Arcangeliba761492011-01-13 15:46:58 -080046 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080047 TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080048#ifdef CONFIG_DEBUG_VM
49 TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG,
50#endif
51};
52
Naoya Horiguchid8c37c42012-03-21 16:34:27 -070053#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
54#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
55
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080056#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Dan Williams3565fce2016-01-15 16:56:55 -080057struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr,
58 pmd_t *pmd, int flags);
59
Aneesh Kumar K.Vfde52792013-06-05 17:14:05 -070060#define HPAGE_PMD_SHIFT PMD_SHIFT
61#define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
62#define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080063
Alex Shi20995972012-05-29 15:06:31 -070064extern bool is_vma_temporary_stack(struct vm_area_struct *vma);
65
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080066#define transparent_hugepage_enabled(__vma) \
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080067 ((transparent_hugepage_flags & \
68 (1<<TRANSPARENT_HUGEPAGE_FLAG) || \
69 (transparent_hugepage_flags & \
70 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \
71 ((__vma)->vm_flags & VM_HUGEPAGE))) && \
Andrea Arcangelia7d6e4e2011-02-15 19:02:45 +010072 !((__vma)->vm_flags & VM_NOHUGEPAGE) && \
73 !is_vma_temporary_stack(__vma))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080074#define transparent_hugepage_defrag(__vma) \
75 ((transparent_hugepage_flags & \
76 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \
77 (transparent_hugepage_flags & \
78 (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \
79 (__vma)->vm_flags & VM_HUGEPAGE))
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080080#define transparent_hugepage_use_zero_page() \
81 (transparent_hugepage_flags & \
82 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080083#ifdef CONFIG_DEBUG_VM
84#define transparent_hugepage_debug_cow() \
85 (transparent_hugepage_flags & \
86 (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
87#else /* CONFIG_DEBUG_VM */
88#define transparent_hugepage_debug_cow() 0
89#endif /* CONFIG_DEBUG_VM */
90
91extern unsigned long transparent_hugepage_flags;
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -080092
Kirill A. Shutemov9a982252016-01-15 16:54:17 -080093extern void prep_transhuge_page(struct page *page);
94extern void free_transhuge_page(struct page *page);
95
Kirill A. Shutemove9b61f12016-01-15 16:54:10 -080096int split_huge_page_to_list(struct page *page, struct list_head *list);
97static inline int split_huge_page(struct page *page)
98{
99 return split_huge_page_to_list(page, NULL);
100}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800101void deferred_split_huge_page(struct page *page);
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800102
103void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
104 unsigned long address);
105
106#define split_huge_pmd(__vma, __pmd, __address) \
107 do { \
108 pmd_t *____pmd = (__pmd); \
Dan Williams5c7fb562016-01-15 16:56:52 -0800109 if (pmd_trans_huge(*____pmd) \
110 || pmd_devmap(*____pmd)) \
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800111 __split_huge_pmd(__vma, __pmd, __address); \
112 } while (0)
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -0800113
Steve Capperdfa5e232013-05-07 14:46:03 +0100114#if HPAGE_PMD_ORDER >= MAX_ORDER
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800115#error "hugepages can't be allocated by the buddy allocator"
116#endif
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800117extern int hugepage_madvise(struct vm_area_struct *vma,
118 unsigned long *vm_flags, int advice);
Kirill A. Shutemove1b99962015-09-08 14:58:37 -0700119extern void vma_adjust_trans_huge(struct vm_area_struct *vma,
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800120 unsigned long start,
121 unsigned long end,
122 long adjust_next);
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800123extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd,
124 struct vm_area_struct *vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700125/* mmap_sem must be held on entry */
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800126static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
127 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700128{
Sasha Levin81d1b092014-10-09 15:28:10 -0700129 VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma);
Dan Williams5c7fb562016-01-15 16:56:52 -0800130 if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd))
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800131 return __pmd_trans_huge_lock(pmd, vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700132 else
Kirill A. Shutemov4b471e82016-01-15 16:53:39 -0800133 return false;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700134}
Rik van Riel2c888cf2011-01-13 15:47:13 -0800135static inline int hpage_nr_pages(struct page *page)
136{
137 if (unlikely(PageTransHuge(page)))
138 return HPAGE_PMD_NR;
139 return 1;
140}
Mel Gormand10e63f2012-10-25 14:16:31 +0200141
Mel Gorman4daae3b2012-11-02 11:33:45 +0000142extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
143 unsigned long addr, pmd_t pmd, pmd_t *pmdp);
Mel Gormand10e63f2012-10-25 14:16:31 +0200144
Wang, Yalin56873f42015-02-11 15:24:51 -0800145extern struct page *huge_zero_page;
146
147static inline bool is_huge_zero_page(struct page *page)
148{
149 return ACCESS_ONCE(huge_zero_page) == page;
150}
151
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700152static inline bool is_huge_zero_pmd(pmd_t pmd)
153{
154 return is_huge_zero_page(pmd_page(pmd));
155}
156
157struct page *get_huge_zero_page(void);
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700158
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800159#else /* CONFIG_TRANSPARENT_HUGEPAGE */
Naoya Horiguchid8c37c42012-03-21 16:34:27 -0700160#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
161#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
162#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800163
Rik van Riel2c888cf2011-01-13 15:47:13 -0800164#define hpage_nr_pages(x) 1
165
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800166#define transparent_hugepage_enabled(__vma) 0
167
168#define transparent_hugepage_flags 0UL
Shaohua Li5bc7b8a2013-04-29 15:08:36 -0700169static inline int
170split_huge_page_to_list(struct page *page, struct list_head *list)
171{
172 return 0;
173}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800174static inline int split_huge_page(struct page *page)
175{
176 return 0;
177}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800178static inline void deferred_split_huge_page(struct page *page) {}
Kirill A. Shutemov78ddc532016-01-15 16:52:42 -0800179#define split_huge_pmd(__vma, __pmd, __address) \
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800180 do { } while (0)
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800181static inline int hugepage_madvise(struct vm_area_struct *vma,
182 unsigned long *vm_flags, int advice)
Andrea Arcangeli0af4e982011-01-13 15:46:55 -0800183{
184 BUG();
185 return 0;
186}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800187static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
188 unsigned long start,
189 unsigned long end,
190 long adjust_next)
191{
192}
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800193static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
194 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700195{
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800196 return NULL;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700197}
Mel Gormand10e63f2012-10-25 14:16:31 +0200198
Mel Gorman4daae3b2012-11-02 11:33:45 +0000199static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
200 unsigned long addr, pmd_t pmd, pmd_t *pmdp)
Mel Gormand10e63f2012-10-25 14:16:31 +0200201{
Mel Gorman4daae3b2012-11-02 11:33:45 +0000202 return 0;
Mel Gormand10e63f2012-10-25 14:16:31 +0200203}
204
Wang, Yalin56873f42015-02-11 15:24:51 -0800205static inline bool is_huge_zero_page(struct page *page)
206{
207 return false;
208}
209
Dan Williams3565fce2016-01-15 16:56:55 -0800210
211static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma,
212 unsigned long addr, pmd_t *pmd, int flags)
213{
214 return NULL;
215}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800216#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
217
218#endif /* _LINUX_HUGE_MM_H */