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); |
Minchan Kim | b8d3c4c | 2016-01-15 16:55:42 -0800 | [diff] [blame] | 22 | extern int madvise_free_huge_pmd(struct mmu_gather *tlb, |
| 23 | struct vm_area_struct *vma, |
| 24 | pmd_t *pmd, unsigned long addr, unsigned long next); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 25 | extern int zap_huge_pmd(struct mmu_gather *tlb, |
| 26 | struct vm_area_struct *vma, |
Shaohua Li | f21760b | 2012-01-12 17:19:16 -0800 | [diff] [blame] | 27 | pmd_t *pmd, unsigned long addr); |
Johannes Weiner | 0ca1634 | 2011-01-13 15:47:02 -0800 | [diff] [blame] | 28 | extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
| 29 | unsigned long addr, unsigned long end, |
| 30 | unsigned char *vec); |
Kirill A. Shutemov | 4b471e8 | 2016-01-15 16:53:39 -0800 | [diff] [blame] | 31 | extern bool move_huge_pmd(struct vm_area_struct *vma, |
Andrea Arcangeli | 37a1c49 | 2011-10-31 17:08:30 -0700 | [diff] [blame] | 32 | struct vm_area_struct *new_vma, |
| 33 | unsigned long old_addr, |
| 34 | unsigned long new_addr, unsigned long old_end, |
| 35 | pmd_t *old_pmd, pmd_t *new_pmd); |
Johannes Weiner | cd7548a | 2011-01-13 15:47:04 -0800 | [diff] [blame] | 36 | 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] | 37 | unsigned long addr, pgprot_t newprot, |
| 38 | int prot_numa); |
Matthew Wilcox | 5cad465 | 2015-09-08 14:58:54 -0700 | [diff] [blame] | 39 | int vmf_insert_pfn_pmd(struct vm_area_struct *, unsigned long addr, pmd_t *, |
Dan Williams | f25748e3 | 2016-01-15 16:56:43 -0800 | [diff] [blame] | 40 | pfn_t pfn, bool write); |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 41 | enum transparent_hugepage_flag { |
| 42 | TRANSPARENT_HUGEPAGE_FLAG, |
| 43 | TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, |
| 44 | TRANSPARENT_HUGEPAGE_DEFRAG_FLAG, |
| 45 | TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 46 | TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG, |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 47 | TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 48 | #ifdef CONFIG_DEBUG_VM |
| 49 | TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG, |
| 50 | #endif |
| 51 | }; |
| 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 |
Dan Williams | 3565fce | 2016-01-15 16:56:55 -0800 | [diff] [blame] | 57 | struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr, |
| 58 | pmd_t *pmd, int flags); |
| 59 | |
Aneesh Kumar K.V | fde5279 | 2013-06-05 17:14:05 -0700 | [diff] [blame] | 60 | #define HPAGE_PMD_SHIFT PMD_SHIFT |
| 61 | #define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT) |
| 62 | #define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 63 | |
Alex Shi | 2099597 | 2012-05-29 15:06:31 -0700 | [diff] [blame] | 64 | extern bool is_vma_temporary_stack(struct vm_area_struct *vma); |
| 65 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 66 | #define transparent_hugepage_enabled(__vma) \ |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 67 | ((transparent_hugepage_flags & \ |
| 68 | (1<<TRANSPARENT_HUGEPAGE_FLAG) || \ |
| 69 | (transparent_hugepage_flags & \ |
| 70 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \ |
| 71 | ((__vma)->vm_flags & VM_HUGEPAGE))) && \ |
Andrea Arcangeli | a7d6e4e | 2011-02-15 19:02:45 +0100 | [diff] [blame] | 72 | !((__vma)->vm_flags & VM_NOHUGEPAGE) && \ |
| 73 | !is_vma_temporary_stack(__vma)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 74 | #define transparent_hugepage_defrag(__vma) \ |
| 75 | ((transparent_hugepage_flags & \ |
| 76 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) || \ |
| 77 | (transparent_hugepage_flags & \ |
| 78 | (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) && \ |
| 79 | (__vma)->vm_flags & VM_HUGEPAGE)) |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 80 | #define transparent_hugepage_use_zero_page() \ |
| 81 | (transparent_hugepage_flags & \ |
| 82 | (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 83 | #ifdef CONFIG_DEBUG_VM |
| 84 | #define transparent_hugepage_debug_cow() \ |
| 85 | (transparent_hugepage_flags & \ |
| 86 | (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG)) |
| 87 | #else /* CONFIG_DEBUG_VM */ |
| 88 | #define transparent_hugepage_debug_cow() 0 |
| 89 | #endif /* CONFIG_DEBUG_VM */ |
| 90 | |
| 91 | extern unsigned long transparent_hugepage_flags; |
Kirill A. Shutemov | ad0bed2 | 2016-01-15 16:52:53 -0800 | [diff] [blame] | 92 | |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 93 | extern void prep_transhuge_page(struct page *page); |
| 94 | extern void free_transhuge_page(struct page *page); |
| 95 | |
Kirill A. Shutemov | e9b61f1 | 2016-01-15 16:54:10 -0800 | [diff] [blame] | 96 | int split_huge_page_to_list(struct page *page, struct list_head *list); |
| 97 | static inline int split_huge_page(struct page *page) |
| 98 | { |
| 99 | return split_huge_page_to_list(page, NULL); |
| 100 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 101 | void deferred_split_huge_page(struct page *page); |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 102 | |
| 103 | void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
| 104 | unsigned long address); |
| 105 | |
| 106 | #define split_huge_pmd(__vma, __pmd, __address) \ |
| 107 | do { \ |
| 108 | pmd_t *____pmd = (__pmd); \ |
Dan Williams | 5c7fb56 | 2016-01-15 16:56:52 -0800 | [diff] [blame] | 109 | if (pmd_trans_huge(*____pmd) \ |
| 110 | || pmd_devmap(*____pmd)) \ |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 111 | __split_huge_pmd(__vma, __pmd, __address); \ |
| 112 | } while (0) |
Kirill A. Shutemov | ad0bed2 | 2016-01-15 16:52:53 -0800 | [diff] [blame] | 113 | |
Steve Capper | dfa5e23 | 2013-05-07 14:46:03 +0100 | [diff] [blame] | 114 | #if HPAGE_PMD_ORDER >= MAX_ORDER |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 115 | #error "hugepages can't be allocated by the buddy allocator" |
| 116 | #endif |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 117 | extern int hugepage_madvise(struct vm_area_struct *vma, |
| 118 | unsigned long *vm_flags, int advice); |
Kirill A. Shutemov | e1b9996 | 2015-09-08 14:58:37 -0700 | [diff] [blame] | 119 | extern void vma_adjust_trans_huge(struct vm_area_struct *vma, |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 120 | unsigned long start, |
| 121 | unsigned long end, |
| 122 | long adjust_next); |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 123 | extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, |
| 124 | struct vm_area_struct *vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 125 | /* mmap_sem must be held on entry */ |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 126 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
| 127 | struct vm_area_struct *vma) |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 128 | { |
Sasha Levin | 81d1b09 | 2014-10-09 15:28:10 -0700 | [diff] [blame] | 129 | VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_mm->mmap_sem), vma); |
Dan Williams | 5c7fb56 | 2016-01-15 16:56:52 -0800 | [diff] [blame] | 130 | if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 131 | return __pmd_trans_huge_lock(pmd, vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 132 | else |
Kirill A. Shutemov | 4b471e8 | 2016-01-15 16:53:39 -0800 | [diff] [blame] | 133 | return false; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 134 | } |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 135 | static inline int hpage_nr_pages(struct page *page) |
| 136 | { |
| 137 | if (unlikely(PageTransHuge(page))) |
| 138 | return HPAGE_PMD_NR; |
| 139 | return 1; |
| 140 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 141 | |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 142 | extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, |
| 143 | unsigned long addr, pmd_t pmd, pmd_t *pmdp); |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 144 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 145 | extern struct page *huge_zero_page; |
| 146 | |
| 147 | static inline bool is_huge_zero_page(struct page *page) |
| 148 | { |
| 149 | return ACCESS_ONCE(huge_zero_page) == page; |
| 150 | } |
| 151 | |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 152 | static inline bool is_huge_zero_pmd(pmd_t pmd) |
| 153 | { |
| 154 | return is_huge_zero_page(pmd_page(pmd)); |
| 155 | } |
| 156 | |
| 157 | struct page *get_huge_zero_page(void); |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 158 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 159 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 160 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) |
| 161 | #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) |
| 162 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 163 | |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 164 | #define hpage_nr_pages(x) 1 |
| 165 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 166 | #define transparent_hugepage_enabled(__vma) 0 |
| 167 | |
| 168 | #define transparent_hugepage_flags 0UL |
Shaohua Li | 5bc7b8a | 2013-04-29 15:08:36 -0700 | [diff] [blame] | 169 | static inline int |
| 170 | split_huge_page_to_list(struct page *page, struct list_head *list) |
| 171 | { |
| 172 | return 0; |
| 173 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 174 | static inline int split_huge_page(struct page *page) |
| 175 | { |
| 176 | return 0; |
| 177 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 178 | static inline void deferred_split_huge_page(struct page *page) {} |
Kirill A. Shutemov | 78ddc53 | 2016-01-15 16:52:42 -0800 | [diff] [blame] | 179 | #define split_huge_pmd(__vma, __pmd, __address) \ |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 180 | do { } while (0) |
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 | } |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 193 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
| 194 | struct vm_area_struct *vma) |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 195 | { |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 196 | return NULL; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 197 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 198 | |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 199 | static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, |
| 200 | unsigned long addr, pmd_t pmd, pmd_t *pmdp) |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 201 | { |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 202 | return 0; |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 205 | static inline bool is_huge_zero_page(struct page *page) |
| 206 | { |
| 207 | return false; |
| 208 | } |
| 209 | |
Dan Williams | 3565fce | 2016-01-15 16:56:55 -0800 | [diff] [blame] | 210 | |
| 211 | static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma, |
| 212 | unsigned long addr, pmd_t *pmd, int flags) |
| 213 | { |
| 214 | return NULL; |
| 215 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 216 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 217 | |
| 218 | #endif /* _LINUX_HUGE_MM_H */ |