blob: 000837e126e64b3b0e64d67aff67a3c9626e4c5e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_HUGETLB_H
2#define _LINUX_HUGETLB_H
3
Linus Torvaldsbe93d8c2011-05-26 12:03:50 -07004#include <linux/mm_types.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +04005#include <linux/fs.h>
Naoya Horiguchi8edf3442010-05-28 09:29:15 +09006#include <linux/hugetlb_inline.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +04007
Andrew Mortone9ea0e22009-09-24 14:47:45 -07008struct ctl_table;
9struct user_struct;
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#ifdef CONFIG_HUGETLB_PAGE
12
13#include <linux/mempolicy.h>
Adam Litke516dffd2007-03-01 15:46:08 -080014#include <linux/shm.h>
David Gibson63551ae2005-06-21 17:14:44 -070015#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
David Gibson90481622012-03-21 16:34:12 -070017struct hugepage_subpool {
18 spinlock_t lock;
19 long count;
20 long max_hpages, used_hpages;
21};
22
23struct hugepage_subpool *hugepage_new_subpool(long nr_blocks);
24void hugepage_put_subpool(struct hugepage_subpool *spool);
25
Wu Fengguang20a03072009-06-16 15:32:22 -070026int PageHuge(struct page *page);
27
Mel Gormana1e78772008-07-23 21:27:23 -070028void reset_vma_resv_huge_pages(struct vm_area_struct *vma);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070029int hugetlb_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
30int hugetlb_overcommit_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
31int hugetlb_treat_movable_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
Lee Schermerhorn06808b02009-12-14 17:58:21 -080032
33#ifdef CONFIG_NUMA
34int hugetlb_mempolicy_sysctl_handler(struct ctl_table *, int,
35 void __user *, size_t *, loff_t *);
36#endif
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *);
Hugh Dickins2a15efc2009-09-21 17:03:27 -070039int follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
40 struct page **, struct vm_area_struct **,
41 unsigned long *, int *, int, unsigned int flags);
Mel Gorman04f2cbe2008-07-23 21:27:25 -070042void unmap_hugepage_range(struct vm_area_struct *,
43 unsigned long, unsigned long, struct page *);
44void __unmap_hugepage_range(struct vm_area_struct *,
45 unsigned long, unsigned long, struct page *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046int hugetlb_prefault(struct address_space *, struct vm_area_struct *);
Alexey Dobriyane1759c22008-10-15 23:50:22 +040047void hugetlb_report_meminfo(struct seq_file *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048int hugetlb_report_node_meminfo(int, char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049unsigned long hugetlb_total_pages(void);
Hugh Dickinsac9b9c62005-10-20 16:24:28 +010050int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
Hugh Dickins788c7df2009-06-23 13:49:05 +010051 unsigned long address, unsigned int flags);
Mel Gormana1e78772008-07-23 21:27:23 -070052int hugetlb_reserve_pages(struct inode *inode, long from, long to,
Mel Gorman5a6fe122009-02-10 14:02:27 +000053 struct vm_area_struct *vma,
KOSAKI Motohiroca16d142011-05-26 19:16:19 +090054 vm_flags_t vm_flags);
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -070055void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed);
Naoya Horiguchi6de2b1a2010-09-08 10:19:36 +090056int dequeue_hwpoisoned_huge_page(struct page *page);
Naoya Horiguchi0ebabb42010-09-08 10:19:34 +090057void copy_huge_page(struct page *dst, struct page *src);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Mel Gorman396faf02007-07-17 04:03:13 -070059extern unsigned long hugepages_treat_as_movable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060extern const unsigned long hugetlb_zero, hugetlb_infinity;
61extern int sysctl_hugetlb_shm_group;
Jon Tollefson53ba51d2008-07-23 21:27:52 -070062extern struct list_head huge_boot_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
David Gibson63551ae2005-06-21 17:14:44 -070064/* arch callbacks */
65
Andi Kleena5516432008-07-23 21:27:41 -070066pte_t *huge_pte_alloc(struct mm_struct *mm,
67 unsigned long addr, unsigned long sz);
David Gibson63551ae2005-06-21 17:14:44 -070068pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr);
Chen, Kenneth W39dde652006-12-06 20:32:03 -080069int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep);
David Gibson63551ae2005-06-21 17:14:44 -070070struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
71 int write);
72struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
73 pmd_t *pmd, int write);
Andi Kleenceb86872008-07-23 21:27:50 -070074struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
75 pud_t *pud, int write);
David Gibson63551ae2005-06-21 17:14:44 -070076int pmd_huge(pmd_t pmd);
Andi Kleenceb86872008-07-23 21:27:50 -070077int pud_huge(pud_t pmd);
Zhang, Yanmin8f860592006-03-22 00:08:50 -080078void hugetlb_change_protection(struct vm_area_struct *vma,
79 unsigned long address, unsigned long end, pgprot_t newprot);
David Gibson63551ae2005-06-21 17:14:44 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#else /* !CONFIG_HUGETLB_PAGE */
82
Wu Fengguang20a03072009-06-16 15:32:22 -070083static inline int PageHuge(struct page *page)
84{
85 return 0;
86}
87
Mel Gormana1e78772008-07-23 21:27:23 -070088static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
89{
90}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static inline unsigned long hugetlb_total_pages(void)
93{
94 return 0;
95}
96
Adam Litke5b23dbe2007-11-14 16:59:33 -080097#define follow_hugetlb_page(m,v,p,vs,a,b,i,w) ({ BUG(); 0; })
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define follow_huge_addr(mm, addr, write) ERR_PTR(-EINVAL)
99#define copy_hugetlb_page_range(src, dst, vma) ({ BUG(); 0; })
100#define hugetlb_prefault(mapping, vma) ({ BUG(); 0; })
Mel Gorman04f2cbe2008-07-23 21:27:25 -0700101#define unmap_hugepage_range(vma, start, end, page) BUG()
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400102static inline void hugetlb_report_meminfo(struct seq_file *m)
103{
104}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#define hugetlb_report_node_meminfo(n, buf) 0
106#define follow_huge_pmd(mm, addr, pmd, write) NULL
Andi Kleenceb86872008-07-23 21:27:50 -0700107#define follow_huge_pud(mm, addr, pud, write) NULL
Andi Kleena5516432008-07-23 21:27:41 -0700108#define prepare_hugepage_range(file, addr, len) (-EINVAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define pmd_huge(x) 0
Andi Kleenceb86872008-07-23 21:27:50 -0700110#define pud_huge(x) 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define is_hugepage_only_range(mm, addr, len) 0
David Gibson9da61ae2006-03-22 00:08:57 -0800112#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; })
Hugh Dickins788c7df2009-06-23 13:49:05 +0100113#define hugetlb_fault(mm, vma, addr, flags) ({ BUG(); 0; })
Naoya Horiguchi0fe6e202010-05-28 09:29:16 +0900114#define huge_pte_offset(mm, address) 0
Naoya Horiguchi6de2b1a2010-09-08 10:19:36 +0900115#define dequeue_hwpoisoned_huge_page(page) 0
Naoya Horiguchi0ebabb42010-09-08 10:19:34 +0900116static inline void copy_huge_page(struct page *dst, struct page *src)
117{
118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Zhang, Yanmin8f860592006-03-22 00:08:50 -0800120#define hugetlb_change_protection(vma, address, end, newprot)
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif /* !CONFIG_HUGETLB_PAGE */
123
Eric B Munson4e527802009-09-21 17:03:47 -0700124#define HUGETLB_ANON_FILE "anon_hugepage"
125
Eric B Munson6bfde052009-09-21 17:03:43 -0700126enum {
127 /*
128 * The file will be used as an shm file so shmfs accounting rules
129 * apply
130 */
131 HUGETLB_SHMFS_INODE = 1,
Eric B Munson4e527802009-09-21 17:03:47 -0700132 /*
133 * The file is being created on the internal vfs mount and shmfs
134 * accounting rules do not apply
135 */
136 HUGETLB_ANONHUGE_INODE = 2,
Eric B Munson6bfde052009-09-21 17:03:43 -0700137};
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#ifdef CONFIG_HUGETLBFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140struct hugetlbfs_sb_info {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 long max_inodes; /* inodes allowed */
142 long free_inodes; /* inodes free */
143 spinlock_t stat_lock;
Andi Kleena137e1c2008-07-23 21:27:43 -0700144 struct hstate *hstate;
David Gibson90481622012-03-21 16:34:12 -0700145 struct hugepage_subpool *spool;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146};
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
149{
150 return sb->s_fs_info;
151}
152
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800153extern const struct file_operations hugetlbfs_file_operations;
Alexey Dobriyanf0f37e22009-09-27 22:29:37 +0400154extern const struct vm_operations_struct hugetlb_vm_ops;
Steven Truelove40716e22012-03-21 16:34:14 -0700155struct file *hugetlb_file_setup(const char *name, unsigned long addr,
156 size_t size, vm_flags_t acct,
Eric B Munson6bfde052009-09-21 17:03:43 -0700157 struct user_struct **user, int creat_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159static inline int is_file_hugepages(struct file *file)
160{
Adam Litke516dffd2007-03-01 15:46:08 -0800161 if (file->f_op == &hugetlbfs_file_operations)
162 return 1;
163 if (is_file_shm_hugepages(file))
164 return 1;
165
166 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#else /* !CONFIG_HUGETLBFS */
170
Stefan Richter1db85082009-02-10 23:27:32 +0100171#define is_file_hugepages(file) 0
Steven Truelove40716e22012-03-21 16:34:14 -0700172static inline struct file *
173hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
KOSAKI Motohiroca16d142011-05-26 19:16:19 +0900174 vm_flags_t acctflag, struct user_struct **user, int creat_flags)
Andrew Mortone9ea0e22009-09-24 14:47:45 -0700175{
176 return ERR_PTR(-ENOSYS);
177}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179#endif /* !CONFIG_HUGETLBFS */
180
Adrian Bunkd2ba27e82007-05-06 14:49:00 -0700181#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
182unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
183 unsigned long len, unsigned long pgoff,
184 unsigned long flags);
185#endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
186
Andi Kleena5516432008-07-23 21:27:41 -0700187#ifdef CONFIG_HUGETLB_PAGE
188
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700189#define HSTATE_NAME_LEN 32
Andi Kleena5516432008-07-23 21:27:41 -0700190/* Defines one hugetlb page size */
191struct hstate {
Lee Schermerhorne8c5c822009-09-21 17:01:22 -0700192 int next_nid_to_alloc;
193 int next_nid_to_free;
Andi Kleena5516432008-07-23 21:27:41 -0700194 unsigned int order;
195 unsigned long mask;
196 unsigned long max_huge_pages;
197 unsigned long nr_huge_pages;
198 unsigned long free_huge_pages;
199 unsigned long resv_huge_pages;
200 unsigned long surplus_huge_pages;
201 unsigned long nr_overcommit_huge_pages;
202 struct list_head hugepage_freelists[MAX_NUMNODES];
203 unsigned int nr_huge_pages_node[MAX_NUMNODES];
204 unsigned int free_huge_pages_node[MAX_NUMNODES];
205 unsigned int surplus_huge_pages_node[MAX_NUMNODES];
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700206 char name[HSTATE_NAME_LEN];
Andi Kleena5516432008-07-23 21:27:41 -0700207};
208
Jon Tollefson53ba51d2008-07-23 21:27:52 -0700209struct huge_bootmem_page {
210 struct list_head list;
211 struct hstate *hstate;
Becky Bruceee8f2482011-07-25 17:11:50 -0700212#ifdef CONFIG_HIGHMEM
213 phys_addr_t phys;
214#endif
Jon Tollefson53ba51d2008-07-23 21:27:52 -0700215};
216
Naoya Horiguchibf50bab2010-09-08 10:19:33 +0900217struct page *alloc_huge_page_node(struct hstate *h, int nid);
218
Jon Tollefson53ba51d2008-07-23 21:27:52 -0700219/* arch callback */
220int __init alloc_bootmem_huge_page(struct hstate *h);
221
Andi Kleene5ff2152008-07-23 21:27:42 -0700222void __init hugetlb_add_hstate(unsigned order);
223struct hstate *size_to_hstate(unsigned long size);
224
225#ifndef HUGE_MAX_HSTATE
226#define HUGE_MAX_HSTATE 1
227#endif
228
229extern struct hstate hstates[HUGE_MAX_HSTATE];
230extern unsigned int default_hstate_idx;
231
232#define default_hstate (hstates[default_hstate_idx])
Andi Kleena5516432008-07-23 21:27:41 -0700233
Andi Kleena137e1c2008-07-23 21:27:43 -0700234static inline struct hstate *hstate_inode(struct inode *i)
Andi Kleena5516432008-07-23 21:27:41 -0700235{
Andi Kleena137e1c2008-07-23 21:27:43 -0700236 struct hugetlbfs_sb_info *hsb;
237 hsb = HUGETLBFS_SB(i->i_sb);
238 return hsb->hstate;
Andi Kleena5516432008-07-23 21:27:41 -0700239}
240
241static inline struct hstate *hstate_file(struct file *f)
242{
Andi Kleena137e1c2008-07-23 21:27:43 -0700243 return hstate_inode(f->f_dentry->d_inode);
Andi Kleena5516432008-07-23 21:27:41 -0700244}
245
Andi Kleena137e1c2008-07-23 21:27:43 -0700246static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
Andi Kleena5516432008-07-23 21:27:41 -0700247{
Andi Kleena137e1c2008-07-23 21:27:43 -0700248 return hstate_file(vma->vm_file);
Andi Kleena5516432008-07-23 21:27:41 -0700249}
250
251static inline unsigned long huge_page_size(struct hstate *h)
252{
253 return (unsigned long)PAGE_SIZE << h->order;
254}
255
Mel Gorman08fba692009-01-06 14:38:53 -0800256extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
257
Mel Gorman33402892009-01-06 14:38:54 -0800258extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
259
Andi Kleena5516432008-07-23 21:27:41 -0700260static inline unsigned long huge_page_mask(struct hstate *h)
261{
262 return h->mask;
263}
264
265static inline unsigned int huge_page_order(struct hstate *h)
266{
267 return h->order;
268}
269
270static inline unsigned huge_page_shift(struct hstate *h)
271{
272 return h->order + PAGE_SHIFT;
273}
274
275static inline unsigned int pages_per_huge_page(struct hstate *h)
276{
277 return 1 << h->order;
278}
279
280static inline unsigned int blocks_per_huge_page(struct hstate *h)
281{
282 return huge_page_size(h) / 512;
283}
284
285#include <asm/hugetlb.h>
286
Andi Kleene5ff2152008-07-23 21:27:42 -0700287static inline struct hstate *page_hstate(struct page *page)
288{
289 return size_to_hstate(PAGE_SIZE << compound_order(page));
290}
291
Andi Kleenaa50d3a2010-10-06 21:45:00 +0200292static inline unsigned hstate_index_to_shift(unsigned index)
293{
294 return hstates[index].order + PAGE_SHIFT;
295}
296
Andi Kleena5516432008-07-23 21:27:41 -0700297#else
298struct hstate {};
Naoya Horiguchibf50bab2010-09-08 10:19:33 +0900299#define alloc_huge_page_node(h, nid) NULL
Jon Tollefson53ba51d2008-07-23 21:27:52 -0700300#define alloc_bootmem_huge_page(h) NULL
Andi Kleena5516432008-07-23 21:27:41 -0700301#define hstate_file(f) NULL
302#define hstate_vma(v) NULL
303#define hstate_inode(i) NULL
304#define huge_page_size(h) PAGE_SIZE
305#define huge_page_mask(h) PAGE_MASK
Mel Gorman08fba692009-01-06 14:38:53 -0800306#define vma_kernel_pagesize(v) PAGE_SIZE
Mel Gorman33402892009-01-06 14:38:54 -0800307#define vma_mmu_pagesize(v) PAGE_SIZE
Andi Kleena5516432008-07-23 21:27:41 -0700308#define huge_page_order(h) 0
309#define huge_page_shift(h) PAGE_SHIFT
Andrea Righi510a35d2008-07-26 15:22:27 -0700310static inline unsigned int pages_per_huge_page(struct hstate *h)
311{
312 return 1;
313}
Andi Kleenaa50d3a2010-10-06 21:45:00 +0200314#define hstate_index_to_shift(index) 0
Andi Kleena5516432008-07-23 21:27:41 -0700315#endif
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#endif /* _LINUX_HUGETLB_H */