blob: a3762d49ba397244f105bade8ee058879c2f08e4 [file] [log] [blame]
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -08001#ifndef _LINUX_HUGE_MM_H
2#define _LINUX_HUGE_MM_H
3
Jan Kara82b0f8c2016-12-14 15:06:58 -08004extern int do_huge_pmd_anonymous_page(struct vm_fault *vmf);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -08005extern int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
6 pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr,
7 struct vm_area_struct *vma);
Jan Kara82b0f8c2016-12-14 15:06:58 -08008extern void huge_pmd_set_accessed(struct vm_fault *vmf, pmd_t orig_pmd);
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -08009extern int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm,
10 pud_t *dst_pud, pud_t *src_pud, unsigned long addr,
11 struct vm_area_struct *vma);
12
13#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
14extern void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud);
15#else
16static inline void huge_pud_set_accessed(struct vm_fault *vmf, pud_t orig_pud)
17{
18}
19#endif
20
Jan Kara82b0f8c2016-12-14 15:06:58 -080021extern int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd);
David Rientjesb676b292012-10-08 16:34:03 -070022extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080023 unsigned long addr,
24 pmd_t *pmd,
25 unsigned int flags);
Huang Ying319904a2016-07-28 15:48:03 -070026extern bool madvise_free_huge_pmd(struct mmu_gather *tlb,
Minchan Kimb8d3c4c2016-01-15 16:55:42 -080027 struct vm_area_struct *vma,
28 pmd_t *pmd, unsigned long addr, unsigned long next);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080029extern int zap_huge_pmd(struct mmu_gather *tlb,
30 struct vm_area_struct *vma,
Shaohua Lif21760b2012-01-12 17:19:16 -080031 pmd_t *pmd, unsigned long addr);
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -080032extern int zap_huge_pud(struct mmu_gather *tlb,
33 struct vm_area_struct *vma,
34 pud_t *pud, unsigned long addr);
Johannes Weiner0ca16342011-01-13 15:47:02 -080035extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
36 unsigned long addr, unsigned long end,
37 unsigned char *vec);
Hugh Dickinsbf8616d2016-05-19 17:12:54 -070038extern bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
Andrea Arcangeli37a1c492011-10-31 17:08:30 -070039 unsigned long new_addr, unsigned long old_end,
Aaron Lu5d190422016-11-10 17:16:33 +080040 pmd_t *old_pmd, pmd_t *new_pmd, bool *need_flush);
Johannes Weinercd7548a2011-01-13 15:47:04 -080041extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
Mel Gorman4b10e7d2012-10-25 14:16:32 +020042 unsigned long addr, pgprot_t newprot,
43 int prot_numa);
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -080044int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
45 pmd_t *pmd, pfn_t pfn, bool write);
46int vmf_insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
47 pud_t *pud, pfn_t pfn, bool write);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080048enum transparent_hugepage_flag {
49 TRANSPARENT_HUGEPAGE_FLAG,
50 TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
Mel Gorman444eb2a42016-03-17 14:19:23 -070051 TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
52 TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
David Rientjes21440d72017-02-22 15:45:49 -080053 TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080054 TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
Andrea Arcangeliba761492011-01-13 15:46:58 -080055 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080056 TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080057#ifdef CONFIG_DEBUG_VM
58 TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG,
59#endif
60};
61
Kirill A. Shutemovb46e7562016-07-26 15:26:24 -070062struct kobject;
63struct kobj_attribute;
64
65extern ssize_t single_hugepage_flag_store(struct kobject *kobj,
66 struct kobj_attribute *attr,
67 const char *buf, size_t count,
68 enum transparent_hugepage_flag flag);
69extern ssize_t single_hugepage_flag_show(struct kobject *kobj,
70 struct kobj_attribute *attr, char *buf,
71 enum transparent_hugepage_flag flag);
Kirill A. Shutemov5a6e75f2016-07-26 15:26:13 -070072extern struct kobj_attribute shmem_enabled_attr;
73
Naoya Horiguchid8c37c42012-03-21 16:34:27 -070074#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
75#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
76
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080077#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Aneesh Kumar K.Vfde52792013-06-05 17:14:05 -070078#define HPAGE_PMD_SHIFT PMD_SHIFT
79#define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
80#define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080081
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -080082#define HPAGE_PUD_SHIFT PUD_SHIFT
83#define HPAGE_PUD_SIZE ((1UL) << HPAGE_PUD_SHIFT)
84#define HPAGE_PUD_MASK (~(HPAGE_PUD_SIZE - 1))
85
Alex Shi20995972012-05-29 15:06:31 -070086extern bool is_vma_temporary_stack(struct vm_area_struct *vma);
87
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080088#define transparent_hugepage_enabled(__vma) \
Andrea Arcangelia664b2d2011-01-13 15:47:17 -080089 ((transparent_hugepage_flags & \
90 (1<<TRANSPARENT_HUGEPAGE_FLAG) || \
91 (transparent_hugepage_flags & \
92 (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \
93 ((__vma)->vm_flags & VM_HUGEPAGE))) && \
Andrea Arcangelia7d6e4e2011-02-15 19:02:45 +010094 !((__vma)->vm_flags & VM_NOHUGEPAGE) && \
95 !is_vma_temporary_stack(__vma))
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080096#define transparent_hugepage_use_zero_page() \
97 (transparent_hugepage_flags & \
98 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080099#ifdef CONFIG_DEBUG_VM
100#define transparent_hugepage_debug_cow() \
101 (transparent_hugepage_flags & \
102 (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
103#else /* CONFIG_DEBUG_VM */
104#define transparent_hugepage_debug_cow() 0
105#endif /* CONFIG_DEBUG_VM */
106
107extern unsigned long transparent_hugepage_flags;
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -0800108
Toshi Kani74d2fad2016-10-07 16:59:56 -0700109extern unsigned long thp_get_unmapped_area(struct file *filp,
110 unsigned long addr, unsigned long len, unsigned long pgoff,
111 unsigned long flags);
112
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800113extern void prep_transhuge_page(struct page *page);
114extern void free_transhuge_page(struct page *page);
115
Kirill A. Shutemove9b61f12016-01-15 16:54:10 -0800116int split_huge_page_to_list(struct page *page, struct list_head *list);
117static inline int split_huge_page(struct page *page)
118{
119 return split_huge_page_to_list(page, NULL);
120}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800121void deferred_split_huge_page(struct page *page);
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800122
123void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
Naoya Horiguchi33f47512016-07-14 12:07:32 -0700124 unsigned long address, bool freeze, struct page *page);
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800125
126#define split_huge_pmd(__vma, __pmd, __address) \
127 do { \
128 pmd_t *____pmd = (__pmd); \
Dan Williams5c7fb562016-01-15 16:56:52 -0800129 if (pmd_trans_huge(*____pmd) \
130 || pmd_devmap(*____pmd)) \
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700131 __split_huge_pmd(__vma, __pmd, __address, \
Naoya Horiguchi33f47512016-07-14 12:07:32 -0700132 false, NULL); \
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800133 } while (0)
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -0800134
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700135
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700136void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address,
137 bool freeze, struct page *page);
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700138
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800139void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud,
140 unsigned long address);
141
142#define split_huge_pud(__vma, __pud, __address) \
143 do { \
144 pud_t *____pud = (__pud); \
145 if (pud_trans_huge(*____pud) \
146 || pud_devmap(*____pud)) \
147 __split_huge_pud(__vma, __pud, __address); \
148 } while (0)
149
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800150extern int hugepage_madvise(struct vm_area_struct *vma,
151 unsigned long *vm_flags, int advice);
Kirill A. Shutemove1b99962015-09-08 14:58:37 -0700152extern void vma_adjust_trans_huge(struct vm_area_struct *vma,
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800153 unsigned long start,
154 unsigned long end,
155 long adjust_next);
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800156extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd,
157 struct vm_area_struct *vma);
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800158extern spinlock_t *__pud_trans_huge_lock(pud_t *pud,
159 struct vm_area_struct *vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700160/* mmap_sem must be held on entry */
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800161static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
162 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700163{
Sasha Levin81d1b092014-10-09 15:28:10 -0700164 VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma);
Dan Williams5c7fb562016-01-15 16:56:52 -0800165 if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd))
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800166 return __pmd_trans_huge_lock(pmd, vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700167 else
Chen Gang969e8d72016-04-01 14:31:17 -0700168 return NULL;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700169}
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800170static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
171 struct vm_area_struct *vma)
172{
173 VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma);
174 if (pud_trans_huge(*pud) || pud_devmap(*pud))
175 return __pud_trans_huge_lock(pud, vma);
176 else
177 return NULL;
178}
Rik van Riel2c888cf2011-01-13 15:47:13 -0800179static inline int hpage_nr_pages(struct page *page)
180{
181 if (unlikely(PageTransHuge(page)))
182 return HPAGE_PMD_NR;
183 return 1;
184}
Mel Gormand10e63f2012-10-25 14:16:31 +0200185
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800186struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr,
187 pmd_t *pmd, int flags);
188struct page *follow_devmap_pud(struct vm_area_struct *vma, unsigned long addr,
189 pud_t *pud, int flags);
190
Jan Kara82b0f8c2016-12-14 15:06:58 -0800191extern int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t orig_pmd);
Mel Gormand10e63f2012-10-25 14:16:31 +0200192
Wang, Yalin56873f42015-02-11 15:24:51 -0800193extern struct page *huge_zero_page;
194
195static inline bool is_huge_zero_page(struct page *page)
196{
197 return ACCESS_ONCE(huge_zero_page) == page;
198}
199
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700200static inline bool is_huge_zero_pmd(pmd_t pmd)
201{
202 return is_huge_zero_page(pmd_page(pmd));
203}
204
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800205static inline bool is_huge_zero_pud(pud_t pud)
206{
207 return false;
208}
209
Aaron Lu6fcb52a2016-10-07 17:00:08 -0700210struct page *mm_get_huge_zero_page(struct mm_struct *mm);
211void mm_put_huge_zero_page(struct mm_struct *mm);
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700212
Kirill A. Shutemov10102452016-07-26 15:25:29 -0700213#define mk_huge_pmd(page, prot) pmd_mkhuge(mk_pmd(page, prot))
214
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800215#else /* CONFIG_TRANSPARENT_HUGEPAGE */
Naoya Horiguchid8c37c42012-03-21 16:34:27 -0700216#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
217#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
218#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800219
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800220#define HPAGE_PUD_SHIFT ({ BUILD_BUG(); 0; })
221#define HPAGE_PUD_MASK ({ BUILD_BUG(); 0; })
222#define HPAGE_PUD_SIZE ({ BUILD_BUG(); 0; })
223
Rik van Riel2c888cf2011-01-13 15:47:13 -0800224#define hpage_nr_pages(x) 1
225
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800226#define transparent_hugepage_enabled(__vma) 0
227
Kirill A. Shutemov800d8c62016-07-26 15:26:18 -0700228static inline void prep_transhuge_page(struct page *page) {}
229
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800230#define transparent_hugepage_flags 0UL
Toshi Kani74d2fad2016-10-07 16:59:56 -0700231
232#define thp_get_unmapped_area NULL
233
Shaohua Li5bc7b8a2013-04-29 15:08:36 -0700234static inline int
235split_huge_page_to_list(struct page *page, struct list_head *list)
236{
237 return 0;
238}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800239static inline int split_huge_page(struct page *page)
240{
241 return 0;
242}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800243static inline void deferred_split_huge_page(struct page *page) {}
Kirill A. Shutemov78ddc532016-01-15 16:52:42 -0800244#define split_huge_pmd(__vma, __pmd, __address) \
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800245 do { } while (0)
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700246
David Rientjesfd607752016-12-12 16:42:20 -0800247static inline void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
248 unsigned long address, bool freeze, struct page *page) {}
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700249static inline void split_huge_pmd_address(struct vm_area_struct *vma,
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700250 unsigned long address, bool freeze, struct page *page) {}
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700251
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800252#define split_huge_pud(__vma, __pmd, __address) \
253 do { } while (0)
254
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800255static inline int hugepage_madvise(struct vm_area_struct *vma,
256 unsigned long *vm_flags, int advice)
Andrea Arcangeli0af4e982011-01-13 15:46:55 -0800257{
258 BUG();
259 return 0;
260}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800261static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
262 unsigned long start,
263 unsigned long end,
264 long adjust_next)
265{
266}
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800267static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
268 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700269{
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800270 return NULL;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700271}
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800272static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
273 struct vm_area_struct *vma)
274{
275 return NULL;
276}
Mel Gormand10e63f2012-10-25 14:16:31 +0200277
Jan Kara82b0f8c2016-12-14 15:06:58 -0800278static inline int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t orig_pmd)
Mel Gormand10e63f2012-10-25 14:16:31 +0200279{
Mel Gorman4daae3b2012-11-02 11:33:45 +0000280 return 0;
Mel Gormand10e63f2012-10-25 14:16:31 +0200281}
282
Wang, Yalin56873f42015-02-11 15:24:51 -0800283static inline bool is_huge_zero_page(struct page *page)
284{
285 return false;
286}
287
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800288static inline bool is_huge_zero_pud(pud_t pud)
289{
290 return false;
291}
292
Aaron Lu6fcb52a2016-10-07 17:00:08 -0700293static inline void mm_put_huge_zero_page(struct mm_struct *mm)
Kirill A. Shutemovaa88b682016-04-28 16:18:27 -0700294{
Aaron Lu6fcb52a2016-10-07 17:00:08 -0700295 return;
Kirill A. Shutemovaa88b682016-04-28 16:18:27 -0700296}
Dan Williams3565fce2016-01-15 16:56:55 -0800297
298static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma,
299 unsigned long addr, pmd_t *pmd, int flags)
300{
301 return NULL;
302}
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -0800303
304static inline struct page *follow_devmap_pud(struct vm_area_struct *vma,
305 unsigned long addr, pud_t *pud, int flags)
306{
307 return NULL;
308}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800309#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
310
311#endif /* _LINUX_HUGE_MM_H */