blob: e35e6de633b9a7bc2a080d6b3596aa16e8c8582f [file] [log] [blame]
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -08001#ifndef _LINUX_HUGE_MM_H
2#define _LINUX_HUGE_MM_H
3
Kirill A. Shutemovbae473a2016-07-26 15:25:20 -07004extern int do_huge_pmd_anonymous_page(struct fault_env *fe);
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);
Kirill A. Shutemovbae473a2016-07-26 15:25:20 -07008extern void huge_pmd_set_accessed(struct fault_env *fe, pmd_t orig_pmd);
9extern int do_huge_pmd_wp_page(struct fault_env *fe, pmd_t orig_pmd);
David Rientjesb676b292012-10-08 16:34:03 -070010extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080011 unsigned long addr,
12 pmd_t *pmd,
13 unsigned int flags);
Huang Ying319904a2016-07-28 15:48:03 -070014extern bool madvise_free_huge_pmd(struct mmu_gather *tlb,
Minchan Kimb8d3c4c2016-01-15 16:55:42 -080015 struct vm_area_struct *vma,
16 pmd_t *pmd, unsigned long addr, unsigned long next);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080017extern int zap_huge_pmd(struct mmu_gather *tlb,
18 struct vm_area_struct *vma,
Shaohua Lif21760b2012-01-12 17:19:16 -080019 pmd_t *pmd, unsigned long addr);
Johannes Weiner0ca16342011-01-13 15:47:02 -080020extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
21 unsigned long addr, unsigned long end,
22 unsigned char *vec);
Hugh Dickinsbf8616d2016-05-19 17:12:54 -070023extern bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
Andrea Arcangeli37a1c492011-10-31 17:08:30 -070024 unsigned long new_addr, unsigned long old_end,
Aaron Lu5d190422016-11-10 17:16:33 +080025 pmd_t *old_pmd, pmd_t *new_pmd, bool *need_flush);
Johannes Weinercd7548a2011-01-13 15:47:04 -080026extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
Mel Gorman4b10e7d2012-10-25 14:16:32 +020027 unsigned long addr, pgprot_t newprot,
28 int prot_numa);
Matthew Wilcox5cad4652015-09-08 14:58:54 -070029int vmf_insert_pfn_pmd(struct vm_area_struct *, unsigned long addr, pmd_t *,
Dan Williamsf25748e32016-01-15 16:56:43 -080030 pfn_t pfn, bool write);
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080031enum transparent_hugepage_flag {
32 TRANSPARENT_HUGEPAGE_FLAG,
33 TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
Mel Gorman444eb2a42016-03-17 14:19:23 -070034 TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
35 TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080036 TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
Andrea Arcangeliba761492011-01-13 15:46:58 -080037 TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080038 TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG,
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080039#ifdef CONFIG_DEBUG_VM
40 TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG,
41#endif
42};
43
Kirill A. Shutemovb46e7562016-07-26 15:26:24 -070044struct kobject;
45struct kobj_attribute;
46
47extern ssize_t single_hugepage_flag_store(struct kobject *kobj,
48 struct kobj_attribute *attr,
49 const char *buf, size_t count,
50 enum transparent_hugepage_flag flag);
51extern ssize_t single_hugepage_flag_show(struct kobject *kobj,
52 struct kobj_attribute *attr, char *buf,
53 enum transparent_hugepage_flag flag);
Kirill A. Shutemov5a6e75f2016-07-26 15:26:13 -070054extern struct kobj_attribute shmem_enabled_attr;
55
Naoya Horiguchid8c37c42012-03-21 16:34:27 -070056#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
57#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
58
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080059#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Dan Williams3565fce2016-01-15 16:56:55 -080060struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr,
61 pmd_t *pmd, int flags);
62
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))
Kirill A. Shutemov79da5402012-12-12 13:51:12 -080077#define transparent_hugepage_use_zero_page() \
78 (transparent_hugepage_flags & \
79 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -080080#ifdef CONFIG_DEBUG_VM
81#define transparent_hugepage_debug_cow() \
82 (transparent_hugepage_flags & \
83 (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
84#else /* CONFIG_DEBUG_VM */
85#define transparent_hugepage_debug_cow() 0
86#endif /* CONFIG_DEBUG_VM */
87
88extern unsigned long transparent_hugepage_flags;
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -080089
Toshi Kani74d2fad2016-10-07 16:59:56 -070090extern unsigned long thp_get_unmapped_area(struct file *filp,
91 unsigned long addr, unsigned long len, unsigned long pgoff,
92 unsigned long flags);
93
Kirill A. Shutemov9a982252016-01-15 16:54:17 -080094extern void prep_transhuge_page(struct page *page);
95extern void free_transhuge_page(struct page *page);
96
Kirill A. Shutemove9b61f12016-01-15 16:54:10 -080097int split_huge_page_to_list(struct page *page, struct list_head *list);
98static inline int split_huge_page(struct page *page)
99{
100 return split_huge_page_to_list(page, NULL);
101}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800102void deferred_split_huge_page(struct page *page);
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800103
104void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
Naoya Horiguchi33f47512016-07-14 12:07:32 -0700105 unsigned long address, bool freeze, struct page *page);
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800106
107#define split_huge_pmd(__vma, __pmd, __address) \
108 do { \
109 pmd_t *____pmd = (__pmd); \
Dan Williams5c7fb562016-01-15 16:56:52 -0800110 if (pmd_trans_huge(*____pmd) \
111 || pmd_devmap(*____pmd)) \
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700112 __split_huge_pmd(__vma, __pmd, __address, \
Naoya Horiguchi33f47512016-07-14 12:07:32 -0700113 false, NULL); \
Kirill A. Shutemoveef1b3b2016-01-15 16:53:53 -0800114 } while (0)
Kirill A. Shutemovad0bed22016-01-15 16:52:53 -0800115
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700116
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700117void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address,
118 bool freeze, struct page *page);
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700119
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800120extern int hugepage_madvise(struct vm_area_struct *vma,
121 unsigned long *vm_flags, int advice);
Kirill A. Shutemove1b99962015-09-08 14:58:37 -0700122extern void vma_adjust_trans_huge(struct vm_area_struct *vma,
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800123 unsigned long start,
124 unsigned long end,
125 long adjust_next);
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800126extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd,
127 struct vm_area_struct *vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700128/* mmap_sem must be held on entry */
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800129static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
130 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700131{
Sasha Levin81d1b092014-10-09 15:28:10 -0700132 VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma);
Dan Williams5c7fb562016-01-15 16:56:52 -0800133 if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd))
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800134 return __pmd_trans_huge_lock(pmd, vma);
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700135 else
Chen Gang969e8d72016-04-01 14:31:17 -0700136 return NULL;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700137}
Rik van Riel2c888cf2011-01-13 15:47:13 -0800138static inline int hpage_nr_pages(struct page *page)
139{
140 if (unlikely(PageTransHuge(page)))
141 return HPAGE_PMD_NR;
142 return 1;
143}
Mel Gormand10e63f2012-10-25 14:16:31 +0200144
Kirill A. Shutemovbae473a2016-07-26 15:25:20 -0700145extern int do_huge_pmd_numa_page(struct fault_env *fe, pmd_t orig_pmd);
Mel Gormand10e63f2012-10-25 14:16:31 +0200146
Wang, Yalin56873f42015-02-11 15:24:51 -0800147extern struct page *huge_zero_page;
148
149static inline bool is_huge_zero_page(struct page *page)
150{
151 return ACCESS_ONCE(huge_zero_page) == page;
152}
153
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700154static inline bool is_huge_zero_pmd(pmd_t pmd)
155{
156 return is_huge_zero_page(pmd_page(pmd));
157}
158
Aaron Lu6fcb52a2016-10-07 17:00:08 -0700159struct page *mm_get_huge_zero_page(struct mm_struct *mm);
160void mm_put_huge_zero_page(struct mm_struct *mm);
Matthew Wilcoxfc437042015-09-08 14:58:51 -0700161
Kirill A. Shutemov10102452016-07-26 15:25:29 -0700162#define mk_huge_pmd(page, prot) pmd_mkhuge(mk_pmd(page, prot))
163
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
Kirill A. Shutemov800d8c62016-07-26 15:26:18 -0700173static inline void prep_transhuge_page(struct page *page) {}
174
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800175#define transparent_hugepage_flags 0UL
Toshi Kani74d2fad2016-10-07 16:59:56 -0700176
177#define thp_get_unmapped_area NULL
178
Shaohua Li5bc7b8a2013-04-29 15:08:36 -0700179static inline int
180split_huge_page_to_list(struct page *page, struct list_head *list)
181{
182 return 0;
183}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800184static inline int split_huge_page(struct page *page)
185{
186 return 0;
187}
Kirill A. Shutemov9a982252016-01-15 16:54:17 -0800188static inline void deferred_split_huge_page(struct page *page) {}
Kirill A. Shutemov78ddc532016-01-15 16:52:42 -0800189#define split_huge_pmd(__vma, __pmd, __address) \
Kirill A. Shutemove1803772012-12-12 13:50:59 -0800190 do { } while (0)
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700191
192static inline void split_huge_pmd_address(struct vm_area_struct *vma,
Kirill A. Shutemovfec89c12016-03-17 14:20:10 -0700193 unsigned long address, bool freeze, struct page *page) {}
Kirill A. Shutemov2a52bcb2016-03-17 14:20:04 -0700194
Andrea Arcangeli60ab3242011-01-13 15:47:18 -0800195static inline int hugepage_madvise(struct vm_area_struct *vma,
196 unsigned long *vm_flags, int advice)
Andrea Arcangeli0af4e982011-01-13 15:46:55 -0800197{
198 BUG();
199 return 0;
200}
Andrea Arcangeli94fcc582011-01-13 15:47:08 -0800201static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
202 unsigned long start,
203 unsigned long end,
204 long adjust_next)
205{
206}
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800207static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd,
208 struct vm_area_struct *vma)
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700209{
Kirill A. Shutemovb6ec57f2016-01-21 16:40:25 -0800210 return NULL;
Naoya Horiguchi025c5b22012-03-21 16:33:57 -0700211}
Mel Gormand10e63f2012-10-25 14:16:31 +0200212
Kirill A. Shutemovbae473a2016-07-26 15:25:20 -0700213static inline int do_huge_pmd_numa_page(struct fault_env *fe, pmd_t orig_pmd)
Mel Gormand10e63f2012-10-25 14:16:31 +0200214{
Mel Gorman4daae3b2012-11-02 11:33:45 +0000215 return 0;
Mel Gormand10e63f2012-10-25 14:16:31 +0200216}
217
Wang, Yalin56873f42015-02-11 15:24:51 -0800218static inline bool is_huge_zero_page(struct page *page)
219{
220 return false;
221}
222
Aaron Lu6fcb52a2016-10-07 17:00:08 -0700223static inline void mm_put_huge_zero_page(struct mm_struct *mm)
Kirill A. Shutemovaa88b682016-04-28 16:18:27 -0700224{
Aaron Lu6fcb52a2016-10-07 17:00:08 -0700225 return;
Kirill A. Shutemovaa88b682016-04-28 16:18:27 -0700226}
Dan Williams3565fce2016-01-15 16:56:55 -0800227
228static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma,
229 unsigned long addr, pmd_t *pmd, int flags)
230{
231 return NULL;
232}
Andrea Arcangeli71e3aac2011-01-13 15:46:52 -0800233#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
234
235#endif /* _LINUX_HUGE_MM_H */