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