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 | |
| 4 | extern 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); |
| 8 | extern 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 Deacon | a1dd450 | 2012-12-11 16:01:27 -0800 | [diff] [blame] | 11 | extern 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 Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 15 | extern 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 Rientjes | b676b29 | 2012-10-08 16:34:03 -0700 | [diff] [blame] | 18 | extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 19 | unsigned long addr, |
| 20 | pmd_t *pmd, |
| 21 | unsigned int flags); |
| 22 | extern int zap_huge_pmd(struct mmu_gather *tlb, |
| 23 | struct vm_area_struct *vma, |
Shaohua Li | f21760b | 2012-01-12 17:19:16 -0800 | [diff] [blame] | 24 | pmd_t *pmd, unsigned long addr); |
Johannes Weiner | 0ca1634 | 2011-01-13 15:47:02 -0800 | [diff] [blame] | 25 | extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
| 26 | unsigned long addr, unsigned long end, |
| 27 | unsigned char *vec); |
Andrea Arcangeli | 37a1c49 | 2011-10-31 17:08:30 -0700 | [diff] [blame] | 28 | extern int move_huge_pmd(struct vm_area_struct *vma, |
| 29 | struct vm_area_struct *new_vma, |
| 30 | unsigned long old_addr, |
| 31 | unsigned long new_addr, unsigned long old_end, |
| 32 | pmd_t *old_pmd, pmd_t *new_pmd); |
Johannes Weiner | cd7548a | 2011-01-13 15:47:04 -0800 | [diff] [blame] | 33 | 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] | 34 | unsigned long addr, pgprot_t newprot, |
| 35 | int prot_numa); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 36 | |
| 37 | enum transparent_hugepage_flag { |
| 38 | TRANSPARENT_HUGEPAGE_FLAG, |
| 39 | TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, |
| 40 | TRANSPARENT_HUGEPAGE_DEFRAG_FLAG, |
| 41 | TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 42 | TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG, |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 43 | TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 44 | #ifdef CONFIG_DEBUG_VM |
| 45 | TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG, |
| 46 | #endif |
| 47 | }; |
| 48 | |
| 49 | enum page_check_address_pmd_flag { |
| 50 | PAGE_CHECK_ADDRESS_PMD_FLAG, |
| 51 | PAGE_CHECK_ADDRESS_PMD_NOTSPLITTING_FLAG, |
| 52 | PAGE_CHECK_ADDRESS_PMD_SPLITTING_FLAG, |
| 53 | }; |
| 54 | extern pmd_t *page_check_address_pmd(struct page *page, |
| 55 | struct mm_struct *mm, |
| 56 | unsigned long address, |
| 57 | enum page_check_address_pmd_flag flag); |
| 58 | |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 59 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) |
| 60 | #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER) |
| 61 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 62 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 63 | #define HPAGE_PMD_SHIFT HPAGE_SHIFT |
| 64 | #define HPAGE_PMD_MASK HPAGE_MASK |
| 65 | #define HPAGE_PMD_SIZE HPAGE_SIZE |
| 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)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 77 | #define transparent_hugepage_defrag(__vma) \ |
| 78 | ((transparent_hugepage_flags & \ |
| 79 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \ |
| 80 | (transparent_hugepage_flags & \ |
| 81 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \ |
| 82 | (__vma)->vm_flags & VM_HUGEPAGE)) |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 83 | #define transparent_hugepage_use_zero_page() \ |
| 84 | (transparent_hugepage_flags & \ |
| 85 | (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 86 | #ifdef CONFIG_DEBUG_VM |
| 87 | #define transparent_hugepage_debug_cow() \ |
| 88 | (transparent_hugepage_flags & \ |
| 89 | (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG)) |
| 90 | #else /* CONFIG_DEBUG_VM */ |
| 91 | #define transparent_hugepage_debug_cow() 0 |
| 92 | #endif /* CONFIG_DEBUG_VM */ |
| 93 | |
| 94 | extern unsigned long transparent_hugepage_flags; |
| 95 | extern int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, |
| 96 | pmd_t *dst_pmd, pmd_t *src_pmd, |
| 97 | struct vm_area_struct *vma, |
| 98 | unsigned long addr, unsigned long end); |
| 99 | extern int handle_pte_fault(struct mm_struct *mm, |
| 100 | struct vm_area_struct *vma, unsigned long address, |
| 101 | pte_t *pte, pmd_t *pmd, unsigned int flags); |
| 102 | extern int split_huge_page(struct page *page); |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 103 | extern void __split_huge_page_pmd(struct vm_area_struct *vma, |
| 104 | unsigned long address, pmd_t *pmd); |
| 105 | #define split_huge_page_pmd(__vma, __address, __pmd) \ |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 106 | do { \ |
| 107 | pmd_t *____pmd = (__pmd); \ |
| 108 | if (unlikely(pmd_trans_huge(*____pmd))) \ |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 109 | __split_huge_page_pmd(__vma, __address, \ |
| 110 | ____pmd); \ |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 111 | } while (0) |
| 112 | #define wait_split_huge_page(__anon_vma, __pmd) \ |
| 113 | do { \ |
| 114 | pmd_t *____pmd = (__pmd); \ |
Ingo Molnar | 4fc3f1d | 2012-12-02 19:56:50 +0000 | [diff] [blame] | 115 | anon_vma_lock_write(__anon_vma); \ |
Peter Zijlstra | 2b575eb | 2011-05-24 17:12:11 -0700 | [diff] [blame] | 116 | anon_vma_unlock(__anon_vma); \ |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 117 | BUG_ON(pmd_trans_splitting(*____pmd) || \ |
| 118 | pmd_trans_huge(*____pmd)); \ |
| 119 | } while (0) |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 120 | extern void split_huge_page_pmd_mm(struct mm_struct *mm, unsigned long address, |
| 121 | pmd_t *pmd); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 122 | #if HPAGE_PMD_ORDER > MAX_ORDER |
| 123 | #error "hugepages can't be allocated by the buddy allocator" |
| 124 | #endif |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 125 | extern int hugepage_madvise(struct vm_area_struct *vma, |
| 126 | unsigned long *vm_flags, int advice); |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 127 | extern void __vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 128 | unsigned long start, |
| 129 | unsigned long end, |
| 130 | long adjust_next); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 131 | extern int __pmd_trans_huge_lock(pmd_t *pmd, |
| 132 | struct vm_area_struct *vma); |
| 133 | /* mmap_sem must be held on entry */ |
| 134 | static inline int pmd_trans_huge_lock(pmd_t *pmd, |
| 135 | struct vm_area_struct *vma) |
| 136 | { |
| 137 | VM_BUG_ON(!rwsem_is_locked(&vma->vm_mm->mmap_sem)); |
| 138 | if (pmd_trans_huge(*pmd)) |
| 139 | return __pmd_trans_huge_lock(pmd, vma); |
| 140 | else |
| 141 | return 0; |
| 142 | } |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 143 | static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 144 | unsigned long start, |
| 145 | unsigned long end, |
| 146 | long adjust_next) |
| 147 | { |
Andrea Arcangeli | 78f11a2 | 2011-04-27 15:26:45 -0700 | [diff] [blame] | 148 | if (!vma->anon_vma || vma->vm_ops) |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 149 | return; |
| 150 | __vma_adjust_trans_huge(vma, start, end, adjust_next); |
| 151 | } |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 152 | static inline int hpage_nr_pages(struct page *page) |
| 153 | { |
| 154 | if (unlikely(PageTransHuge(page))) |
| 155 | return HPAGE_PMD_NR; |
| 156 | return 1; |
| 157 | } |
Andrea Arcangeli | 22e5c47 | 2011-01-13 15:47:20 -0800 | [diff] [blame] | 158 | static inline struct page *compound_trans_head(struct page *page) |
| 159 | { |
| 160 | if (PageTail(page)) { |
| 161 | struct page *head; |
| 162 | head = page->first_page; |
| 163 | smp_rmb(); |
| 164 | /* |
| 165 | * head may be a dangling pointer. |
| 166 | * __split_huge_page_refcount clears PageTail before |
| 167 | * overwriting first_page, so if PageTail is still |
| 168 | * there it means the head pointer isn't dangling. |
| 169 | */ |
| 170 | if (PageTail(page)) |
| 171 | return head; |
| 172 | } |
| 173 | return page; |
| 174 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 175 | |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 176 | extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, |
| 177 | unsigned long addr, pmd_t pmd, pmd_t *pmdp); |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 178 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 179 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 180 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) |
| 181 | #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) |
| 182 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 183 | |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 184 | #define hpage_nr_pages(x) 1 |
| 185 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 186 | #define transparent_hugepage_enabled(__vma) 0 |
| 187 | |
| 188 | #define transparent_hugepage_flags 0UL |
| 189 | static inline int split_huge_page(struct page *page) |
| 190 | { |
| 191 | return 0; |
| 192 | } |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 193 | #define split_huge_page_pmd(__vma, __address, __pmd) \ |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 194 | do { } while (0) |
| 195 | #define wait_split_huge_page(__anon_vma, __pmd) \ |
| 196 | do { } while (0) |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 197 | #define split_huge_page_pmd_mm(__mm, __address, __pmd) \ |
| 198 | do { } while (0) |
Andrea Arcangeli | 22e5c47 | 2011-01-13 15:47:20 -0800 | [diff] [blame] | 199 | #define compound_trans_head(page) compound_head(page) |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 200 | static inline int hugepage_madvise(struct vm_area_struct *vma, |
| 201 | unsigned long *vm_flags, int advice) |
Andrea Arcangeli | 0af4e98 | 2011-01-13 15:46:55 -0800 | [diff] [blame] | 202 | { |
| 203 | BUG(); |
| 204 | return 0; |
| 205 | } |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 206 | static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 207 | unsigned long start, |
| 208 | unsigned long end, |
| 209 | long adjust_next) |
| 210 | { |
| 211 | } |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 212 | static inline int pmd_trans_huge_lock(pmd_t *pmd, |
| 213 | struct vm_area_struct *vma) |
| 214 | { |
| 215 | return 0; |
| 216 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 217 | |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 218 | static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, |
| 219 | unsigned long addr, pmd_t pmd, pmd_t *pmdp) |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 220 | { |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 221 | return 0; |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 222 | } |
| 223 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 224 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 225 | |
| 226 | #endif /* _LINUX_HUGE_MM_H */ |