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); |
Johannes Weiner | cd7548a | 2011-01-13 15:47:04 -0800 | [diff] [blame] | 25 | extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
| 26 | unsigned long addr, pgprot_t newprot); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 27 | |
| 28 | enum transparent_hugepage_flag { |
| 29 | TRANSPARENT_HUGEPAGE_FLAG, |
| 30 | TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, |
| 31 | TRANSPARENT_HUGEPAGE_DEFRAG_FLAG, |
| 32 | TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 33 | TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 34 | #ifdef CONFIG_DEBUG_VM |
| 35 | TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG, |
| 36 | #endif |
| 37 | }; |
| 38 | |
| 39 | enum page_check_address_pmd_flag { |
| 40 | PAGE_CHECK_ADDRESS_PMD_FLAG, |
| 41 | PAGE_CHECK_ADDRESS_PMD_NOTSPLITTING_FLAG, |
| 42 | PAGE_CHECK_ADDRESS_PMD_SPLITTING_FLAG, |
| 43 | }; |
| 44 | extern pmd_t *page_check_address_pmd(struct page *page, |
| 45 | struct mm_struct *mm, |
| 46 | unsigned long address, |
| 47 | enum page_check_address_pmd_flag flag); |
| 48 | |
| 49 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 50 | #define HPAGE_PMD_SHIFT HPAGE_SHIFT |
| 51 | #define HPAGE_PMD_MASK HPAGE_MASK |
| 52 | #define HPAGE_PMD_SIZE HPAGE_SIZE |
| 53 | |
| 54 | #define transparent_hugepage_enabled(__vma) \ |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 55 | ((transparent_hugepage_flags & \ |
| 56 | (1<<TRANSPARENT_HUGEPAGE_FLAG) || \ |
| 57 | (transparent_hugepage_flags & \ |
| 58 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \ |
| 59 | ((__vma)->vm_flags & VM_HUGEPAGE))) && \ |
| 60 | !((__vma)->vm_flags & VM_NOHUGEPAGE)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 61 | #define transparent_hugepage_defrag(__vma) \ |
| 62 | ((transparent_hugepage_flags & \ |
| 63 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \ |
| 64 | (transparent_hugepage_flags & \ |
| 65 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \ |
| 66 | (__vma)->vm_flags & VM_HUGEPAGE)) |
| 67 | #ifdef CONFIG_DEBUG_VM |
| 68 | #define transparent_hugepage_debug_cow() \ |
| 69 | (transparent_hugepage_flags & \ |
| 70 | (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG)) |
| 71 | #else /* CONFIG_DEBUG_VM */ |
| 72 | #define transparent_hugepage_debug_cow() 0 |
| 73 | #endif /* CONFIG_DEBUG_VM */ |
| 74 | |
| 75 | extern unsigned long transparent_hugepage_flags; |
| 76 | extern int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, |
| 77 | pmd_t *dst_pmd, pmd_t *src_pmd, |
| 78 | struct vm_area_struct *vma, |
| 79 | unsigned long addr, unsigned long end); |
| 80 | extern int handle_pte_fault(struct mm_struct *mm, |
| 81 | struct vm_area_struct *vma, unsigned long address, |
| 82 | pte_t *pte, pmd_t *pmd, unsigned int flags); |
| 83 | extern int split_huge_page(struct page *page); |
| 84 | extern void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd); |
| 85 | #define split_huge_page_pmd(__mm, __pmd) \ |
| 86 | do { \ |
| 87 | pmd_t *____pmd = (__pmd); \ |
| 88 | if (unlikely(pmd_trans_huge(*____pmd))) \ |
| 89 | __split_huge_page_pmd(__mm, ____pmd); \ |
| 90 | } while (0) |
| 91 | #define wait_split_huge_page(__anon_vma, __pmd) \ |
| 92 | do { \ |
| 93 | pmd_t *____pmd = (__pmd); \ |
| 94 | spin_unlock_wait(&(__anon_vma)->root->lock); \ |
| 95 | /* \ |
| 96 | * spin_unlock_wait() is just a loop in C and so the \ |
| 97 | * CPU can reorder anything around it. \ |
| 98 | */ \ |
| 99 | smp_mb(); \ |
| 100 | BUG_ON(pmd_trans_splitting(*____pmd) || \ |
| 101 | pmd_trans_huge(*____pmd)); \ |
| 102 | } while (0) |
| 103 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) |
| 104 | #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER) |
| 105 | #if HPAGE_PMD_ORDER > MAX_ORDER |
| 106 | #error "hugepages can't be allocated by the buddy allocator" |
| 107 | #endif |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame^] | 108 | extern int hugepage_madvise(struct vm_area_struct *vma, |
| 109 | unsigned long *vm_flags, int advice); |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 110 | extern void __vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 111 | unsigned long start, |
| 112 | unsigned long end, |
| 113 | long adjust_next); |
| 114 | static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 115 | unsigned long start, |
| 116 | unsigned long end, |
| 117 | long adjust_next) |
| 118 | { |
| 119 | if (!vma->anon_vma || vma->vm_ops || vma->vm_file) |
| 120 | return; |
| 121 | __vma_adjust_trans_huge(vma, start, end, adjust_next); |
| 122 | } |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 123 | static inline int hpage_nr_pages(struct page *page) |
| 124 | { |
| 125 | if (unlikely(PageTransHuge(page))) |
| 126 | return HPAGE_PMD_NR; |
| 127 | return 1; |
| 128 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 129 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 130 | #define HPAGE_PMD_SHIFT ({ BUG(); 0; }) |
| 131 | #define HPAGE_PMD_MASK ({ BUG(); 0; }) |
| 132 | #define HPAGE_PMD_SIZE ({ BUG(); 0; }) |
| 133 | |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 134 | #define hpage_nr_pages(x) 1 |
| 135 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 136 | #define transparent_hugepage_enabled(__vma) 0 |
| 137 | |
| 138 | #define transparent_hugepage_flags 0UL |
| 139 | static inline int split_huge_page(struct page *page) |
| 140 | { |
| 141 | return 0; |
| 142 | } |
| 143 | #define split_huge_page_pmd(__mm, __pmd) \ |
| 144 | do { } while (0) |
| 145 | #define wait_split_huge_page(__anon_vma, __pmd) \ |
| 146 | do { } while (0) |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame^] | 147 | static inline int hugepage_madvise(struct vm_area_struct *vma, |
| 148 | unsigned long *vm_flags, int advice) |
Andrea Arcangeli | 0af4e98 | 2011-01-13 15:46:55 -0800 | [diff] [blame] | 149 | { |
| 150 | BUG(); |
| 151 | return 0; |
| 152 | } |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 153 | static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 154 | unsigned long start, |
| 155 | unsigned long end, |
| 156 | long adjust_next) |
| 157 | { |
| 158 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 159 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 160 | |
| 161 | #endif /* _LINUX_HUGE_MM_H */ |