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