blob: 79b0ef6aaa143d4f093f9f3cd7f9ad19a4421258 [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,
Mel Gorman444eb2a42016-03-17 14:19:23 -070044 TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
45 TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080046 TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
Andrea Arcangeliba761492011-01-13 15:46:58 -080047 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080048 TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080049#ifdef CONFIG_DEBUG_VM
50 TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG,
51#endif
52};
53
Naoya Horiguchid8c37c42012-03-21 16:34:27 -070054#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
55#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
56
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080057#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Dan Williams3565fce2016-01-15 16:56:55 -080058struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr,
59 pmd_t *pmd, int flags);
60
Aneesh Kumar K.Vfde52792013-06-05 17:14:05 -070061#define HPAGE_PMD_SHIFT PMD_SHIFT
62#define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
63#define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080064
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))
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080075#define transparent_hugepage_use_zero_page() \
76 (transparent_hugepage_flags & \
77 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080078#ifdef CONFIG_DEBUG_VM
79#define transparent_hugepage_debug_cow() \
80 (transparent_hugepage_flags & \
81 (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
82#else /* CONFIG_DEBUG_VM */
83#define transparent_hugepage_debug_cow() 0
84#endif /* CONFIG_DEBUG_VM */
85
86extern unsigned long transparent_hugepage_flags;
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -080087
Kirill A. Shutemov9a982252016-01-15 16:54:17 -080088extern void prep_transhuge_page(struct page *page);
89extern void free_transhuge_page(struct page *page);
90
Kirill A. Shutemove9b61f12016-01-15 16:54:10 -080091int split_huge_page_to_list(struct page *page, struct list_head *list);
92static inline int split_huge_page(struct page *page)
93{
94 return split_huge_page_to_list(page, NULL);
95}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -080096void deferred_split_huge_page(struct page *page);
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -080097
98void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -070099 unsigned long address, bool freeze);
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800100
101#define split_huge_pmd(__vma, __pmd, __address) \
102 do { \
103 pmd_t *____pmd = (__pmd); \
Dan Williams5c7fb562016-01-15 16:56:52 -0800104 if (pmd_trans_huge(*____pmd) \
105 || pmd_devmap(*____pmd)) \
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700106 __split_huge_pmd(__vma, __pmd, __address, \
107 false); \
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800108 } while (0)
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -0800109
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700110
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700111void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address,
112 bool freeze, struct page *page);
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700113
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800114extern int hugepage_madvise(struct vm_area_struct *vma,
115 unsigned long *vm_flags, int advice);
Kirill A. Shutemove1b99962015-09-08 14:58:37 -0700116extern void vma_adjust_trans_huge(struct vm_area_struct *vma,
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800117 unsigned long start,
118 unsigned long end,
119 long adjust_next);
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800120extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd,
121 struct vm_area_struct *vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700122/* mmap_sem must be held on entry */
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800123static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
124 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700125{
Sasha Levin81d1b092014-10-09 15:28:10 -0700126 VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma);
Dan Williams5c7fb562016-01-15 16:56:52 -0800127 if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd))
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800128 return __pmd_trans_huge_lock(pmd, vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700129 else
Kirill A. Shutemov4b471e82016-01-15 16:53:39 -0800130 return false;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700131}
Rik van Riel2c888cf2011-01-13 15:47:13 -0800132static inline int hpage_nr_pages(struct page *page)
133{
134 if (unlikely(PageTransHuge(page)))
135 return HPAGE_PMD_NR;
136 return 1;
137}
Mel Gormand10e63f2012-10-25 14:16:31 +0200138
Mel Gorman4daae3b2012-11-02 11:33:45 +0000139extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
140 unsigned long addr, pmd_t pmd, pmd_t *pmdp);
Mel Gormand10e63f2012-10-25 14:16:31 +0200141
Wang, Yalin56873f42015-02-11 15:24:51 -0800142extern struct page *huge_zero_page;
143
144static inline bool is_huge_zero_page(struct page *page)
145{
146 return ACCESS_ONCE(huge_zero_page) == page;
147}
148
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700149static inline bool is_huge_zero_pmd(pmd_t pmd)
150{
151 return is_huge_zero_page(pmd_page(pmd));
152}
153
154struct page *get_huge_zero_page(void);
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700155
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800156#else /* CONFIG_TRANSPARENT_HUGEPAGE */
Naoya Horiguchid8c37c42012-03-21 16:34:27 -0700157#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
158#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
159#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800160
Rik van Riel2c888cf2011-01-13 15:47:13 -0800161#define hpage_nr_pages(x) 1
162
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800163#define transparent_hugepage_enabled(__vma) 0
164
165#define transparent_hugepage_flags 0UL
Shaohua Li5bc7b8a2013-04-29 15:08:36 -0700166static inline int
167split_huge_page_to_list(struct page *page, struct list_head *list)
168{
169 return 0;
170}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800171static inline int split_huge_page(struct page *page)
172{
173 return 0;
174}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800175static inline void deferred_split_huge_page(struct page *page) {}
Kirill A. Shutemov78ddc532016-01-15 16:52:42 -0800176#define split_huge_pmd(__vma, __pmd, __address) \
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800177 do { } while (0)
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700178
179static inline void split_huge_pmd_address(struct vm_area_struct *vma,
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700180 unsigned long address, bool freeze, struct page *page) {}
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700181
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800182static inline int hugepage_madvise(struct vm_area_struct *vma,
183 unsigned long *vm_flags, int advice)
Andrea Arcangeli0af4e982011-01-13 15:46:55 -0800184{
185 BUG();
186 return 0;
187}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800188static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
189 unsigned long start,
190 unsigned long end,
191 long adjust_next)
192{
193}
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800194static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
195 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700196{
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800197 return NULL;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700198}
Mel Gormand10e63f2012-10-25 14:16:31 +0200199
Mel Gorman4daae3b2012-11-02 11:33:45 +0000200static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
201 unsigned long addr, pmd_t pmd, pmd_t *pmdp)
Mel Gormand10e63f2012-10-25 14:16:31 +0200202{
Mel Gorman4daae3b2012-11-02 11:33:45 +0000203 return 0;
Mel Gormand10e63f2012-10-25 14:16:31 +0200204}
205
Wang, Yalin56873f42015-02-11 15:24:51 -0800206static inline bool is_huge_zero_page(struct page *page)
207{
208 return false;
209}
210
Dan Williams3565fce2016-01-15 16:56:55 -0800211
212static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma,
213 unsigned long addr, pmd_t *pmd, int flags)
214{
215 return NULL;
216}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800217#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
218
219#endif /* _LINUX_HUGE_MM_H */