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 | |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 90 | extern void prep_transhuge_page(struct page *page); |
| 91 | extern void free_transhuge_page(struct page *page); |
| 92 | |
Kirill A. Shutemov | e9b61f1 | 2016-01-15 16:54:10 -0800 | [diff] [blame] | 93 | int split_huge_page_to_list(struct page *page, struct list_head *list); |
| 94 | static inline int split_huge_page(struct page *page) |
| 95 | { |
| 96 | return split_huge_page_to_list(page, NULL); |
| 97 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 98 | void deferred_split_huge_page(struct page *page); |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 99 | |
| 100 | void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
Naoya Horiguchi | 33f4751 | 2016-07-14 12:07:32 -0700 | [diff] [blame] | 101 | unsigned long address, bool freeze, struct page *page); |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 102 | |
| 103 | #define split_huge_pmd(__vma, __pmd, __address) \ |
| 104 | do { \ |
| 105 | pmd_t *____pmd = (__pmd); \ |
Dan Williams | 5c7fb56 | 2016-01-15 16:56:52 -0800 | [diff] [blame] | 106 | if (pmd_trans_huge(*____pmd) \ |
| 107 | || pmd_devmap(*____pmd)) \ |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 108 | __split_huge_pmd(__vma, __pmd, __address, \ |
Naoya Horiguchi | 33f4751 | 2016-07-14 12:07:32 -0700 | [diff] [blame] | 109 | false, NULL); \ |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 110 | } while (0) |
Kirill A. Shutemov | ad0bed2 | 2016-01-15 16:52:53 -0800 | [diff] [blame] | 111 | |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 112 | |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 113 | void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address, |
| 114 | bool freeze, struct page *page); |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 115 | |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 116 | extern int hugepage_madvise(struct vm_area_struct *vma, |
| 117 | unsigned long *vm_flags, int advice); |
Kirill A. Shutemov | e1b9996 | 2015-09-08 14:58:37 -0700 | [diff] [blame] | 118 | extern void vma_adjust_trans_huge(struct vm_area_struct *vma, |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 119 | unsigned long start, |
| 120 | unsigned long end, |
| 121 | long adjust_next); |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 122 | extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, |
| 123 | struct vm_area_struct *vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 124 | /* mmap_sem must be held on entry */ |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 125 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
| 126 | struct vm_area_struct *vma) |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 127 | { |
Sasha Levin | 81d1b09 | 2014-10-09 15:28:10 -0700 | [diff] [blame] | 128 | 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] | 129 | if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 130 | return __pmd_trans_huge_lock(pmd, vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 131 | else |
Chen Gang | 969e8d7 | 2016-04-01 14:31:17 -0700 | [diff] [blame] | 132 | return NULL; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 133 | } |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 134 | static inline int hpage_nr_pages(struct page *page) |
| 135 | { |
| 136 | if (unlikely(PageTransHuge(page))) |
| 137 | return HPAGE_PMD_NR; |
| 138 | return 1; |
| 139 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 140 | |
Kirill A. Shutemov | bae473a | 2016-07-26 15:25:20 -0700 | [diff] [blame] | 141 | 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] | 142 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 143 | extern struct page *huge_zero_page; |
| 144 | |
| 145 | static inline bool is_huge_zero_page(struct page *page) |
| 146 | { |
| 147 | return ACCESS_ONCE(huge_zero_page) == page; |
| 148 | } |
| 149 | |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 150 | static inline bool is_huge_zero_pmd(pmd_t pmd) |
| 151 | { |
| 152 | return is_huge_zero_page(pmd_page(pmd)); |
| 153 | } |
| 154 | |
| 155 | struct page *get_huge_zero_page(void); |
Kirill A. Shutemov | aa88b68 | 2016-04-28 16:18:27 -0700 | [diff] [blame] | 156 | void put_huge_zero_page(void); |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 157 | |
Kirill A. Shutemov | 1010245 | 2016-07-26 15:25:29 -0700 | [diff] [blame] | 158 | #define mk_huge_pmd(page, prot) pmd_mkhuge(mk_pmd(page, prot)) |
| 159 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 160 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 161 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) |
| 162 | #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) |
| 163 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 164 | |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 165 | #define hpage_nr_pages(x) 1 |
| 166 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 167 | #define transparent_hugepage_enabled(__vma) 0 |
| 168 | |
Kirill A. Shutemov | 800d8c6 | 2016-07-26 15:26:18 -0700 | [diff] [blame] | 169 | static inline void prep_transhuge_page(struct page *page) {} |
| 170 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 171 | #define transparent_hugepage_flags 0UL |
Shaohua Li | 5bc7b8a | 2013-04-29 15:08:36 -0700 | [diff] [blame] | 172 | static inline int |
| 173 | split_huge_page_to_list(struct page *page, struct list_head *list) |
| 174 | { |
| 175 | return 0; |
| 176 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 177 | static inline int split_huge_page(struct page *page) |
| 178 | { |
| 179 | return 0; |
| 180 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 181 | static inline void deferred_split_huge_page(struct page *page) {} |
Kirill A. Shutemov | 78ddc53 | 2016-01-15 16:52:42 -0800 | [diff] [blame] | 182 | #define split_huge_pmd(__vma, __pmd, __address) \ |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 183 | do { } while (0) |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 184 | |
| 185 | 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] | 186 | unsigned long address, bool freeze, struct page *page) {} |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 187 | |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 188 | static inline int hugepage_madvise(struct vm_area_struct *vma, |
| 189 | unsigned long *vm_flags, int advice) |
Andrea Arcangeli | 0af4e98 | 2011-01-13 15:46:55 -0800 | [diff] [blame] | 190 | { |
| 191 | BUG(); |
| 192 | return 0; |
| 193 | } |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 194 | static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 195 | unsigned long start, |
| 196 | unsigned long end, |
| 197 | long adjust_next) |
| 198 | { |
| 199 | } |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 200 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
| 201 | struct vm_area_struct *vma) |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 202 | { |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 203 | return NULL; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 204 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 205 | |
Kirill A. Shutemov | bae473a | 2016-07-26 15:25:20 -0700 | [diff] [blame] | 206 | 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] | 207 | { |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 208 | return 0; |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 211 | static inline bool is_huge_zero_page(struct page *page) |
| 212 | { |
| 213 | return false; |
| 214 | } |
| 215 | |
Kirill A. Shutemov | aa88b68 | 2016-04-28 16:18:27 -0700 | [diff] [blame] | 216 | static inline void put_huge_zero_page(void) |
| 217 | { |
| 218 | BUILD_BUG(); |
| 219 | } |
Dan Williams | 3565fce | 2016-01-15 16:56:55 -0800 | [diff] [blame] | 220 | |
| 221 | static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma, |
| 222 | unsigned long addr, pmd_t *pmd, int flags) |
| 223 | { |
| 224 | return NULL; |
| 225 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 226 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 227 | |
| 228 | #endif /* _LINUX_HUGE_MM_H */ |