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); |
| 22 | |
| 23 | enum transparent_hugepage_flag { |
| 24 | TRANSPARENT_HUGEPAGE_FLAG, |
| 25 | TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, |
| 26 | TRANSPARENT_HUGEPAGE_DEFRAG_FLAG, |
| 27 | TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame^] | 28 | TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 29 | #ifdef CONFIG_DEBUG_VM |
| 30 | TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG, |
| 31 | #endif |
| 32 | }; |
| 33 | |
| 34 | enum page_check_address_pmd_flag { |
| 35 | PAGE_CHECK_ADDRESS_PMD_FLAG, |
| 36 | PAGE_CHECK_ADDRESS_PMD_NOTSPLITTING_FLAG, |
| 37 | PAGE_CHECK_ADDRESS_PMD_SPLITTING_FLAG, |
| 38 | }; |
| 39 | extern pmd_t *page_check_address_pmd(struct page *page, |
| 40 | struct mm_struct *mm, |
| 41 | unsigned long address, |
| 42 | enum page_check_address_pmd_flag flag); |
| 43 | |
| 44 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 45 | #define HPAGE_PMD_SHIFT HPAGE_SHIFT |
| 46 | #define HPAGE_PMD_MASK HPAGE_MASK |
| 47 | #define HPAGE_PMD_SIZE HPAGE_SIZE |
| 48 | |
| 49 | #define transparent_hugepage_enabled(__vma) \ |
| 50 | (transparent_hugepage_flags & (1<<TRANSPARENT_HUGEPAGE_FLAG) || \ |
| 51 | (transparent_hugepage_flags & \ |
| 52 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \ |
| 53 | (__vma)->vm_flags & VM_HUGEPAGE)) |
| 54 | #define transparent_hugepage_defrag(__vma) \ |
| 55 | ((transparent_hugepage_flags & \ |
| 56 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \ |
| 57 | (transparent_hugepage_flags & \ |
| 58 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \ |
| 59 | (__vma)->vm_flags & VM_HUGEPAGE)) |
| 60 | #ifdef CONFIG_DEBUG_VM |
| 61 | #define transparent_hugepage_debug_cow() \ |
| 62 | (transparent_hugepage_flags & \ |
| 63 | (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG)) |
| 64 | #else /* CONFIG_DEBUG_VM */ |
| 65 | #define transparent_hugepage_debug_cow() 0 |
| 66 | #endif /* CONFIG_DEBUG_VM */ |
| 67 | |
| 68 | extern unsigned long transparent_hugepage_flags; |
| 69 | extern int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, |
| 70 | pmd_t *dst_pmd, pmd_t *src_pmd, |
| 71 | struct vm_area_struct *vma, |
| 72 | unsigned long addr, unsigned long end); |
| 73 | extern int handle_pte_fault(struct mm_struct *mm, |
| 74 | struct vm_area_struct *vma, unsigned long address, |
| 75 | pte_t *pte, pmd_t *pmd, unsigned int flags); |
| 76 | extern int split_huge_page(struct page *page); |
| 77 | extern void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd); |
| 78 | #define split_huge_page_pmd(__mm, __pmd) \ |
| 79 | do { \ |
| 80 | pmd_t *____pmd = (__pmd); \ |
| 81 | if (unlikely(pmd_trans_huge(*____pmd))) \ |
| 82 | __split_huge_page_pmd(__mm, ____pmd); \ |
| 83 | } while (0) |
| 84 | #define wait_split_huge_page(__anon_vma, __pmd) \ |
| 85 | do { \ |
| 86 | pmd_t *____pmd = (__pmd); \ |
| 87 | spin_unlock_wait(&(__anon_vma)->root->lock); \ |
| 88 | /* \ |
| 89 | * spin_unlock_wait() is just a loop in C and so the \ |
| 90 | * CPU can reorder anything around it. \ |
| 91 | */ \ |
| 92 | smp_mb(); \ |
| 93 | BUG_ON(pmd_trans_splitting(*____pmd) || \ |
| 94 | pmd_trans_huge(*____pmd)); \ |
| 95 | } while (0) |
| 96 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) |
| 97 | #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER) |
| 98 | #if HPAGE_PMD_ORDER > MAX_ORDER |
| 99 | #error "hugepages can't be allocated by the buddy allocator" |
| 100 | #endif |
Andrea Arcangeli | 0af4e98 | 2011-01-13 15:46:55 -0800 | [diff] [blame] | 101 | extern int hugepage_madvise(unsigned long *vm_flags); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 102 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 103 | #define HPAGE_PMD_SHIFT ({ BUG(); 0; }) |
| 104 | #define HPAGE_PMD_MASK ({ BUG(); 0; }) |
| 105 | #define HPAGE_PMD_SIZE ({ BUG(); 0; }) |
| 106 | |
| 107 | #define transparent_hugepage_enabled(__vma) 0 |
| 108 | |
| 109 | #define transparent_hugepage_flags 0UL |
| 110 | static inline int split_huge_page(struct page *page) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | #define split_huge_page_pmd(__mm, __pmd) \ |
| 115 | do { } while (0) |
| 116 | #define wait_split_huge_page(__anon_vma, __pmd) \ |
| 117 | do { } while (0) |
Andrea Arcangeli | 0af4e98 | 2011-01-13 15:46:55 -0800 | [diff] [blame] | 118 | static inline int hugepage_madvise(unsigned long *vm_flags) |
| 119 | { |
| 120 | BUG(); |
| 121 | return 0; |
| 122 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 123 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 124 | |
| 125 | #endif /* _LINUX_HUGE_MM_H */ |