blob: 16cdb75a543a031f0e5fbb67998104a7ee12ee34 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_HUGETLB_H
2#define _LINUX_HUGETLB_H
3
Alexey Dobriyan4e950f62007-07-30 02:36:13 +04004#include <linux/fs.h>
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#ifdef CONFIG_HUGETLB_PAGE
7
8#include <linux/mempolicy.h>
Adam Litke516dffd2007-03-01 15:46:08 -08009#include <linux/shm.h>
David Gibson63551ae2005-06-21 17:14:44 -070010#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12struct ctl_table;
Hugh Dickins353d5c32009-08-24 16:30:28 +010013struct user_struct;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Wu Fengguang20a03072009-06-16 15:32:22 -070015int PageHuge(struct page *page);
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
18{
19 return vma->vm_flags & VM_HUGETLB;
20}
21
Mel Gormana1e78772008-07-23 21:27:23 -070022void reset_vma_resv_huge_pages(struct vm_area_struct *vma);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023int hugetlb_sysctl_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *);
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -080024int hugetlb_overcommit_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *);
Mel Gorman396faf02007-07-17 04:03:13 -070025int hugetlb_treat_movable_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *);
Adam Litke5b23dbe2007-11-14 16:59:33 -080027int follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, struct page **, struct vm_area_struct **, unsigned long *, int *, int, int);
Mel Gorman04f2cbe2008-07-23 21:27:25 -070028void unmap_hugepage_range(struct vm_area_struct *,
29 unsigned long, unsigned long, struct page *);
30void __unmap_hugepage_range(struct vm_area_struct *,
31 unsigned long, unsigned long, struct page *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032int hugetlb_prefault(struct address_space *, struct vm_area_struct *);
Alexey Dobriyane1759c22008-10-15 23:50:22 +040033void hugetlb_report_meminfo(struct seq_file *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034int hugetlb_report_node_meminfo(int, char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035unsigned long hugetlb_total_pages(void);
Hugh Dickinsac9b9c62005-10-20 16:24:28 +010036int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
Hugh Dickins788c7df2009-06-23 13:49:05 +010037 unsigned long address, unsigned int flags);
Mel Gormana1e78772008-07-23 21:27:23 -070038int hugetlb_reserve_pages(struct inode *inode, long from, long to,
Mel Gorman5a6fe122009-02-10 14:02:27 +000039 struct vm_area_struct *vma,
40 int acctflags);
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -070041void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Mel Gorman396faf02007-07-17 04:03:13 -070043extern unsigned long hugepages_treat_as_movable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044extern const unsigned long hugetlb_zero, hugetlb_infinity;
45extern int sysctl_hugetlb_shm_group;
Jon Tollefson53ba51d2008-07-23 21:27:52 -070046extern struct list_head huge_boot_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
David Gibson63551ae2005-06-21 17:14:44 -070048/* arch callbacks */
49
Andi Kleena5516432008-07-23 21:27:41 -070050pte_t *huge_pte_alloc(struct mm_struct *mm,
51 unsigned long addr, unsigned long sz);
David Gibson63551ae2005-06-21 17:14:44 -070052pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr);
Chen, Kenneth W39dde652006-12-06 20:32:03 -080053int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep);
David Gibson63551ae2005-06-21 17:14:44 -070054struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
55 int write);
56struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
57 pmd_t *pmd, int write);
Andi Kleenceb86872008-07-23 21:27:50 -070058struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
59 pud_t *pud, int write);
David Gibson63551ae2005-06-21 17:14:44 -070060int pmd_huge(pmd_t pmd);
Andi Kleenceb86872008-07-23 21:27:50 -070061int pud_huge(pud_t pmd);
Zhang, Yanmin8f860592006-03-22 00:08:50 -080062void hugetlb_change_protection(struct vm_area_struct *vma,
63 unsigned long address, unsigned long end, pgprot_t newprot);
David Gibson63551ae2005-06-21 17:14:44 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#else /* !CONFIG_HUGETLB_PAGE */
66
Wu Fengguang20a03072009-06-16 15:32:22 -070067static inline int PageHuge(struct page *page)
68{
69 return 0;
70}
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
73{
74 return 0;
75}
Mel Gormana1e78772008-07-23 21:27:23 -070076
77static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
78{
79}
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static inline unsigned long hugetlb_total_pages(void)
82{
83 return 0;
84}
85
Adam Litke5b23dbe2007-11-14 16:59:33 -080086#define follow_hugetlb_page(m,v,p,vs,a,b,i,w) ({ BUG(); 0; })
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define follow_huge_addr(mm, addr, write) ERR_PTR(-EINVAL)
88#define copy_hugetlb_page_range(src, dst, vma) ({ BUG(); 0; })
89#define hugetlb_prefault(mapping, vma) ({ BUG(); 0; })
Mel Gorman04f2cbe2008-07-23 21:27:25 -070090#define unmap_hugepage_range(vma, start, end, page) BUG()
Alexey Dobriyane1759c22008-10-15 23:50:22 +040091static inline void hugetlb_report_meminfo(struct seq_file *m)
92{
93}
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define hugetlb_report_node_meminfo(n, buf) 0
95#define follow_huge_pmd(mm, addr, pmd, write) NULL
Andi Kleenceb86872008-07-23 21:27:50 -070096#define follow_huge_pud(mm, addr, pud, write) NULL
Andi Kleena5516432008-07-23 21:27:41 -070097#define prepare_hugepage_range(file, addr, len) (-EINVAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define pmd_huge(x) 0
Andi Kleenceb86872008-07-23 21:27:50 -070099#define pud_huge(x) 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define is_hugepage_only_range(mm, addr, len) 0
David Gibson9da61ae2006-03-22 00:08:57 -0800101#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; })
Hugh Dickins788c7df2009-06-23 13:49:05 +0100102#define hugetlb_fault(mm, vma, addr, flags) ({ BUG(); 0; })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Zhang, Yanmin8f860592006-03-22 00:08:50 -0800104#define hugetlb_change_protection(vma, address, end, newprot)
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#ifndef HPAGE_MASK
Robin Holt51c6f662005-11-13 16:06:42 -0800107#define HPAGE_MASK PAGE_MASK /* Keep the compiler happy */
108#define HPAGE_SIZE PAGE_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#endif
110
111#endif /* !CONFIG_HUGETLB_PAGE */
112
113#ifdef CONFIG_HUGETLBFS
114struct hugetlbfs_config {
115 uid_t uid;
116 gid_t gid;
117 umode_t mode;
118 long nr_blocks;
119 long nr_inodes;
Andi Kleena137e1c2008-07-23 21:27:43 -0700120 struct hstate *hstate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
123struct hugetlbfs_sb_info {
124 long max_blocks; /* blocks allowed */
125 long free_blocks; /* blocks free */
126 long max_inodes; /* inodes allowed */
127 long free_inodes; /* inodes free */
128 spinlock_t stat_lock;
Andi Kleena137e1c2008-07-23 21:27:43 -0700129 struct hstate *hstate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130};
131
132
133struct hugetlbfs_inode_info {
134 struct shared_policy policy;
135 struct inode vfs_inode;
136};
137
138static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
139{
140 return container_of(inode, struct hugetlbfs_inode_info, vfs_inode);
141}
142
143static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
144{
145 return sb->s_fs_info;
146}
147
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800148extern const struct file_operations hugetlbfs_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149extern struct vm_operations_struct hugetlb_vm_ops;
Hugh Dickins353d5c32009-08-24 16:30:28 +0100150struct file *hugetlb_file_setup(const char *name, size_t size, int acct,
151 struct user_struct **user);
Adam Litke9a119c02007-11-14 16:59:41 -0800152int hugetlb_get_quota(struct address_space *mapping, long delta);
153void hugetlb_put_quota(struct address_space *mapping, long delta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155static inline int is_file_hugepages(struct file *file)
156{
Adam Litke516dffd2007-03-01 15:46:08 -0800157 if (file->f_op == &hugetlbfs_file_operations)
158 return 1;
159 if (is_file_shm_hugepages(file))
160 return 1;
161
162 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline void set_file_hugepages(struct file *file)
166{
167 file->f_op = &hugetlbfs_file_operations;
168}
169#else /* !CONFIG_HUGETLBFS */
170
Stefan Richter1db85082009-02-10 23:27:32 +0100171#define is_file_hugepages(file) 0
172#define set_file_hugepages(file) BUG()
Hugh Dickins353d5c32009-08-24 16:30:28 +0100173#define hugetlb_file_setup(name,size,acct,user) ERR_PTR(-ENOSYS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175#endif /* !CONFIG_HUGETLBFS */
176
Adrian Bunkd2ba27e82007-05-06 14:49:00 -0700177#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
178unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
179 unsigned long len, unsigned long pgoff,
180 unsigned long flags);
181#endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
182
Andi Kleena5516432008-07-23 21:27:41 -0700183#ifdef CONFIG_HUGETLB_PAGE
184
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700185#define HSTATE_NAME_LEN 32
Andi Kleena5516432008-07-23 21:27:41 -0700186/* Defines one hugetlb page size */
187struct hstate {
Lee Schermerhorne8c5c822009-09-21 17:01:22 -0700188 int next_nid_to_alloc;
189 int next_nid_to_free;
Andi Kleena5516432008-07-23 21:27:41 -0700190 unsigned int order;
191 unsigned long mask;
192 unsigned long max_huge_pages;
193 unsigned long nr_huge_pages;
194 unsigned long free_huge_pages;
195 unsigned long resv_huge_pages;
196 unsigned long surplus_huge_pages;
197 unsigned long nr_overcommit_huge_pages;
198 struct list_head hugepage_freelists[MAX_NUMNODES];
199 unsigned int nr_huge_pages_node[MAX_NUMNODES];
200 unsigned int free_huge_pages_node[MAX_NUMNODES];
201 unsigned int surplus_huge_pages_node[MAX_NUMNODES];
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700202 char name[HSTATE_NAME_LEN];
Andi Kleena5516432008-07-23 21:27:41 -0700203};
204
Jon Tollefson53ba51d2008-07-23 21:27:52 -0700205struct huge_bootmem_page {
206 struct list_head list;
207 struct hstate *hstate;
208};
209
210/* arch callback */
211int __init alloc_bootmem_huge_page(struct hstate *h);
212
Andi Kleene5ff2152008-07-23 21:27:42 -0700213void __init hugetlb_add_hstate(unsigned order);
214struct hstate *size_to_hstate(unsigned long size);
215
216#ifndef HUGE_MAX_HSTATE
217#define HUGE_MAX_HSTATE 1
218#endif
219
220extern struct hstate hstates[HUGE_MAX_HSTATE];
221extern unsigned int default_hstate_idx;
222
223#define default_hstate (hstates[default_hstate_idx])
Andi Kleena5516432008-07-23 21:27:41 -0700224
Andi Kleena137e1c2008-07-23 21:27:43 -0700225static inline struct hstate *hstate_inode(struct inode *i)
Andi Kleena5516432008-07-23 21:27:41 -0700226{
Andi Kleena137e1c2008-07-23 21:27:43 -0700227 struct hugetlbfs_sb_info *hsb;
228 hsb = HUGETLBFS_SB(i->i_sb);
229 return hsb->hstate;
Andi Kleena5516432008-07-23 21:27:41 -0700230}
231
232static inline struct hstate *hstate_file(struct file *f)
233{
Andi Kleena137e1c2008-07-23 21:27:43 -0700234 return hstate_inode(f->f_dentry->d_inode);
Andi Kleena5516432008-07-23 21:27:41 -0700235}
236
Andi Kleena137e1c2008-07-23 21:27:43 -0700237static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
Andi Kleena5516432008-07-23 21:27:41 -0700238{
Andi Kleena137e1c2008-07-23 21:27:43 -0700239 return hstate_file(vma->vm_file);
Andi Kleena5516432008-07-23 21:27:41 -0700240}
241
242static inline unsigned long huge_page_size(struct hstate *h)
243{
244 return (unsigned long)PAGE_SIZE << h->order;
245}
246
Mel Gorman08fba692009-01-06 14:38:53 -0800247extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
248
Mel Gorman33402892009-01-06 14:38:54 -0800249extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
250
Andi Kleena5516432008-07-23 21:27:41 -0700251static inline unsigned long huge_page_mask(struct hstate *h)
252{
253 return h->mask;
254}
255
256static inline unsigned int huge_page_order(struct hstate *h)
257{
258 return h->order;
259}
260
261static inline unsigned huge_page_shift(struct hstate *h)
262{
263 return h->order + PAGE_SHIFT;
264}
265
266static inline unsigned int pages_per_huge_page(struct hstate *h)
267{
268 return 1 << h->order;
269}
270
271static inline unsigned int blocks_per_huge_page(struct hstate *h)
272{
273 return huge_page_size(h) / 512;
274}
275
276#include <asm/hugetlb.h>
277
Andi Kleene5ff2152008-07-23 21:27:42 -0700278static inline struct hstate *page_hstate(struct page *page)
279{
280 return size_to_hstate(PAGE_SIZE << compound_order(page));
281}
282
Andi Kleena5516432008-07-23 21:27:41 -0700283#else
284struct hstate {};
Jon Tollefson53ba51d2008-07-23 21:27:52 -0700285#define alloc_bootmem_huge_page(h) NULL
Andi Kleena5516432008-07-23 21:27:41 -0700286#define hstate_file(f) NULL
287#define hstate_vma(v) NULL
288#define hstate_inode(i) NULL
289#define huge_page_size(h) PAGE_SIZE
290#define huge_page_mask(h) PAGE_MASK
Mel Gorman08fba692009-01-06 14:38:53 -0800291#define vma_kernel_pagesize(v) PAGE_SIZE
Mel Gorman33402892009-01-06 14:38:54 -0800292#define vma_mmu_pagesize(v) PAGE_SIZE
Andi Kleena5516432008-07-23 21:27:41 -0700293#define huge_page_order(h) 0
294#define huge_page_shift(h) PAGE_SHIFT
Andrea Righi510a35d2008-07-26 15:22:27 -0700295static inline unsigned int pages_per_huge_page(struct hstate *h)
296{
297 return 1;
298}
Andi Kleena5516432008-07-23 21:27:41 -0700299#endif
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#endif /* _LINUX_HUGETLB_H */