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