Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_HUGE_MM_H |
| 2 | #define _LINUX_HUGE_MM_H |
| 3 | |
Kirill A. Shutemov | bae473a | 2016-07-26 15:25:20 -0700 | [diff] [blame] | 4 | extern int do_huge_pmd_anonymous_page(struct fault_env *fe); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 5 | extern 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. Shutemov | bae473a | 2016-07-26 15:25:20 -0700 | [diff] [blame] | 8 | extern void huge_pmd_set_accessed(struct fault_env *fe, pmd_t orig_pmd); |
| 9 | extern int do_huge_pmd_wp_page(struct fault_env *fe, pmd_t orig_pmd); |
David Rientjes | b676b29 | 2012-10-08 16:34:03 -0700 | [diff] [blame] | 10 | extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 11 | unsigned long addr, |
| 12 | pmd_t *pmd, |
| 13 | unsigned int flags); |
Huang Ying | 319904a | 2016-07-28 15:48:03 -0700 | [diff] [blame] | 14 | extern bool madvise_free_huge_pmd(struct mmu_gather *tlb, |
Minchan Kim | b8d3c4c | 2016-01-15 16:55:42 -0800 | [diff] [blame] | 15 | struct vm_area_struct *vma, |
| 16 | pmd_t *pmd, unsigned long addr, unsigned long next); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 17 | extern int zap_huge_pmd(struct mmu_gather *tlb, |
| 18 | struct vm_area_struct *vma, |
Shaohua Li | f21760b | 2012-01-12 17:19:16 -0800 | [diff] [blame] | 19 | pmd_t *pmd, unsigned long addr); |
Johannes Weiner | 0ca1634 | 2011-01-13 15:47:02 -0800 | [diff] [blame] | 20 | extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
| 21 | unsigned long addr, unsigned long end, |
| 22 | unsigned char *vec); |
Hugh Dickins | bf8616d | 2016-05-19 17:12:54 -0700 | [diff] [blame] | 23 | extern bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr, |
Andrea Arcangeli | 37a1c49 | 2011-10-31 17:08:30 -0700 | [diff] [blame] | 24 | unsigned long new_addr, unsigned long old_end, |
| 25 | pmd_t *old_pmd, pmd_t *new_pmd); |
Johannes Weiner | cd7548a | 2011-01-13 15:47:04 -0800 | [diff] [blame] | 26 | extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
Mel Gorman | 4b10e7d | 2012-10-25 14:16:32 +0200 | [diff] [blame] | 27 | unsigned long addr, pgprot_t newprot, |
| 28 | int prot_numa); |
Matthew Wilcox | 5cad465 | 2015-09-08 14:58:54 -0700 | [diff] [blame] | 29 | int vmf_insert_pfn_pmd(struct vm_area_struct *, unsigned long addr, pmd_t *, |
Dan Williams | f25748e3 | 2016-01-15 16:56:43 -0800 | [diff] [blame] | 30 | pfn_t pfn, bool write); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 31 | enum transparent_hugepage_flag { |
| 32 | TRANSPARENT_HUGEPAGE_FLAG, |
| 33 | TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, |
Mel Gorman | 444eb2a4 | 2016-03-17 14:19:23 -0700 | [diff] [blame] | 34 | TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, |
| 35 | TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 36 | TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 37 | TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG, |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 38 | TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 39 | #ifdef CONFIG_DEBUG_VM |
| 40 | TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG, |
| 41 | #endif |
| 42 | }; |
| 43 | |
Kirill A. Shutemov | b46e756 | 2016-07-26 15:26:24 -0700 | [diff] [blame] | 44 | struct kobject; |
| 45 | struct kobj_attribute; |
| 46 | |
| 47 | extern 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); |
| 51 | extern ssize_t single_hugepage_flag_show(struct kobject *kobj, |
| 52 | struct kobj_attribute *attr, char *buf, |
| 53 | enum transparent_hugepage_flag flag); |
Kirill A. Shutemov | 5a6e75f | 2016-07-26 15:26:13 -0700 | [diff] [blame] | 54 | extern struct kobj_attribute shmem_enabled_attr; |
| 55 | |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 56 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) |
| 57 | #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER) |
| 58 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 59 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Dan Williams | 3565fce | 2016-01-15 16:56:55 -0800 | [diff] [blame] | 60 | struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr, |
| 61 | pmd_t *pmd, int flags); |
| 62 | |
Aneesh Kumar K.V | fde5279 | 2013-06-05 17:14:05 -0700 | [diff] [blame] | 63 | #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 Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 66 | |
Alex Shi | 2099597 | 2012-05-29 15:06:31 -0700 | [diff] [blame] | 67 | extern bool is_vma_temporary_stack(struct vm_area_struct *vma); |
| 68 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 69 | #define transparent_hugepage_enabled(__vma) \ |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 70 | ((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 Arcangeli | a7d6e4e | 2011-02-15 19:02:45 +0100 | [diff] [blame] | 75 | !((__vma)->vm_flags & VM_NOHUGEPAGE) && \ |
| 76 | !is_vma_temporary_stack(__vma)) |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 77 | #define transparent_hugepage_use_zero_page() \ |
| 78 | (transparent_hugepage_flags & \ |
| 79 | (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 80 | #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 | |
| 88 | extern unsigned long transparent_hugepage_flags; |
Kirill A. Shutemov | ad0bed2 | 2016-01-15 16:52:53 -0800 | [diff] [blame] | 89 | |
Toshi Kani | 74d2fad | 2016-10-07 16:59:56 -0700 | [diff] [blame] | 90 | extern 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. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 94 | extern void prep_transhuge_page(struct page *page); |
| 95 | extern void free_transhuge_page(struct page *page); |
| 96 | |
Kirill A. Shutemov | e9b61f1 | 2016-01-15 16:54:10 -0800 | [diff] [blame] | 97 | int split_huge_page_to_list(struct page *page, struct list_head *list); |
| 98 | static inline int split_huge_page(struct page *page) |
| 99 | { |
| 100 | return split_huge_page_to_list(page, NULL); |
| 101 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 102 | void deferred_split_huge_page(struct page *page); |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 103 | |
| 104 | void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
Naoya Horiguchi | 33f4751 | 2016-07-14 12:07:32 -0700 | [diff] [blame] | 105 | unsigned long address, bool freeze, struct page *page); |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 106 | |
| 107 | #define split_huge_pmd(__vma, __pmd, __address) \ |
| 108 | do { \ |
| 109 | pmd_t *____pmd = (__pmd); \ |
Dan Williams | 5c7fb56 | 2016-01-15 16:56:52 -0800 | [diff] [blame] | 110 | if (pmd_trans_huge(*____pmd) \ |
| 111 | || pmd_devmap(*____pmd)) \ |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 112 | __split_huge_pmd(__vma, __pmd, __address, \ |
Naoya Horiguchi | 33f4751 | 2016-07-14 12:07:32 -0700 | [diff] [blame] | 113 | false, NULL); \ |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 114 | } while (0) |
Kirill A. Shutemov | ad0bed2 | 2016-01-15 16:52:53 -0800 | [diff] [blame] | 115 | |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 116 | |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 117 | void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address, |
| 118 | bool freeze, struct page *page); |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 119 | |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 120 | extern int hugepage_madvise(struct vm_area_struct *vma, |
| 121 | unsigned long *vm_flags, int advice); |
Kirill A. Shutemov | e1b9996 | 2015-09-08 14:58:37 -0700 | [diff] [blame] | 122 | extern void vma_adjust_trans_huge(struct vm_area_struct *vma, |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 123 | unsigned long start, |
| 124 | unsigned long end, |
| 125 | long adjust_next); |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 126 | extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, |
| 127 | struct vm_area_struct *vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 128 | /* mmap_sem must be held on entry */ |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 129 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
| 130 | struct vm_area_struct *vma) |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 131 | { |
Sasha Levin | 81d1b09 | 2014-10-09 15:28:10 -0700 | [diff] [blame] | 132 | VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma); |
Dan Williams | 5c7fb56 | 2016-01-15 16:56:52 -0800 | [diff] [blame] | 133 | if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 134 | return __pmd_trans_huge_lock(pmd, vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 135 | else |
Chen Gang | 969e8d7 | 2016-04-01 14:31:17 -0700 | [diff] [blame] | 136 | return NULL; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 137 | } |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 138 | static inline int hpage_nr_pages(struct page *page) |
| 139 | { |
| 140 | if (unlikely(PageTransHuge(page))) |
| 141 | return HPAGE_PMD_NR; |
| 142 | return 1; |
| 143 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 144 | |
Kirill A. Shutemov | bae473a | 2016-07-26 15:25:20 -0700 | [diff] [blame] | 145 | extern int do_huge_pmd_numa_page(struct fault_env *fe, pmd_t orig_pmd); |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 146 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 147 | extern struct page *huge_zero_page; |
| 148 | |
| 149 | static inline bool is_huge_zero_page(struct page *page) |
| 150 | { |
| 151 | return ACCESS_ONCE(huge_zero_page) == page; |
| 152 | } |
| 153 | |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 154 | static inline bool is_huge_zero_pmd(pmd_t pmd) |
| 155 | { |
| 156 | return is_huge_zero_page(pmd_page(pmd)); |
| 157 | } |
| 158 | |
Aaron Lu | 6fcb52a | 2016-10-07 17:00:08 -0700 | [diff] [blame] | 159 | struct page *mm_get_huge_zero_page(struct mm_struct *mm); |
| 160 | void mm_put_huge_zero_page(struct mm_struct *mm); |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 161 | |
Kirill A. Shutemov | 1010245 | 2016-07-26 15:25:29 -0700 | [diff] [blame] | 162 | #define mk_huge_pmd(page, prot) pmd_mkhuge(mk_pmd(page, prot)) |
| 163 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 164 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 165 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) |
| 166 | #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) |
| 167 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 168 | |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 169 | #define hpage_nr_pages(x) 1 |
| 170 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 171 | #define transparent_hugepage_enabled(__vma) 0 |
| 172 | |
Kirill A. Shutemov | 800d8c6 | 2016-07-26 15:26:18 -0700 | [diff] [blame] | 173 | static inline void prep_transhuge_page(struct page *page) {} |
| 174 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 175 | #define transparent_hugepage_flags 0UL |
Toshi Kani | 74d2fad | 2016-10-07 16:59:56 -0700 | [diff] [blame] | 176 | |
| 177 | #define thp_get_unmapped_area NULL |
| 178 | |
Shaohua Li | 5bc7b8a | 2013-04-29 15:08:36 -0700 | [diff] [blame] | 179 | static inline int |
| 180 | split_huge_page_to_list(struct page *page, struct list_head *list) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 184 | static inline int split_huge_page(struct page *page) |
| 185 | { |
| 186 | return 0; |
| 187 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 188 | static inline void deferred_split_huge_page(struct page *page) {} |
Kirill A. Shutemov | 78ddc53 | 2016-01-15 16:52:42 -0800 | [diff] [blame] | 189 | #define split_huge_pmd(__vma, __pmd, __address) \ |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 190 | do { } while (0) |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 191 | |
| 192 | static inline void split_huge_pmd_address(struct vm_area_struct *vma, |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 193 | unsigned long address, bool freeze, struct page *page) {} |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 194 | |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 195 | static inline int hugepage_madvise(struct vm_area_struct *vma, |
| 196 | unsigned long *vm_flags, int advice) |
Andrea Arcangeli | 0af4e98 | 2011-01-13 15:46:55 -0800 | [diff] [blame] | 197 | { |
| 198 | BUG(); |
| 199 | return 0; |
| 200 | } |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 201 | static 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. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 207 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
| 208 | struct vm_area_struct *vma) |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 209 | { |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 210 | return NULL; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 211 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 212 | |
Kirill A. Shutemov | bae473a | 2016-07-26 15:25:20 -0700 | [diff] [blame] | 213 | static inline int do_huge_pmd_numa_page(struct fault_env *fe, pmd_t orig_pmd) |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 214 | { |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 215 | return 0; |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 218 | static inline bool is_huge_zero_page(struct page *page) |
| 219 | { |
| 220 | return false; |
| 221 | } |
| 222 | |
Aaron Lu | 6fcb52a | 2016-10-07 17:00:08 -0700 | [diff] [blame] | 223 | static inline void mm_put_huge_zero_page(struct mm_struct *mm) |
Kirill A. Shutemov | aa88b68 | 2016-04-28 16:18:27 -0700 | [diff] [blame] | 224 | { |
Aaron Lu | 6fcb52a | 2016-10-07 17:00:08 -0700 | [diff] [blame] | 225 | return; |
Kirill A. Shutemov | aa88b68 | 2016-04-28 16:18:27 -0700 | [diff] [blame] | 226 | } |
Dan Williams | 3565fce | 2016-01-15 16:56:55 -0800 | [diff] [blame] | 227 | |
| 228 | static 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 Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 233 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 234 | |
| 235 | #endif /* _LINUX_HUGE_MM_H */ |