]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_HUGETLB_H |
2 | #define _LINUX_HUGETLB_H | |
3 | ||
be93d8cf | 4 | #include <linux/mm_types.h> |
309381fe | 5 | #include <linux/mmdebug.h> |
4e950f6f | 6 | #include <linux/fs.h> |
8edf344c | 7 | #include <linux/hugetlb_inline.h> |
abb8206c | 8 | #include <linux/cgroup.h> |
9119a41e JK |
9 | #include <linux/list.h> |
10 | #include <linux/kref.h> | |
4e950f6f | 11 | |
e9ea0e2d AM |
12 | struct ctl_table; |
13 | struct user_struct; | |
24669e58 | 14 | struct mmu_gather; |
e9ea0e2d | 15 | |
1da177e4 LT |
16 | #ifdef CONFIG_HUGETLB_PAGE |
17 | ||
18 | #include <linux/mempolicy.h> | |
516dffdc | 19 | #include <linux/shm.h> |
63551ae0 | 20 | #include <asm/tlbflush.h> |
1da177e4 | 21 | |
90481622 DG |
22 | struct hugepage_subpool { |
23 | spinlock_t lock; | |
24 | long count; | |
25 | long max_hpages, used_hpages; | |
26 | }; | |
27 | ||
9119a41e JK |
28 | struct resv_map { |
29 | struct kref refs; | |
30 | struct list_head regions; | |
31 | }; | |
32 | extern struct resv_map *resv_map_alloc(void); | |
33 | void resv_map_release(struct kref *ref); | |
34 | ||
c3f38a38 AK |
35 | extern spinlock_t hugetlb_lock; |
36 | extern int hugetlb_max_hstate __read_mostly; | |
37 | #define for_each_hstate(h) \ | |
38 | for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++) | |
39 | ||
90481622 DG |
40 | struct hugepage_subpool *hugepage_new_subpool(long nr_blocks); |
41 | void hugepage_put_subpool(struct hugepage_subpool *spool); | |
42 | ||
20a0307c WF |
43 | int PageHuge(struct page *page); |
44 | ||
a1e78772 | 45 | void reset_vma_resv_huge_pages(struct vm_area_struct *vma); |
8d65af78 AD |
46 | int hugetlb_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); |
47 | int hugetlb_overcommit_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); | |
48 | int hugetlb_treat_movable_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); | |
06808b08 LS |
49 | |
50 | #ifdef CONFIG_NUMA | |
51 | int hugetlb_mempolicy_sysctl_handler(struct ctl_table *, int, | |
52 | void __user *, size_t *, loff_t *); | |
53 | #endif | |
54 | ||
1da177e4 | 55 | int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *); |
28a35716 ML |
56 | long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, |
57 | struct page **, struct vm_area_struct **, | |
58 | unsigned long *, unsigned long *, long, unsigned int); | |
04f2cbe3 | 59 | void unmap_hugepage_range(struct vm_area_struct *, |
24669e58 | 60 | unsigned long, unsigned long, struct page *); |
d833352a MG |
61 | void __unmap_hugepage_range_final(struct mmu_gather *tlb, |
62 | struct vm_area_struct *vma, | |
63 | unsigned long start, unsigned long end, | |
64 | struct page *ref_page); | |
24669e58 AK |
65 | void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, |
66 | unsigned long start, unsigned long end, | |
67 | struct page *ref_page); | |
e1759c21 | 68 | void hugetlb_report_meminfo(struct seq_file *); |
1da177e4 | 69 | int hugetlb_report_node_meminfo(int, char *); |
949f7ec5 | 70 | void hugetlb_show_meminfo(void); |
1da177e4 | 71 | unsigned long hugetlb_total_pages(void); |
ac9b9c66 | 72 | int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, |
788c7df4 | 73 | unsigned long address, unsigned int flags); |
a1e78772 | 74 | int hugetlb_reserve_pages(struct inode *inode, long from, long to, |
5a6fe125 | 75 | struct vm_area_struct *vma, |
ca16d140 | 76 | vm_flags_t vm_flags); |
a43a8c39 | 77 | void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed); |
6de2b1aa | 78 | int dequeue_hwpoisoned_huge_page(struct page *page); |
31caf665 NH |
79 | bool isolate_huge_page(struct page *page, struct list_head *list); |
80 | void putback_active_hugepage(struct page *page); | |
c8721bbb | 81 | bool is_hugepage_active(struct page *page); |
1da177e4 | 82 | |
3212b535 SC |
83 | #ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE |
84 | pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud); | |
85 | #endif | |
86 | ||
396faf03 | 87 | extern unsigned long hugepages_treat_as_movable; |
1da177e4 LT |
88 | extern const unsigned long hugetlb_zero, hugetlb_infinity; |
89 | extern int sysctl_hugetlb_shm_group; | |
53ba51d2 | 90 | extern struct list_head huge_boot_pages; |
1da177e4 | 91 | |
63551ae0 DG |
92 | /* arch callbacks */ |
93 | ||
a5516438 AK |
94 | pte_t *huge_pte_alloc(struct mm_struct *mm, |
95 | unsigned long addr, unsigned long sz); | |
63551ae0 | 96 | pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr); |
39dde65c | 97 | int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep); |
63551ae0 DG |
98 | struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address, |
99 | int write); | |
100 | struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address, | |
101 | pmd_t *pmd, int write); | |
ceb86879 AK |
102 | struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address, |
103 | pud_t *pud, int write); | |
63551ae0 | 104 | int pmd_huge(pmd_t pmd); |
ceb86879 | 105 | int pud_huge(pud_t pmd); |
7da4d641 | 106 | unsigned long hugetlb_change_protection(struct vm_area_struct *vma, |
8f860591 | 107 | unsigned long address, unsigned long end, pgprot_t newprot); |
63551ae0 | 108 | |
1da177e4 LT |
109 | #else /* !CONFIG_HUGETLB_PAGE */ |
110 | ||
20a0307c WF |
111 | static inline int PageHuge(struct page *page) |
112 | { | |
113 | return 0; | |
114 | } | |
115 | ||
a1e78772 MG |
116 | static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma) |
117 | { | |
118 | } | |
119 | ||
1da177e4 LT |
120 | static inline unsigned long hugetlb_total_pages(void) |
121 | { | |
122 | return 0; | |
123 | } | |
124 | ||
5b23dbe8 | 125 | #define follow_hugetlb_page(m,v,p,vs,a,b,i,w) ({ BUG(); 0; }) |
1da177e4 LT |
126 | #define follow_huge_addr(mm, addr, write) ERR_PTR(-EINVAL) |
127 | #define copy_hugetlb_page_range(src, dst, vma) ({ BUG(); 0; }) | |
e1759c21 AD |
128 | static inline void hugetlb_report_meminfo(struct seq_file *m) |
129 | { | |
130 | } | |
1da177e4 | 131 | #define hugetlb_report_node_meminfo(n, buf) 0 |
949f7ec5 DR |
132 | static inline void hugetlb_show_meminfo(void) |
133 | { | |
134 | } | |
1da177e4 | 135 | #define follow_huge_pmd(mm, addr, pmd, write) NULL |
ceb86879 | 136 | #define follow_huge_pud(mm, addr, pud, write) NULL |
a5516438 | 137 | #define prepare_hugepage_range(file, addr, len) (-EINVAL) |
1da177e4 | 138 | #define pmd_huge(x) 0 |
ceb86879 | 139 | #define pud_huge(x) 0 |
1da177e4 | 140 | #define is_hugepage_only_range(mm, addr, len) 0 |
9da61aef | 141 | #define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; }) |
788c7df4 | 142 | #define hugetlb_fault(mm, vma, addr, flags) ({ BUG(); 0; }) |
0fe6e20b | 143 | #define huge_pte_offset(mm, address) 0 |
24669e58 AK |
144 | static inline int dequeue_hwpoisoned_huge_page(struct page *page) |
145 | { | |
146 | return 0; | |
147 | } | |
148 | ||
f40386a4 NH |
149 | static inline bool isolate_huge_page(struct page *page, struct list_head *list) |
150 | { | |
151 | return false; | |
152 | } | |
31caf665 | 153 | #define putback_active_hugepage(p) do {} while (0) |
c8721bbb | 154 | #define is_hugepage_active(x) false |
1da177e4 | 155 | |
7da4d641 PZ |
156 | static inline unsigned long hugetlb_change_protection(struct vm_area_struct *vma, |
157 | unsigned long address, unsigned long end, pgprot_t newprot) | |
158 | { | |
159 | return 0; | |
160 | } | |
8f860591 | 161 | |
d833352a MG |
162 | static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb, |
163 | struct vm_area_struct *vma, unsigned long start, | |
164 | unsigned long end, struct page *ref_page) | |
165 | { | |
166 | BUG(); | |
167 | } | |
168 | ||
24669e58 AK |
169 | static inline void __unmap_hugepage_range(struct mmu_gather *tlb, |
170 | struct vm_area_struct *vma, unsigned long start, | |
171 | unsigned long end, struct page *ref_page) | |
172 | { | |
173 | BUG(); | |
174 | } | |
175 | ||
1da177e4 LT |
176 | #endif /* !CONFIG_HUGETLB_PAGE */ |
177 | ||
4e52780d EM |
178 | #define HUGETLB_ANON_FILE "anon_hugepage" |
179 | ||
6bfde05b EM |
180 | enum { |
181 | /* | |
182 | * The file will be used as an shm file so shmfs accounting rules | |
183 | * apply | |
184 | */ | |
185 | HUGETLB_SHMFS_INODE = 1, | |
4e52780d EM |
186 | /* |
187 | * The file is being created on the internal vfs mount and shmfs | |
188 | * accounting rules do not apply | |
189 | */ | |
190 | HUGETLB_ANONHUGE_INODE = 2, | |
6bfde05b EM |
191 | }; |
192 | ||
1da177e4 | 193 | #ifdef CONFIG_HUGETLBFS |
1da177e4 | 194 | struct hugetlbfs_sb_info { |
1da177e4 LT |
195 | long max_inodes; /* inodes allowed */ |
196 | long free_inodes; /* inodes free */ | |
197 | spinlock_t stat_lock; | |
a137e1cc | 198 | struct hstate *hstate; |
90481622 | 199 | struct hugepage_subpool *spool; |
1da177e4 LT |
200 | }; |
201 | ||
1da177e4 LT |
202 | static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb) |
203 | { | |
204 | return sb->s_fs_info; | |
205 | } | |
206 | ||
4b6f5d20 | 207 | extern const struct file_operations hugetlbfs_file_operations; |
f0f37e2f | 208 | extern const struct vm_operations_struct hugetlb_vm_ops; |
af73e4d9 | 209 | struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct, |
42d7395f AK |
210 | struct user_struct **user, int creat_flags, |
211 | int page_size_log); | |
1da177e4 LT |
212 | |
213 | static inline int is_file_hugepages(struct file *file) | |
214 | { | |
516dffdc AL |
215 | if (file->f_op == &hugetlbfs_file_operations) |
216 | return 1; | |
217 | if (is_file_shm_hugepages(file)) | |
218 | return 1; | |
219 | ||
220 | return 0; | |
1da177e4 LT |
221 | } |
222 | ||
42d7395f | 223 | |
1da177e4 LT |
224 | #else /* !CONFIG_HUGETLBFS */ |
225 | ||
1db8508c | 226 | #define is_file_hugepages(file) 0 |
40716e29 | 227 | static inline struct file * |
af73e4d9 NH |
228 | hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag, |
229 | struct user_struct **user, int creat_flags, | |
42d7395f | 230 | int page_size_log) |
e9ea0e2d AM |
231 | { |
232 | return ERR_PTR(-ENOSYS); | |
233 | } | |
1da177e4 LT |
234 | |
235 | #endif /* !CONFIG_HUGETLBFS */ | |
236 | ||
d2ba27e8 AB |
237 | #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA |
238 | unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, | |
239 | unsigned long len, unsigned long pgoff, | |
240 | unsigned long flags); | |
241 | #endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */ | |
242 | ||
a5516438 AK |
243 | #ifdef CONFIG_HUGETLB_PAGE |
244 | ||
a3437870 | 245 | #define HSTATE_NAME_LEN 32 |
a5516438 AK |
246 | /* Defines one hugetlb page size */ |
247 | struct hstate { | |
e8c5c824 LS |
248 | int next_nid_to_alloc; |
249 | int next_nid_to_free; | |
a5516438 AK |
250 | unsigned int order; |
251 | unsigned long mask; | |
252 | unsigned long max_huge_pages; | |
253 | unsigned long nr_huge_pages; | |
254 | unsigned long free_huge_pages; | |
255 | unsigned long resv_huge_pages; | |
256 | unsigned long surplus_huge_pages; | |
257 | unsigned long nr_overcommit_huge_pages; | |
0edaecfa | 258 | struct list_head hugepage_activelist; |
a5516438 AK |
259 | struct list_head hugepage_freelists[MAX_NUMNODES]; |
260 | unsigned int nr_huge_pages_node[MAX_NUMNODES]; | |
261 | unsigned int free_huge_pages_node[MAX_NUMNODES]; | |
262 | unsigned int surplus_huge_pages_node[MAX_NUMNODES]; | |
abb8206c AK |
263 | #ifdef CONFIG_CGROUP_HUGETLB |
264 | /* cgroup control files */ | |
265 | struct cftype cgroup_files[5]; | |
266 | #endif | |
a3437870 | 267 | char name[HSTATE_NAME_LEN]; |
a5516438 AK |
268 | }; |
269 | ||
53ba51d2 JT |
270 | struct huge_bootmem_page { |
271 | struct list_head list; | |
272 | struct hstate *hstate; | |
ee8f248d BB |
273 | #ifdef CONFIG_HIGHMEM |
274 | phys_addr_t phys; | |
275 | #endif | |
53ba51d2 JT |
276 | }; |
277 | ||
bf50bab2 | 278 | struct page *alloc_huge_page_node(struct hstate *h, int nid); |
74060e4d NH |
279 | struct page *alloc_huge_page_noerr(struct vm_area_struct *vma, |
280 | unsigned long addr, int avoid_reserve); | |
bf50bab2 | 281 | |
53ba51d2 JT |
282 | /* arch callback */ |
283 | int __init alloc_bootmem_huge_page(struct hstate *h); | |
284 | ||
e5ff2159 AK |
285 | void __init hugetlb_add_hstate(unsigned order); |
286 | struct hstate *size_to_hstate(unsigned long size); | |
287 | ||
288 | #ifndef HUGE_MAX_HSTATE | |
289 | #define HUGE_MAX_HSTATE 1 | |
290 | #endif | |
291 | ||
292 | extern struct hstate hstates[HUGE_MAX_HSTATE]; | |
293 | extern unsigned int default_hstate_idx; | |
294 | ||
295 | #define default_hstate (hstates[default_hstate_idx]) | |
a5516438 | 296 | |
a137e1cc | 297 | static inline struct hstate *hstate_inode(struct inode *i) |
a5516438 | 298 | { |
a137e1cc AK |
299 | struct hugetlbfs_sb_info *hsb; |
300 | hsb = HUGETLBFS_SB(i->i_sb); | |
301 | return hsb->hstate; | |
a5516438 AK |
302 | } |
303 | ||
304 | static inline struct hstate *hstate_file(struct file *f) | |
305 | { | |
496ad9aa | 306 | return hstate_inode(file_inode(f)); |
a5516438 AK |
307 | } |
308 | ||
af73e4d9 NH |
309 | static inline struct hstate *hstate_sizelog(int page_size_log) |
310 | { | |
311 | if (!page_size_log) | |
312 | return &default_hstate; | |
313 | return size_to_hstate(1 << page_size_log); | |
314 | } | |
315 | ||
a137e1cc | 316 | static inline struct hstate *hstate_vma(struct vm_area_struct *vma) |
a5516438 | 317 | { |
a137e1cc | 318 | return hstate_file(vma->vm_file); |
a5516438 AK |
319 | } |
320 | ||
321 | static inline unsigned long huge_page_size(struct hstate *h) | |
322 | { | |
323 | return (unsigned long)PAGE_SIZE << h->order; | |
324 | } | |
325 | ||
08fba699 MG |
326 | extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma); |
327 | ||
3340289d MG |
328 | extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma); |
329 | ||
a5516438 AK |
330 | static inline unsigned long huge_page_mask(struct hstate *h) |
331 | { | |
332 | return h->mask; | |
333 | } | |
334 | ||
335 | static inline unsigned int huge_page_order(struct hstate *h) | |
336 | { | |
337 | return h->order; | |
338 | } | |
339 | ||
340 | static inline unsigned huge_page_shift(struct hstate *h) | |
341 | { | |
342 | return h->order + PAGE_SHIFT; | |
343 | } | |
344 | ||
345 | static inline unsigned int pages_per_huge_page(struct hstate *h) | |
346 | { | |
347 | return 1 << h->order; | |
348 | } | |
349 | ||
350 | static inline unsigned int blocks_per_huge_page(struct hstate *h) | |
351 | { | |
352 | return huge_page_size(h) / 512; | |
353 | } | |
354 | ||
355 | #include <asm/hugetlb.h> | |
356 | ||
d9ed9faa CM |
357 | #ifndef arch_make_huge_pte |
358 | static inline pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma, | |
359 | struct page *page, int writable) | |
360 | { | |
361 | return entry; | |
362 | } | |
363 | #endif | |
364 | ||
e5ff2159 AK |
365 | static inline struct hstate *page_hstate(struct page *page) |
366 | { | |
309381fe | 367 | VM_BUG_ON_PAGE(!PageHuge(page), page); |
e5ff2159 AK |
368 | return size_to_hstate(PAGE_SIZE << compound_order(page)); |
369 | } | |
370 | ||
aa50d3a7 AK |
371 | static inline unsigned hstate_index_to_shift(unsigned index) |
372 | { | |
373 | return hstates[index].order + PAGE_SHIFT; | |
374 | } | |
375 | ||
972dc4de AK |
376 | static inline int hstate_index(struct hstate *h) |
377 | { | |
378 | return h - hstates; | |
379 | } | |
380 | ||
13d60f4b ZY |
381 | pgoff_t __basepage_index(struct page *page); |
382 | ||
383 | /* Return page->index in PAGE_SIZE units */ | |
384 | static inline pgoff_t basepage_index(struct page *page) | |
385 | { | |
386 | if (!PageCompound(page)) | |
387 | return page->index; | |
388 | ||
389 | return __basepage_index(page); | |
390 | } | |
391 | ||
c8721bbb NH |
392 | extern void dissolve_free_huge_pages(unsigned long start_pfn, |
393 | unsigned long end_pfn); | |
83467efb NH |
394 | int pmd_huge_support(void); |
395 | /* | |
396 | * Currently hugepage migration is enabled only for pmd-based hugepage. | |
397 | * This function will be updated when hugepage migration is more widely | |
398 | * supported. | |
399 | */ | |
400 | static inline int hugepage_migration_support(struct hstate *h) | |
401 | { | |
402 | return pmd_huge_support() && (huge_page_shift(h) == PMD_SHIFT); | |
403 | } | |
c8721bbb | 404 | |
cb900f41 KS |
405 | static inline spinlock_t *huge_pte_lockptr(struct hstate *h, |
406 | struct mm_struct *mm, pte_t *pte) | |
407 | { | |
408 | if (huge_page_size(h) == PMD_SIZE) | |
409 | return pmd_lockptr(mm, (pmd_t *) pte); | |
410 | VM_BUG_ON(huge_page_size(h) == PAGE_SIZE); | |
411 | return &mm->page_table_lock; | |
412 | } | |
413 | ||
af73e4d9 | 414 | #else /* CONFIG_HUGETLB_PAGE */ |
a5516438 | 415 | struct hstate {}; |
bf50bab2 | 416 | #define alloc_huge_page_node(h, nid) NULL |
74060e4d | 417 | #define alloc_huge_page_noerr(v, a, r) NULL |
53ba51d2 | 418 | #define alloc_bootmem_huge_page(h) NULL |
a5516438 | 419 | #define hstate_file(f) NULL |
af73e4d9 | 420 | #define hstate_sizelog(s) NULL |
a5516438 AK |
421 | #define hstate_vma(v) NULL |
422 | #define hstate_inode(i) NULL | |
cb900f41 | 423 | #define page_hstate(page) NULL |
a5516438 AK |
424 | #define huge_page_size(h) PAGE_SIZE |
425 | #define huge_page_mask(h) PAGE_MASK | |
08fba699 | 426 | #define vma_kernel_pagesize(v) PAGE_SIZE |
3340289d | 427 | #define vma_mmu_pagesize(v) PAGE_SIZE |
a5516438 AK |
428 | #define huge_page_order(h) 0 |
429 | #define huge_page_shift(h) PAGE_SHIFT | |
510a35d4 AR |
430 | static inline unsigned int pages_per_huge_page(struct hstate *h) |
431 | { | |
432 | return 1; | |
433 | } | |
aa50d3a7 | 434 | #define hstate_index_to_shift(index) 0 |
972dc4de | 435 | #define hstate_index(h) 0 |
13d60f4b ZY |
436 | |
437 | static inline pgoff_t basepage_index(struct page *page) | |
438 | { | |
439 | return page->index; | |
440 | } | |
c8721bbb | 441 | #define dissolve_free_huge_pages(s, e) do {} while (0) |
83467efb NH |
442 | #define pmd_huge_support() 0 |
443 | #define hugepage_migration_support(h) 0 | |
cb900f41 KS |
444 | |
445 | static inline spinlock_t *huge_pte_lockptr(struct hstate *h, | |
446 | struct mm_struct *mm, pte_t *pte) | |
447 | { | |
448 | return &mm->page_table_lock; | |
449 | } | |
af73e4d9 | 450 | #endif /* CONFIG_HUGETLB_PAGE */ |
a5516438 | 451 | |
cb900f41 KS |
452 | static inline spinlock_t *huge_pte_lock(struct hstate *h, |
453 | struct mm_struct *mm, pte_t *pte) | |
454 | { | |
455 | spinlock_t *ptl; | |
456 | ||
457 | ptl = huge_pte_lockptr(h, mm, pte); | |
458 | spin_lock(ptl); | |
459 | return ptl; | |
460 | } | |
461 | ||
1da177e4 | 462 | #endif /* _LINUX_HUGETLB_H */ |