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, |
Mel Gorman | 444eb2a4 | 2016-03-17 14:19:23 -0700 | [diff] [blame] | 44 | TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, |
| 45 | TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 46 | TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, |
Andrea Arcangeli | ba76149 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 47 | TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG, |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 48 | TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG, |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 49 | #ifdef CONFIG_DEBUG_VM |
| 50 | TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG, |
| 51 | #endif |
| 52 | }; |
| 53 | |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 54 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) |
| 55 | #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER) |
| 56 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 57 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Dan Williams | 3565fce | 2016-01-15 16:56:55 -0800 | [diff] [blame] | 58 | struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr, |
| 59 | pmd_t *pmd, int flags); |
| 60 | |
Aneesh Kumar K.V | fde5279 | 2013-06-05 17:14:05 -0700 | [diff] [blame] | 61 | #define HPAGE_PMD_SHIFT PMD_SHIFT |
| 62 | #define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT) |
| 63 | #define HPAGE_PMD_MASK (~(HPAGE_PMD_SIZE - 1)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 64 | |
Alex Shi | 2099597 | 2012-05-29 15:06:31 -0700 | [diff] [blame] | 65 | extern bool is_vma_temporary_stack(struct vm_area_struct *vma); |
| 66 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 67 | #define transparent_hugepage_enabled(__vma) \ |
Andrea Arcangeli | a664b2d | 2011-01-13 15:47:17 -0800 | [diff] [blame] | 68 | ((transparent_hugepage_flags & \ |
| 69 | (1<<TRANSPARENT_HUGEPAGE_FLAG) || \ |
| 70 | (transparent_hugepage_flags & \ |
| 71 | (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) && \ |
| 72 | ((__vma)->vm_flags & VM_HUGEPAGE))) && \ |
Andrea Arcangeli | a7d6e4e | 2011-02-15 19:02:45 +0100 | [diff] [blame] | 73 | !((__vma)->vm_flags & VM_NOHUGEPAGE) && \ |
| 74 | !is_vma_temporary_stack(__vma)) |
Kirill A. Shutemov | 79da540 | 2012-12-12 13:51:12 -0800 | [diff] [blame] | 75 | #define transparent_hugepage_use_zero_page() \ |
| 76 | (transparent_hugepage_flags & \ |
| 77 | (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG)) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 78 | #ifdef CONFIG_DEBUG_VM |
| 79 | #define transparent_hugepage_debug_cow() \ |
| 80 | (transparent_hugepage_flags & \ |
| 81 | (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG)) |
| 82 | #else /* CONFIG_DEBUG_VM */ |
| 83 | #define transparent_hugepage_debug_cow() 0 |
| 84 | #endif /* CONFIG_DEBUG_VM */ |
| 85 | |
| 86 | extern unsigned long transparent_hugepage_flags; |
Kirill A. Shutemov | ad0bed2 | 2016-01-15 16:52:53 -0800 | [diff] [blame] | 87 | |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 88 | extern void prep_transhuge_page(struct page *page); |
| 89 | extern void free_transhuge_page(struct page *page); |
| 90 | |
Kirill A. Shutemov | e9b61f1 | 2016-01-15 16:54:10 -0800 | [diff] [blame] | 91 | int split_huge_page_to_list(struct page *page, struct list_head *list); |
| 92 | static inline int split_huge_page(struct page *page) |
| 93 | { |
| 94 | return split_huge_page_to_list(page, NULL); |
| 95 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 96 | void deferred_split_huge_page(struct page *page); |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 97 | |
| 98 | void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 99 | unsigned long address, bool freeze); |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 100 | |
| 101 | #define split_huge_pmd(__vma, __pmd, __address) \ |
| 102 | do { \ |
| 103 | pmd_t *____pmd = (__pmd); \ |
Dan Williams | 5c7fb56 | 2016-01-15 16:56:52 -0800 | [diff] [blame] | 104 | if (pmd_trans_huge(*____pmd) \ |
| 105 | || pmd_devmap(*____pmd)) \ |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 106 | __split_huge_pmd(__vma, __pmd, __address, \ |
| 107 | false); \ |
Kirill A. Shutemov | eef1b3b | 2016-01-15 16:53:53 -0800 | [diff] [blame] | 108 | } while (0) |
Kirill A. Shutemov | ad0bed2 | 2016-01-15 16:52:53 -0800 | [diff] [blame] | 109 | |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 110 | |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 111 | void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address, |
| 112 | bool freeze, struct page *page); |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 113 | |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 114 | extern int hugepage_madvise(struct vm_area_struct *vma, |
| 115 | unsigned long *vm_flags, int advice); |
Kirill A. Shutemov | e1b9996 | 2015-09-08 14:58:37 -0700 | [diff] [blame] | 116 | extern void vma_adjust_trans_huge(struct vm_area_struct *vma, |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 117 | unsigned long start, |
| 118 | unsigned long end, |
| 119 | long adjust_next); |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 120 | extern spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, |
| 121 | struct vm_area_struct *vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 122 | /* mmap_sem must be held on entry */ |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 123 | static inline 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 | { |
Sasha Levin | 81d1b09 | 2014-10-09 15:28:10 -0700 | [diff] [blame] | 126 | 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] | 127 | if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 128 | return __pmd_trans_huge_lock(pmd, vma); |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 129 | else |
Chen Gang | 969e8d7 | 2016-04-01 14:31:17 -0700 | [diff] [blame] | 130 | return NULL; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 131 | } |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 132 | static inline int hpage_nr_pages(struct page *page) |
| 133 | { |
| 134 | if (unlikely(PageTransHuge(page))) |
| 135 | return HPAGE_PMD_NR; |
| 136 | return 1; |
| 137 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 138 | |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 139 | extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, |
| 140 | unsigned long addr, pmd_t pmd, pmd_t *pmdp); |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 141 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 142 | extern struct page *huge_zero_page; |
| 143 | |
| 144 | static inline bool is_huge_zero_page(struct page *page) |
| 145 | { |
| 146 | return ACCESS_ONCE(huge_zero_page) == page; |
| 147 | } |
| 148 | |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 149 | static inline bool is_huge_zero_pmd(pmd_t pmd) |
| 150 | { |
| 151 | return is_huge_zero_page(pmd_page(pmd)); |
| 152 | } |
| 153 | |
| 154 | struct page *get_huge_zero_page(void); |
Kirill A. Shutemov | aa88b68 | 2016-04-28 16:18:27 -0700 | [diff] [blame] | 155 | void put_huge_zero_page(void); |
Matthew Wilcox | fc43704 | 2015-09-08 14:58:51 -0700 | [diff] [blame] | 156 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 157 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
Naoya Horiguchi | d8c37c4 | 2012-03-21 16:34:27 -0700 | [diff] [blame] | 158 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) |
| 159 | #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) |
| 160 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 161 | |
Rik van Riel | 2c888cf | 2011-01-13 15:47:13 -0800 | [diff] [blame] | 162 | #define hpage_nr_pages(x) 1 |
| 163 | |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 164 | #define transparent_hugepage_enabled(__vma) 0 |
| 165 | |
| 166 | #define transparent_hugepage_flags 0UL |
Shaohua Li | 5bc7b8a | 2013-04-29 15:08:36 -0700 | [diff] [blame] | 167 | static inline int |
| 168 | split_huge_page_to_list(struct page *page, struct list_head *list) |
| 169 | { |
| 170 | return 0; |
| 171 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 172 | static inline int split_huge_page(struct page *page) |
| 173 | { |
| 174 | return 0; |
| 175 | } |
Kirill A. Shutemov | 9a98225 | 2016-01-15 16:54:17 -0800 | [diff] [blame] | 176 | static inline void deferred_split_huge_page(struct page *page) {} |
Kirill A. Shutemov | 78ddc53 | 2016-01-15 16:52:42 -0800 | [diff] [blame] | 177 | #define split_huge_pmd(__vma, __pmd, __address) \ |
Kirill A. Shutemov | e180377 | 2012-12-12 13:50:59 -0800 | [diff] [blame] | 178 | do { } while (0) |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 179 | |
| 180 | static inline void split_huge_pmd_address(struct vm_area_struct *vma, |
Kirill A. Shutemov | fec89c1 | 2016-03-17 14:20:10 -0700 | [diff] [blame] | 181 | unsigned long address, bool freeze, struct page *page) {} |
Kirill A. Shutemov | 2a52bcb | 2016-03-17 14:20:04 -0700 | [diff] [blame] | 182 | |
Andrea Arcangeli | 60ab324 | 2011-01-13 15:47:18 -0800 | [diff] [blame] | 183 | static inline int hugepage_madvise(struct vm_area_struct *vma, |
| 184 | unsigned long *vm_flags, int advice) |
Andrea Arcangeli | 0af4e98 | 2011-01-13 15:46:55 -0800 | [diff] [blame] | 185 | { |
| 186 | BUG(); |
| 187 | return 0; |
| 188 | } |
Andrea Arcangeli | 94fcc58 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 189 | static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, |
| 190 | unsigned long start, |
| 191 | unsigned long end, |
| 192 | long adjust_next) |
| 193 | { |
| 194 | } |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 195 | static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, |
| 196 | struct vm_area_struct *vma) |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 197 | { |
Kirill A. Shutemov | b6ec57f | 2016-01-21 16:40:25 -0800 | [diff] [blame] | 198 | return NULL; |
Naoya Horiguchi | 025c5b2 | 2012-03-21 16:33:57 -0700 | [diff] [blame] | 199 | } |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 200 | |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 201 | static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, |
| 202 | unsigned long addr, pmd_t pmd, pmd_t *pmdp) |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 203 | { |
Mel Gorman | 4daae3b | 2012-11-02 11:33:45 +0000 | [diff] [blame] | 204 | return 0; |
Mel Gorman | d10e63f | 2012-10-25 14:16:31 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Wang, Yalin | 56873f4 | 2015-02-11 15:24:51 -0800 | [diff] [blame] | 207 | static inline bool is_huge_zero_page(struct page *page) |
| 208 | { |
| 209 | return false; |
| 210 | } |
| 211 | |
Kirill A. Shutemov | aa88b68 | 2016-04-28 16:18:27 -0700 | [diff] [blame] | 212 | static inline void put_huge_zero_page(void) |
| 213 | { |
| 214 | BUILD_BUG(); |
| 215 | } |
Dan Williams | 3565fce | 2016-01-15 16:56:55 -0800 | [diff] [blame] | 216 | |
| 217 | static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma, |
| 218 | unsigned long addr, pmd_t *pmd, int flags) |
| 219 | { |
| 220 | return NULL; |
| 221 | } |
Andrea Arcangeli | 71e3aac | 2011-01-13 15:46:52 -0800 | [diff] [blame] | 222 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
| 223 | |
| 224 | #endif /* _LINUX_HUGE_MM_H */ |