blob: 0af500db3632e809956b4acc8f8580724efa628d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic hugetlb support.
3 * (C) William Irwin, April 2004
4 */
5#include <linux/gfp.h>
6#include <linux/list.h>
7#include <linux/init.h>
8#include <linux/module.h>
9#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/sysctl.h>
11#include <linux/highmem.h>
12#include <linux/nodemask.h>
David Gibson63551ae2005-06-21 17:14:44 -070013#include <linux/pagemap.h>
Christoph Lameter5da7ca82006-01-06 00:10:46 -080014#include <linux/mempolicy.h>
Christoph Lameteraea47ff2006-01-08 01:00:57 -080015#include <linux/cpuset.h>
David Gibson3935baa2006-03-22 00:08:53 -080016#include <linux/mutex.h>
Christoph Lameter5da7ca82006-01-06 00:10:46 -080017
David Gibson63551ae2005-06-21 17:14:44 -070018#include <asm/page.h>
19#include <asm/pgtable.h>
20
21#include <linux/hugetlb.h>
Nick Piggin7835e982006-03-22 00:08:40 -080022#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -070025static unsigned long nr_huge_pages, free_huge_pages, resv_huge_pages;
Adam Litke7893d1d2007-10-16 01:26:18 -070026static unsigned long surplus_huge_pages;
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -080027static unsigned long nr_overcommit_huge_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028unsigned long max_huge_pages;
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -080029unsigned long sysctl_overcommit_huge_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static struct list_head hugepage_freelists[MAX_NUMNODES];
31static unsigned int nr_huge_pages_node[MAX_NUMNODES];
32static unsigned int free_huge_pages_node[MAX_NUMNODES];
Adam Litke7893d1d2007-10-16 01:26:18 -070033static unsigned int surplus_huge_pages_node[MAX_NUMNODES];
Mel Gorman396faf02007-07-17 04:03:13 -070034static gfp_t htlb_alloc_mask = GFP_HIGHUSER;
35unsigned long hugepages_treat_as_movable;
Nishanth Aravamudan63b46132007-10-16 01:26:24 -070036static int hugetlb_next_nid;
Mel Gorman396faf02007-07-17 04:03:13 -070037
David Gibson3935baa2006-03-22 00:08:53 -080038/*
39 * Protects updates to hugepage_freelists, nr_huge_pages, and free_huge_pages
40 */
41static DEFINE_SPINLOCK(hugetlb_lock);
Eric Paris0bd0f9f2005-11-21 21:32:28 -080042
Mel Gormana1e78772008-07-23 21:27:23 -070043/*
44 * These helpers are used to track how many pages are reserved for
45 * faults in a MAP_PRIVATE mapping. Only the process that called mmap()
46 * is guaranteed to have their future faults succeed.
47 *
48 * With the exception of reset_vma_resv_huge_pages() which is called at fork(),
49 * the reserve counters are updated with the hugetlb_lock held. It is safe
50 * to reset the VMA at fork() time as it is not in use yet and there is no
51 * chance of the global counters getting corrupted as a result of the values.
52 */
53static unsigned long vma_resv_huge_pages(struct vm_area_struct *vma)
54{
55 VM_BUG_ON(!is_vm_hugetlb_page(vma));
56 if (!(vma->vm_flags & VM_SHARED))
57 return (unsigned long)vma->vm_private_data;
58 return 0;
59}
60
61static void set_vma_resv_huge_pages(struct vm_area_struct *vma,
62 unsigned long reserve)
63{
64 VM_BUG_ON(!is_vm_hugetlb_page(vma));
65 VM_BUG_ON(vma->vm_flags & VM_SHARED);
66
67 vma->vm_private_data = (void *)reserve;
68}
69
70/* Decrement the reserved pages in the hugepage pool by one */
71static void decrement_hugepage_resv_vma(struct vm_area_struct *vma)
72{
73 if (vma->vm_flags & VM_SHARED) {
74 /* Shared mappings always use reserves */
75 resv_huge_pages--;
76 } else {
77 /*
78 * Only the process that called mmap() has reserves for
79 * private mappings.
80 */
81 if (vma_resv_huge_pages(vma)) {
82 resv_huge_pages--;
83 reserve = (unsigned long)vma->vm_private_data - 1;
84 vma->vm_private_data = (void *)reserve;
85 }
86 }
87}
88
89void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
90{
91 VM_BUG_ON(!is_vm_hugetlb_page(vma));
92 if (!(vma->vm_flags & VM_SHARED))
93 vma->vm_private_data = (void *)0;
94}
95
96/* Returns true if the VMA has associated reserve pages */
97static int vma_has_private_reserves(struct vm_area_struct *vma)
98{
99 if (vma->vm_flags & VM_SHARED)
100 return 0;
101 if (!vma_resv_huge_pages(vma))
102 return 0;
103 return 1;
104}
105
David Gibson79ac6ba2006-03-22 00:08:51 -0800106static void clear_huge_page(struct page *page, unsigned long addr)
107{
108 int i;
109
110 might_sleep();
111 for (i = 0; i < (HPAGE_SIZE/PAGE_SIZE); i++) {
112 cond_resched();
Ralf Baechle281e0e32007-10-01 01:20:10 -0700113 clear_user_highpage(page + i, addr + i * PAGE_SIZE);
David Gibson79ac6ba2006-03-22 00:08:51 -0800114 }
115}
116
117static void copy_huge_page(struct page *dst, struct page *src,
Atsushi Nemoto9de455b2006-12-12 17:14:55 +0000118 unsigned long addr, struct vm_area_struct *vma)
David Gibson79ac6ba2006-03-22 00:08:51 -0800119{
120 int i;
121
122 might_sleep();
123 for (i = 0; i < HPAGE_SIZE/PAGE_SIZE; i++) {
124 cond_resched();
Atsushi Nemoto9de455b2006-12-12 17:14:55 +0000125 copy_user_highpage(dst + i, src + i, addr + i*PAGE_SIZE, vma);
David Gibson79ac6ba2006-03-22 00:08:51 -0800126 }
127}
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129static void enqueue_huge_page(struct page *page)
130{
131 int nid = page_to_nid(page);
132 list_add(&page->lru, &hugepage_freelists[nid]);
133 free_huge_pages++;
134 free_huge_pages_node[nid]++;
135}
136
Nishanth Aravamudan348e1e02008-03-04 14:29:42 -0800137static struct page *dequeue_huge_page(void)
138{
139 int nid;
140 struct page *page = NULL;
141
142 for (nid = 0; nid < MAX_NUMNODES; ++nid) {
143 if (!list_empty(&hugepage_freelists[nid])) {
144 page = list_entry(hugepage_freelists[nid].next,
145 struct page, lru);
146 list_del(&page->lru);
147 free_huge_pages--;
148 free_huge_pages_node[nid]--;
149 break;
150 }
151 }
152 return page;
153}
154
155static struct page *dequeue_huge_page_vma(struct vm_area_struct *vma,
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800156 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Nishanth Aravamudan31a5c6e2007-07-15 23:38:02 -0700158 int nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 struct page *page = NULL;
Lee Schermerhorn480eccf2007-09-18 22:46:47 -0700160 struct mempolicy *mpol;
Mel Gorman19770b32008-04-28 02:12:18 -0700161 nodemask_t *nodemask;
Mel Gorman396faf02007-07-17 04:03:13 -0700162 struct zonelist *zonelist = huge_zonelist(vma, address,
Mel Gorman19770b32008-04-28 02:12:18 -0700163 htlb_alloc_mask, &mpol, &nodemask);
Mel Gormandd1a2392008-04-28 02:12:17 -0700164 struct zone *zone;
165 struct zoneref *z;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Mel Gormana1e78772008-07-23 21:27:23 -0700167 /*
168 * A child process with MAP_PRIVATE mappings created by their parent
169 * have no page reserves. This check ensures that reservations are
170 * not "stolen". The child may still get SIGKILLed
171 */
172 if (!vma_has_private_reserves(vma) &&
173 free_huge_pages - resv_huge_pages == 0)
174 return NULL;
175
Mel Gorman19770b32008-04-28 02:12:18 -0700176 for_each_zone_zonelist_nodemask(zone, z, zonelist,
177 MAX_NR_ZONES - 1, nodemask) {
Mel Gorman54a6eb52008-04-28 02:12:16 -0700178 nid = zone_to_nid(zone);
179 if (cpuset_zone_allowed_softwall(zone, htlb_alloc_mask) &&
Andrew Morton3abf7af2007-07-19 01:49:08 -0700180 !list_empty(&hugepage_freelists[nid])) {
181 page = list_entry(hugepage_freelists[nid].next,
182 struct page, lru);
183 list_del(&page->lru);
184 free_huge_pages--;
185 free_huge_pages_node[nid]--;
Mel Gormana1e78772008-07-23 21:27:23 -0700186 decrement_hugepage_resv_vma(vma);
187
Ken Chen5ab3ee72007-07-23 18:44:00 -0700188 break;
Andrew Morton3abf7af2007-07-19 01:49:08 -0700189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
Lee Schermerhorn52cd3b02008-04-28 02:13:16 -0700191 mpol_cond_put(mpol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return page;
193}
194
Adam Litke6af2acb2007-10-16 01:26:16 -0700195static void update_and_free_page(struct page *page)
196{
197 int i;
198 nr_huge_pages--;
199 nr_huge_pages_node[page_to_nid(page)]--;
200 for (i = 0; i < (HPAGE_SIZE / PAGE_SIZE); i++) {
201 page[i].flags &= ~(1 << PG_locked | 1 << PG_error | 1 << PG_referenced |
202 1 << PG_dirty | 1 << PG_active | 1 << PG_reserved |
203 1 << PG_private | 1<< PG_writeback);
204 }
205 set_compound_page_dtor(page, NULL);
206 set_page_refcounted(page);
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700207 arch_release_hugepage(page);
Adam Litke6af2acb2007-10-16 01:26:16 -0700208 __free_pages(page, HUGETLB_PAGE_ORDER);
209}
210
David Gibson27a85ef2006-03-22 00:08:56 -0800211static void free_huge_page(struct page *page)
212{
Adam Litke7893d1d2007-10-16 01:26:18 -0700213 int nid = page_to_nid(page);
Adam Litkec79fb752007-11-14 16:59:38 -0800214 struct address_space *mapping;
David Gibson27a85ef2006-03-22 00:08:56 -0800215
Adam Litkec79fb752007-11-14 16:59:38 -0800216 mapping = (struct address_space *) page_private(page);
Andy Whitcrofte5df70a2008-02-23 15:23:32 -0800217 set_page_private(page, 0);
Adam Litke7893d1d2007-10-16 01:26:18 -0700218 BUG_ON(page_count(page));
David Gibson27a85ef2006-03-22 00:08:56 -0800219 INIT_LIST_HEAD(&page->lru);
220
221 spin_lock(&hugetlb_lock);
Adam Litke7893d1d2007-10-16 01:26:18 -0700222 if (surplus_huge_pages_node[nid]) {
223 update_and_free_page(page);
224 surplus_huge_pages--;
225 surplus_huge_pages_node[nid]--;
226 } else {
227 enqueue_huge_page(page);
228 }
David Gibson27a85ef2006-03-22 00:08:56 -0800229 spin_unlock(&hugetlb_lock);
Adam Litkec79fb752007-11-14 16:59:38 -0800230 if (mapping)
Adam Litke9a119c02007-11-14 16:59:41 -0800231 hugetlb_put_quota(mapping, 1);
David Gibson27a85ef2006-03-22 00:08:56 -0800232}
233
Adam Litke7893d1d2007-10-16 01:26:18 -0700234/*
235 * Increment or decrement surplus_huge_pages. Keep node-specific counters
236 * balanced by operating on them in a round-robin fashion.
237 * Returns 1 if an adjustment was made.
238 */
239static int adjust_pool_surplus(int delta)
240{
241 static int prev_nid;
242 int nid = prev_nid;
243 int ret = 0;
244
245 VM_BUG_ON(delta != -1 && delta != 1);
246 do {
247 nid = next_node(nid, node_online_map);
248 if (nid == MAX_NUMNODES)
249 nid = first_node(node_online_map);
250
251 /* To shrink on this node, there must be a surplus page */
252 if (delta < 0 && !surplus_huge_pages_node[nid])
253 continue;
254 /* Surplus cannot exceed the total number of pages */
255 if (delta > 0 && surplus_huge_pages_node[nid] >=
256 nr_huge_pages_node[nid])
257 continue;
258
259 surplus_huge_pages += delta;
260 surplus_huge_pages_node[nid] += delta;
261 ret = 1;
262 break;
263 } while (nid != prev_nid);
264
265 prev_nid = nid;
266 return ret;
267}
268
Nishanth Aravamudan63b46132007-10-16 01:26:24 -0700269static struct page *alloc_fresh_huge_page_node(int nid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 struct page *page;
Joe Jinf96efd52007-07-15 23:38:12 -0700272
Nishanth Aravamudan63b46132007-10-16 01:26:24 -0700273 page = alloc_pages_node(nid,
Nishanth Aravamudan551883a2008-04-29 00:58:26 -0700274 htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|
275 __GFP_REPEAT|__GFP_NOWARN,
Nishanth Aravamudan63b46132007-10-16 01:26:24 -0700276 HUGETLB_PAGE_ORDER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (page) {
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700278 if (arch_prepare_hugepage(page)) {
279 __free_pages(page, HUGETLB_PAGE_ORDER);
Harvey Harrison7b8ee842008-04-28 14:13:19 -0700280 return NULL;
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700281 }
Andy Whitcroft33f2ef82006-12-06 20:33:32 -0800282 set_compound_page_dtor(page, free_huge_page);
Eric Paris0bd0f9f2005-11-21 21:32:28 -0800283 spin_lock(&hugetlb_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 nr_huge_pages++;
Nishanth Aravamudan63b46132007-10-16 01:26:24 -0700285 nr_huge_pages_node[nid]++;
Eric Paris0bd0f9f2005-11-21 21:32:28 -0800286 spin_unlock(&hugetlb_lock);
Nick Piggina4822892006-03-22 00:08:08 -0800287 put_page(page); /* free it into the hugepage allocator */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
Nishanth Aravamudan63b46132007-10-16 01:26:24 -0700289
290 return page;
291}
292
293static int alloc_fresh_huge_page(void)
294{
295 struct page *page;
296 int start_nid;
297 int next_nid;
298 int ret = 0;
299
300 start_nid = hugetlb_next_nid;
301
302 do {
303 page = alloc_fresh_huge_page_node(hugetlb_next_nid);
304 if (page)
305 ret = 1;
306 /*
307 * Use a helper variable to find the next node and then
308 * copy it back to hugetlb_next_nid afterwards:
309 * otherwise there's a window in which a racer might
310 * pass invalid nid MAX_NUMNODES to alloc_pages_node.
311 * But we don't need to use a spin_lock here: it really
312 * doesn't matter if occasionally a racer chooses the
313 * same nid as we do. Move nid forward in the mask even
314 * if we just successfully allocated a hugepage so that
315 * the next caller gets hugepages on the next node.
316 */
317 next_nid = next_node(hugetlb_next_nid, node_online_map);
318 if (next_nid == MAX_NUMNODES)
319 next_nid = first_node(node_online_map);
320 hugetlb_next_nid = next_nid;
321 } while (!page && hugetlb_next_nid != start_nid);
322
Adam Litke3b116302008-04-28 02:13:06 -0700323 if (ret)
324 count_vm_event(HTLB_BUDDY_PGALLOC);
325 else
326 count_vm_event(HTLB_BUDDY_PGALLOC_FAIL);
327
Nishanth Aravamudan63b46132007-10-16 01:26:24 -0700328 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
Adam Litke7893d1d2007-10-16 01:26:18 -0700331static struct page *alloc_buddy_huge_page(struct vm_area_struct *vma,
332 unsigned long address)
333{
334 struct page *page;
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800335 unsigned int nid;
Adam Litke7893d1d2007-10-16 01:26:18 -0700336
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800337 /*
338 * Assume we will successfully allocate the surplus page to
339 * prevent racing processes from causing the surplus to exceed
340 * overcommit
341 *
342 * This however introduces a different race, where a process B
343 * tries to grow the static hugepage pool while alloc_pages() is
344 * called by process A. B will only examine the per-node
345 * counters in determining if surplus huge pages can be
346 * converted to normal huge pages in adjust_pool_surplus(). A
347 * won't be able to increment the per-node counter, until the
348 * lock is dropped by B, but B doesn't drop hugetlb_lock until
349 * no more huge pages can be converted from surplus to normal
350 * state (and doesn't try to convert again). Thus, we have a
351 * case where a surplus huge page exists, the pool is grown, and
352 * the surplus huge page still exists after, even though it
353 * should just have been converted to a normal huge page. This
354 * does not leak memory, though, as the hugepage will be freed
355 * once it is out of use. It also does not allow the counters to
356 * go out of whack in adjust_pool_surplus() as we don't modify
357 * the node values until we've gotten the hugepage and only the
358 * per-node value is checked there.
359 */
360 spin_lock(&hugetlb_lock);
361 if (surplus_huge_pages >= nr_overcommit_huge_pages) {
362 spin_unlock(&hugetlb_lock);
363 return NULL;
364 } else {
365 nr_huge_pages++;
366 surplus_huge_pages++;
367 }
368 spin_unlock(&hugetlb_lock);
369
Nishanth Aravamudan551883a2008-04-29 00:58:26 -0700370 page = alloc_pages(htlb_alloc_mask|__GFP_COMP|
371 __GFP_REPEAT|__GFP_NOWARN,
Adam Litke7893d1d2007-10-16 01:26:18 -0700372 HUGETLB_PAGE_ORDER);
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800373
374 spin_lock(&hugetlb_lock);
Adam Litke7893d1d2007-10-16 01:26:18 -0700375 if (page) {
Adam Litke2668db92008-03-10 11:43:50 -0700376 /*
377 * This page is now managed by the hugetlb allocator and has
378 * no users -- drop the buddy allocator's reference.
379 */
380 put_page_testzero(page);
381 VM_BUG_ON(page_count(page));
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800382 nid = page_to_nid(page);
Adam Litke7893d1d2007-10-16 01:26:18 -0700383 set_compound_page_dtor(page, free_huge_page);
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800384 /*
385 * We incremented the global counters already
386 */
387 nr_huge_pages_node[nid]++;
388 surplus_huge_pages_node[nid]++;
Adam Litke3b116302008-04-28 02:13:06 -0700389 __count_vm_event(HTLB_BUDDY_PGALLOC);
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800390 } else {
391 nr_huge_pages--;
392 surplus_huge_pages--;
Adam Litke3b116302008-04-28 02:13:06 -0700393 __count_vm_event(HTLB_BUDDY_PGALLOC_FAIL);
Adam Litke7893d1d2007-10-16 01:26:18 -0700394 }
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800395 spin_unlock(&hugetlb_lock);
Adam Litke7893d1d2007-10-16 01:26:18 -0700396
397 return page;
398}
399
Adam Litkee4e574b2007-10-16 01:26:19 -0700400/*
401 * Increase the hugetlb pool such that it can accomodate a reservation
402 * of size 'delta'.
403 */
404static int gather_surplus_pages(int delta)
405{
406 struct list_head surplus_list;
407 struct page *page, *tmp;
408 int ret, i;
409 int needed, allocated;
410
411 needed = (resv_huge_pages + delta) - free_huge_pages;
Adam Litkeac09b3a2008-03-04 14:29:38 -0800412 if (needed <= 0) {
413 resv_huge_pages += delta;
Adam Litkee4e574b2007-10-16 01:26:19 -0700414 return 0;
Adam Litkeac09b3a2008-03-04 14:29:38 -0800415 }
Adam Litkee4e574b2007-10-16 01:26:19 -0700416
417 allocated = 0;
418 INIT_LIST_HEAD(&surplus_list);
419
420 ret = -ENOMEM;
421retry:
422 spin_unlock(&hugetlb_lock);
423 for (i = 0; i < needed; i++) {
424 page = alloc_buddy_huge_page(NULL, 0);
425 if (!page) {
426 /*
427 * We were not able to allocate enough pages to
428 * satisfy the entire reservation so we free what
429 * we've allocated so far.
430 */
431 spin_lock(&hugetlb_lock);
432 needed = 0;
433 goto free;
434 }
435
436 list_add(&page->lru, &surplus_list);
437 }
438 allocated += needed;
439
440 /*
441 * After retaking hugetlb_lock, we need to recalculate 'needed'
442 * because either resv_huge_pages or free_huge_pages may have changed.
443 */
444 spin_lock(&hugetlb_lock);
445 needed = (resv_huge_pages + delta) - (free_huge_pages + allocated);
446 if (needed > 0)
447 goto retry;
448
449 /*
450 * The surplus_list now contains _at_least_ the number of extra pages
451 * needed to accomodate the reservation. Add the appropriate number
452 * of pages to the hugetlb pool and free the extras back to the buddy
Adam Litkeac09b3a2008-03-04 14:29:38 -0800453 * allocator. Commit the entire reservation here to prevent another
454 * process from stealing the pages as they are added to the pool but
455 * before they are reserved.
Adam Litkee4e574b2007-10-16 01:26:19 -0700456 */
457 needed += allocated;
Adam Litkeac09b3a2008-03-04 14:29:38 -0800458 resv_huge_pages += delta;
Adam Litkee4e574b2007-10-16 01:26:19 -0700459 ret = 0;
460free:
Adam Litke19fc3f02008-04-28 02:12:20 -0700461 /* Free the needed pages to the hugetlb pool */
Adam Litkee4e574b2007-10-16 01:26:19 -0700462 list_for_each_entry_safe(page, tmp, &surplus_list, lru) {
Adam Litke19fc3f02008-04-28 02:12:20 -0700463 if ((--needed) < 0)
464 break;
Adam Litkee4e574b2007-10-16 01:26:19 -0700465 list_del(&page->lru);
Adam Litke19fc3f02008-04-28 02:12:20 -0700466 enqueue_huge_page(page);
467 }
468
469 /* Free unnecessary surplus pages to the buddy allocator */
470 if (!list_empty(&surplus_list)) {
471 spin_unlock(&hugetlb_lock);
472 list_for_each_entry_safe(page, tmp, &surplus_list, lru) {
473 list_del(&page->lru);
Adam Litkeaf767cb2007-10-16 01:26:25 -0700474 /*
Adam Litke2668db92008-03-10 11:43:50 -0700475 * The page has a reference count of zero already, so
476 * call free_huge_page directly instead of using
477 * put_page. This must be done with hugetlb_lock
Adam Litkeaf767cb2007-10-16 01:26:25 -0700478 * unlocked which is safe because free_huge_page takes
479 * hugetlb_lock before deciding how to free the page.
480 */
Adam Litke2668db92008-03-10 11:43:50 -0700481 free_huge_page(page);
Adam Litkeaf767cb2007-10-16 01:26:25 -0700482 }
Adam Litke19fc3f02008-04-28 02:12:20 -0700483 spin_lock(&hugetlb_lock);
Adam Litkee4e574b2007-10-16 01:26:19 -0700484 }
485
486 return ret;
487}
488
489/*
490 * When releasing a hugetlb pool reservation, any surplus pages that were
491 * allocated to satisfy the reservation must be explicitly freed if they were
492 * never used.
493 */
Adrian Bunk8cde0452007-11-14 16:59:43 -0800494static void return_unused_surplus_pages(unsigned long unused_resv_pages)
Adam Litkee4e574b2007-10-16 01:26:19 -0700495{
496 static int nid = -1;
497 struct page *page;
498 unsigned long nr_pages;
499
Nishanth Aravamudan11320d12008-03-26 14:40:20 -0700500 /*
501 * We want to release as many surplus pages as possible, spread
502 * evenly across all nodes. Iterate across all nodes until we
503 * can no longer free unreserved surplus pages. This occurs when
504 * the nodes with surplus pages have no free pages.
505 */
506 unsigned long remaining_iterations = num_online_nodes();
507
Adam Litkeac09b3a2008-03-04 14:29:38 -0800508 /* Uncommit the reservation */
509 resv_huge_pages -= unused_resv_pages;
510
Adam Litkee4e574b2007-10-16 01:26:19 -0700511 nr_pages = min(unused_resv_pages, surplus_huge_pages);
512
Nishanth Aravamudan11320d12008-03-26 14:40:20 -0700513 while (remaining_iterations-- && nr_pages) {
Adam Litkee4e574b2007-10-16 01:26:19 -0700514 nid = next_node(nid, node_online_map);
515 if (nid == MAX_NUMNODES)
516 nid = first_node(node_online_map);
517
518 if (!surplus_huge_pages_node[nid])
519 continue;
520
521 if (!list_empty(&hugepage_freelists[nid])) {
522 page = list_entry(hugepage_freelists[nid].next,
523 struct page, lru);
524 list_del(&page->lru);
525 update_and_free_page(page);
526 free_huge_pages--;
527 free_huge_pages_node[nid]--;
528 surplus_huge_pages--;
529 surplus_huge_pages_node[nid]--;
530 nr_pages--;
Nishanth Aravamudan11320d12008-03-26 14:40:20 -0700531 remaining_iterations = num_online_nodes();
Adam Litkee4e574b2007-10-16 01:26:19 -0700532 }
533 }
534}
535
David Gibson27a85ef2006-03-22 00:08:56 -0800536static struct page *alloc_huge_page(struct vm_area_struct *vma,
537 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Adam Litke348ea202007-11-14 16:59:37 -0800539 struct page *page;
Adam Litke2fc39ce2007-11-14 16:59:39 -0800540 struct address_space *mapping = vma->vm_file->f_mapping;
Mel Gormana1e78772008-07-23 21:27:23 -0700541 struct inode *inode = mapping->host;
542 unsigned int chg = 0;
Adam Litke2fc39ce2007-11-14 16:59:39 -0800543
Mel Gormana1e78772008-07-23 21:27:23 -0700544 /*
545 * Processes that did not create the mapping will have no reserves and
546 * will not have accounted against quota. Check that the quota can be
547 * made before satisfying the allocation
548 */
549 if (!vma_has_private_reserves(vma)) {
550 chg = 1;
551 if (hugetlb_get_quota(inode->i_mapping, chg))
552 return ERR_PTR(-ENOSPC);
Adam Litke90d8b7e2007-11-14 16:59:42 -0800553 }
Mel Gormana1e78772008-07-23 21:27:23 -0700554
555 spin_lock(&hugetlb_lock);
556 page = dequeue_huge_page_vma(vma, addr);
557 spin_unlock(&hugetlb_lock);
558
559 if (!page) {
560 page = alloc_buddy_huge_page(vma, addr);
561 if (!page) {
562 hugetlb_put_quota(inode->i_mapping, chg);
563 return ERR_PTR(-VM_FAULT_OOM);
564 }
565 }
566
567 set_page_refcounted(page);
568 set_page_private(page, (unsigned long) mapping);
569
Adam Litke90d8b7e2007-11-14 16:59:42 -0800570 return page;
David Gibsonb45b5bd2006-03-22 00:08:55 -0800571}
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573static int __init hugetlb_init(void)
574{
575 unsigned long i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100577 if (HPAGE_SHIFT == 0)
578 return 0;
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 for (i = 0; i < MAX_NUMNODES; ++i)
581 INIT_LIST_HEAD(&hugepage_freelists[i]);
582
Nishanth Aravamudan63b46132007-10-16 01:26:24 -0700583 hugetlb_next_nid = first_node(node_online_map);
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 for (i = 0; i < max_huge_pages; ++i) {
Nick Piggina4822892006-03-22 00:08:08 -0800586 if (!alloc_fresh_huge_page())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589 max_huge_pages = free_huge_pages = nr_huge_pages = i;
590 printk("Total HugeTLB memory allocated, %ld\n", free_huge_pages);
591 return 0;
592}
593module_init(hugetlb_init);
594
595static int __init hugetlb_setup(char *s)
596{
597 if (sscanf(s, "%lu", &max_huge_pages) <= 0)
598 max_huge_pages = 0;
599 return 1;
600}
601__setup("hugepages=", hugetlb_setup);
602
Ken Chen8a630112007-05-09 02:33:34 -0700603static unsigned int cpuset_mems_nr(unsigned int *array)
604{
605 int node;
606 unsigned int nr = 0;
607
608 for_each_node_mask(node, cpuset_current_mems_allowed)
609 nr += array[node];
610
611 return nr;
612}
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#ifdef CONFIG_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#ifdef CONFIG_HIGHMEM
616static void try_to_free_low(unsigned long count)
617{
Christoph Lameter4415cc82006-09-25 23:31:55 -0700618 int i;
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 for (i = 0; i < MAX_NUMNODES; ++i) {
621 struct page *page, *next;
622 list_for_each_entry_safe(page, next, &hugepage_freelists[i], lru) {
Adam Litke6b0c8802007-10-16 01:26:23 -0700623 if (count >= nr_huge_pages)
624 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (PageHighMem(page))
626 continue;
627 list_del(&page->lru);
628 update_and_free_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 free_huge_pages--;
Christoph Lameter4415cc82006-09-25 23:31:55 -0700630 free_huge_pages_node[page_to_nid(page)]--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
632 }
633}
634#else
635static inline void try_to_free_low(unsigned long count)
636{
637}
638#endif
639
Adam Litke7893d1d2007-10-16 01:26:18 -0700640#define persistent_huge_pages (nr_huge_pages - surplus_huge_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641static unsigned long set_max_huge_pages(unsigned long count)
642{
Adam Litke7893d1d2007-10-16 01:26:18 -0700643 unsigned long min_count, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Adam Litke7893d1d2007-10-16 01:26:18 -0700645 /*
646 * Increase the pool size
647 * First take pages out of surplus state. Then make up the
648 * remaining difference by allocating fresh huge pages.
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800649 *
650 * We might race with alloc_buddy_huge_page() here and be unable
651 * to convert a surplus huge page to a normal huge page. That is
652 * not critical, though, it just means the overall size of the
653 * pool might be one hugepage larger than it needs to be, but
654 * within all the constraints specified by the sysctls.
Adam Litke7893d1d2007-10-16 01:26:18 -0700655 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 spin_lock(&hugetlb_lock);
Adam Litke7893d1d2007-10-16 01:26:18 -0700657 while (surplus_huge_pages && count > persistent_huge_pages) {
658 if (!adjust_pool_surplus(-1))
659 break;
660 }
661
662 while (count > persistent_huge_pages) {
Adam Litke7893d1d2007-10-16 01:26:18 -0700663 /*
664 * If this allocation races such that we no longer need the
665 * page, free_huge_page will handle it by freeing the page
666 * and reducing the surplus.
667 */
668 spin_unlock(&hugetlb_lock);
669 ret = alloc_fresh_huge_page();
670 spin_lock(&hugetlb_lock);
671 if (!ret)
672 goto out;
673
674 }
Adam Litke7893d1d2007-10-16 01:26:18 -0700675
676 /*
677 * Decrease the pool size
678 * First return free pages to the buddy allocator (being careful
679 * to keep enough around to satisfy reservations). Then place
680 * pages into surplus state as needed so the pool will shrink
681 * to the desired size as pages become free.
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800682 *
683 * By placing pages into the surplus state independent of the
684 * overcommit value, we are allowing the surplus pool size to
685 * exceed overcommit. There are few sane options here. Since
686 * alloc_buddy_huge_page() is checking the global counter,
687 * though, we'll note that we're not allowed to exceed surplus
688 * and won't grow the pool anywhere else. Not until one of the
689 * sysctls are changed, or the surplus pages go out of use.
Adam Litke7893d1d2007-10-16 01:26:18 -0700690 */
Adam Litke6b0c8802007-10-16 01:26:23 -0700691 min_count = resv_huge_pages + nr_huge_pages - free_huge_pages;
692 min_count = max(count, min_count);
Adam Litke7893d1d2007-10-16 01:26:18 -0700693 try_to_free_low(min_count);
694 while (min_count < persistent_huge_pages) {
Nishanth Aravamudan348e1e02008-03-04 14:29:42 -0800695 struct page *page = dequeue_huge_page();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (!page)
697 break;
698 update_and_free_page(page);
699 }
Adam Litke7893d1d2007-10-16 01:26:18 -0700700 while (count < persistent_huge_pages) {
701 if (!adjust_pool_surplus(1))
702 break;
703 }
704out:
705 ret = persistent_huge_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 spin_unlock(&hugetlb_lock);
Adam Litke7893d1d2007-10-16 01:26:18 -0700707 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
710int hugetlb_sysctl_handler(struct ctl_table *table, int write,
711 struct file *file, void __user *buffer,
712 size_t *length, loff_t *ppos)
713{
714 proc_doulongvec_minmax(table, write, file, buffer, length, ppos);
715 max_huge_pages = set_max_huge_pages(max_huge_pages);
716 return 0;
717}
Mel Gorman396faf02007-07-17 04:03:13 -0700718
719int hugetlb_treat_movable_handler(struct ctl_table *table, int write,
720 struct file *file, void __user *buffer,
721 size_t *length, loff_t *ppos)
722{
723 proc_dointvec(table, write, file, buffer, length, ppos);
724 if (hugepages_treat_as_movable)
725 htlb_alloc_mask = GFP_HIGHUSER_MOVABLE;
726 else
727 htlb_alloc_mask = GFP_HIGHUSER;
728 return 0;
729}
730
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800731int hugetlb_overcommit_handler(struct ctl_table *table, int write,
732 struct file *file, void __user *buffer,
733 size_t *length, loff_t *ppos)
734{
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800735 proc_doulongvec_minmax(table, write, file, buffer, length, ppos);
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -0800736 spin_lock(&hugetlb_lock);
737 nr_overcommit_huge_pages = sysctl_overcommit_huge_pages;
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800738 spin_unlock(&hugetlb_lock);
739 return 0;
740}
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742#endif /* CONFIG_SYSCTL */
743
744int hugetlb_report_meminfo(char *buf)
745{
746 return sprintf(buf,
747 "HugePages_Total: %5lu\n"
748 "HugePages_Free: %5lu\n"
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -0700749 "HugePages_Rsvd: %5lu\n"
Adam Litke7893d1d2007-10-16 01:26:18 -0700750 "HugePages_Surp: %5lu\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 "Hugepagesize: %5lu kB\n",
752 nr_huge_pages,
753 free_huge_pages,
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -0700754 resv_huge_pages,
Adam Litke7893d1d2007-10-16 01:26:18 -0700755 surplus_huge_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 HPAGE_SIZE/1024);
757}
758
759int hugetlb_report_node_meminfo(int nid, char *buf)
760{
761 return sprintf(buf,
762 "Node %d HugePages_Total: %5u\n"
Nishanth Aravamudana1de0912008-03-26 14:37:53 -0700763 "Node %d HugePages_Free: %5u\n"
764 "Node %d HugePages_Surp: %5u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 nid, nr_huge_pages_node[nid],
Nishanth Aravamudana1de0912008-03-26 14:37:53 -0700766 nid, free_huge_pages_node[nid],
767 nid, surplus_huge_pages_node[nid]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770/* Return the number pages of memory we physically have, in PAGE_SIZE units. */
771unsigned long hugetlb_total_pages(void)
772{
773 return nr_huge_pages * (HPAGE_SIZE / PAGE_SIZE);
774}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Mel Gormanfc1b8a72008-07-23 21:27:22 -0700776static int hugetlb_acct_memory(long delta)
777{
778 int ret = -ENOMEM;
779
780 spin_lock(&hugetlb_lock);
781 /*
782 * When cpuset is configured, it breaks the strict hugetlb page
783 * reservation as the accounting is done on a global variable. Such
784 * reservation is completely rubbish in the presence of cpuset because
785 * the reservation is not checked against page availability for the
786 * current cpuset. Application can still potentially OOM'ed by kernel
787 * with lack of free htlb page in cpuset that the task is in.
788 * Attempt to enforce strict accounting with cpuset is almost
789 * impossible (or too ugly) because cpuset is too fluid that
790 * task or memory node can be dynamically moved between cpusets.
791 *
792 * The change of semantics for shared hugetlb mapping with cpuset is
793 * undesirable. However, in order to preserve some of the semantics,
794 * we fall back to check against current free page availability as
795 * a best attempt and hopefully to minimize the impact of changing
796 * semantics that cpuset has.
797 */
798 if (delta > 0) {
799 if (gather_surplus_pages(delta) < 0)
800 goto out;
801
802 if (delta > cpuset_mems_nr(free_huge_pages_node)) {
803 return_unused_surplus_pages(delta);
804 goto out;
805 }
806 }
807
808 ret = 0;
809 if (delta < 0)
810 return_unused_surplus_pages((unsigned long) -delta);
811
812out:
813 spin_unlock(&hugetlb_lock);
814 return ret;
815}
816
Mel Gormana1e78772008-07-23 21:27:23 -0700817static void hugetlb_vm_op_close(struct vm_area_struct *vma)
818{
819 unsigned long reserve = vma_resv_huge_pages(vma);
820 if (reserve)
821 hugetlb_acct_memory(-reserve);
822}
823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824/*
825 * We cannot handle pagefaults against hugetlb pages at all. They cause
826 * handle_mm_fault() to try to instantiate regular-sized pages in the
827 * hugegpage VMA. do_page_fault() is supposed to trap this, so BUG is we get
828 * this far.
829 */
Nick Piggind0217ac2007-07-19 01:47:03 -0700830static int hugetlb_vm_op_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
832 BUG();
Nick Piggind0217ac2007-07-19 01:47:03 -0700833 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
836struct vm_operations_struct hugetlb_vm_ops = {
Nick Piggind0217ac2007-07-19 01:47:03 -0700837 .fault = hugetlb_vm_op_fault,
Mel Gormana1e78772008-07-23 21:27:23 -0700838 .close = hugetlb_vm_op_close,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839};
840
David Gibson1e8f8892006-01-06 00:10:44 -0800841static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page,
842 int writable)
David Gibson63551ae2005-06-21 17:14:44 -0700843{
844 pte_t entry;
845
David Gibson1e8f8892006-01-06 00:10:44 -0800846 if (writable) {
David Gibson63551ae2005-06-21 17:14:44 -0700847 entry =
848 pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
849 } else {
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700850 entry = huge_pte_wrprotect(mk_pte(page, vma->vm_page_prot));
David Gibson63551ae2005-06-21 17:14:44 -0700851 }
852 entry = pte_mkyoung(entry);
853 entry = pte_mkhuge(entry);
854
855 return entry;
856}
857
David Gibson1e8f8892006-01-06 00:10:44 -0800858static void set_huge_ptep_writable(struct vm_area_struct *vma,
859 unsigned long address, pte_t *ptep)
860{
861 pte_t entry;
862
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700863 entry = pte_mkwrite(pte_mkdirty(huge_ptep_get(ptep)));
864 if (huge_ptep_set_access_flags(vma, address, ptep, entry, 1)) {
Benjamin Herrenschmidt8dab5242007-06-16 10:16:12 -0700865 update_mmu_cache(vma, address, entry);
Benjamin Herrenschmidt8dab5242007-06-16 10:16:12 -0700866 }
David Gibson1e8f8892006-01-06 00:10:44 -0800867}
868
869
David Gibson63551ae2005-06-21 17:14:44 -0700870int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
871 struct vm_area_struct *vma)
872{
873 pte_t *src_pte, *dst_pte, entry;
874 struct page *ptepage;
Hugh Dickins1c598272005-10-19 21:23:43 -0700875 unsigned long addr;
David Gibson1e8f8892006-01-06 00:10:44 -0800876 int cow;
877
878 cow = (vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
David Gibson63551ae2005-06-21 17:14:44 -0700879
Hugh Dickins1c598272005-10-19 21:23:43 -0700880 for (addr = vma->vm_start; addr < vma->vm_end; addr += HPAGE_SIZE) {
Hugh Dickinsc74df322005-10-29 18:16:23 -0700881 src_pte = huge_pte_offset(src, addr);
882 if (!src_pte)
883 continue;
David Gibson63551ae2005-06-21 17:14:44 -0700884 dst_pte = huge_pte_alloc(dst, addr);
885 if (!dst_pte)
886 goto nomem;
Larry Woodmanc5c99422008-01-24 05:49:25 -0800887
888 /* If the pagetables are shared don't copy or take references */
889 if (dst_pte == src_pte)
890 continue;
891
Hugh Dickinsc74df322005-10-29 18:16:23 -0700892 spin_lock(&dst->page_table_lock);
Nick Piggin46478752008-06-05 22:45:57 -0700893 spin_lock_nested(&src->page_table_lock, SINGLE_DEPTH_NESTING);
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700894 if (!huge_pte_none(huge_ptep_get(src_pte))) {
David Gibson1e8f8892006-01-06 00:10:44 -0800895 if (cow)
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700896 huge_ptep_set_wrprotect(src, addr, src_pte);
897 entry = huge_ptep_get(src_pte);
Hugh Dickins1c598272005-10-19 21:23:43 -0700898 ptepage = pte_page(entry);
899 get_page(ptepage);
Hugh Dickins1c598272005-10-19 21:23:43 -0700900 set_huge_pte_at(dst, addr, dst_pte, entry);
901 }
902 spin_unlock(&src->page_table_lock);
Hugh Dickinsc74df322005-10-29 18:16:23 -0700903 spin_unlock(&dst->page_table_lock);
David Gibson63551ae2005-06-21 17:14:44 -0700904 }
905 return 0;
906
907nomem:
908 return -ENOMEM;
909}
910
Chen, Kenneth W502717f2006-10-11 01:20:46 -0700911void __unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
912 unsigned long end)
David Gibson63551ae2005-06-21 17:14:44 -0700913{
914 struct mm_struct *mm = vma->vm_mm;
915 unsigned long address;
David Gibsonc7546f82005-08-05 11:59:35 -0700916 pte_t *ptep;
David Gibson63551ae2005-06-21 17:14:44 -0700917 pte_t pte;
918 struct page *page;
Chen, Kenneth Wfe1668a2006-10-04 02:15:24 -0700919 struct page *tmp;
Chen, Kenneth Wc0a499c2006-12-06 20:31:39 -0800920 /*
921 * A page gathering list, protected by per file i_mmap_lock. The
922 * lock is used to avoid list corruption from multiple unmapping
923 * of the same page since we are using page->lru.
924 */
Chen, Kenneth Wfe1668a2006-10-04 02:15:24 -0700925 LIST_HEAD(page_list);
David Gibson63551ae2005-06-21 17:14:44 -0700926
927 WARN_ON(!is_vm_hugetlb_page(vma));
928 BUG_ON(start & ~HPAGE_MASK);
929 BUG_ON(end & ~HPAGE_MASK);
930
Hugh Dickins508034a2005-10-29 18:16:30 -0700931 spin_lock(&mm->page_table_lock);
David Gibson63551ae2005-06-21 17:14:44 -0700932 for (address = start; address < end; address += HPAGE_SIZE) {
David Gibsonc7546f82005-08-05 11:59:35 -0700933 ptep = huge_pte_offset(mm, address);
Adam Litke4c887262005-10-29 18:16:46 -0700934 if (!ptep)
David Gibsonc7546f82005-08-05 11:59:35 -0700935 continue;
936
Chen, Kenneth W39dde652006-12-06 20:32:03 -0800937 if (huge_pmd_unshare(mm, &address, ptep))
938 continue;
939
David Gibsonc7546f82005-08-05 11:59:35 -0700940 pte = huge_ptep_get_and_clear(mm, address, ptep);
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700941 if (huge_pte_none(pte))
David Gibson63551ae2005-06-21 17:14:44 -0700942 continue;
David Gibsonc7546f82005-08-05 11:59:35 -0700943
David Gibson63551ae2005-06-21 17:14:44 -0700944 page = pte_page(pte);
Ken Chen6649a382007-02-08 14:20:27 -0800945 if (pte_dirty(pte))
946 set_page_dirty(page);
Chen, Kenneth Wfe1668a2006-10-04 02:15:24 -0700947 list_add(&page->lru, &page_list);
David Gibson63551ae2005-06-21 17:14:44 -0700948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 spin_unlock(&mm->page_table_lock);
Hugh Dickins508034a2005-10-29 18:16:30 -0700950 flush_tlb_range(vma, start, end);
Chen, Kenneth Wfe1668a2006-10-04 02:15:24 -0700951 list_for_each_entry_safe(page, tmp, &page_list, lru) {
952 list_del(&page->lru);
953 put_page(page);
954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955}
David Gibson63551ae2005-06-21 17:14:44 -0700956
Chen, Kenneth W502717f2006-10-11 01:20:46 -0700957void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
958 unsigned long end)
959{
960 /*
961 * It is undesirable to test vma->vm_file as it should be non-null
962 * for valid hugetlb area. However, vm_file will be NULL in the error
963 * cleanup path of do_mmap_pgoff. When hugetlbfs ->mmap method fails,
964 * do_mmap_pgoff() nullifies vma->vm_file before calling this function
965 * to clean up. Since no pte has actually been setup, it is safe to
966 * do nothing in this case.
967 */
968 if (vma->vm_file) {
969 spin_lock(&vma->vm_file->f_mapping->i_mmap_lock);
970 __unmap_hugepage_range(vma, start, end);
971 spin_unlock(&vma->vm_file->f_mapping->i_mmap_lock);
972 }
973}
974
David Gibson1e8f8892006-01-06 00:10:44 -0800975static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
976 unsigned long address, pte_t *ptep, pte_t pte)
977{
978 struct page *old_page, *new_page;
David Gibson79ac6ba2006-03-22 00:08:51 -0800979 int avoidcopy;
David Gibson1e8f8892006-01-06 00:10:44 -0800980
981 old_page = pte_page(pte);
982
983 /* If no-one else is actually using this page, avoid the copy
984 * and just make the page writable */
985 avoidcopy = (page_count(old_page) == 1);
986 if (avoidcopy) {
987 set_huge_ptep_writable(vma, address, ptep);
Nick Piggin83c54072007-07-19 01:47:05 -0700988 return 0;
David Gibson1e8f8892006-01-06 00:10:44 -0800989 }
990
991 page_cache_get(old_page);
Christoph Lameter5da7ca82006-01-06 00:10:46 -0800992 new_page = alloc_huge_page(vma, address);
David Gibson1e8f8892006-01-06 00:10:44 -0800993
Adam Litke2fc39ce2007-11-14 16:59:39 -0800994 if (IS_ERR(new_page)) {
David Gibson1e8f8892006-01-06 00:10:44 -0800995 page_cache_release(old_page);
Adam Litke2fc39ce2007-11-14 16:59:39 -0800996 return -PTR_ERR(new_page);
David Gibson1e8f8892006-01-06 00:10:44 -0800997 }
998
999 spin_unlock(&mm->page_table_lock);
Atsushi Nemoto9de455b2006-12-12 17:14:55 +00001000 copy_huge_page(new_page, old_page, address, vma);
Nick Piggin0ed361d2008-02-04 22:29:34 -08001001 __SetPageUptodate(new_page);
David Gibson1e8f8892006-01-06 00:10:44 -08001002 spin_lock(&mm->page_table_lock);
1003
1004 ptep = huge_pte_offset(mm, address & HPAGE_MASK);
Gerald Schaefer7f2e9522008-04-28 02:13:29 -07001005 if (likely(pte_same(huge_ptep_get(ptep), pte))) {
David Gibson1e8f8892006-01-06 00:10:44 -08001006 /* Break COW */
Gerald Schaefer8fe627e2008-04-28 02:13:28 -07001007 huge_ptep_clear_flush(vma, address, ptep);
David Gibson1e8f8892006-01-06 00:10:44 -08001008 set_huge_pte_at(mm, address, ptep,
1009 make_huge_pte(vma, new_page, 1));
1010 /* Make the old page be freed below */
1011 new_page = old_page;
1012 }
1013 page_cache_release(new_page);
1014 page_cache_release(old_page);
Nick Piggin83c54072007-07-19 01:47:05 -07001015 return 0;
David Gibson1e8f8892006-01-06 00:10:44 -08001016}
1017
Robert P. J. Daya1ed3dd2007-07-17 04:03:33 -07001018static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
David Gibson1e8f8892006-01-06 00:10:44 -08001019 unsigned long address, pte_t *ptep, int write_access)
Hugh Dickinsac9b9c62005-10-20 16:24:28 +01001020{
1021 int ret = VM_FAULT_SIGBUS;
Adam Litke4c887262005-10-29 18:16:46 -07001022 unsigned long idx;
1023 unsigned long size;
Adam Litke4c887262005-10-29 18:16:46 -07001024 struct page *page;
1025 struct address_space *mapping;
David Gibson1e8f8892006-01-06 00:10:44 -08001026 pte_t new_pte;
Adam Litke4c887262005-10-29 18:16:46 -07001027
Adam Litke4c887262005-10-29 18:16:46 -07001028 mapping = vma->vm_file->f_mapping;
1029 idx = ((address - vma->vm_start) >> HPAGE_SHIFT)
1030 + (vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT));
1031
1032 /*
1033 * Use page lock to guard against racing truncation
1034 * before we get page_table_lock.
1035 */
Christoph Lameter6bda6662006-01-06 00:10:49 -08001036retry:
1037 page = find_lock_page(mapping, idx);
1038 if (!page) {
Hugh Dickinsebed4bf2006-10-28 10:38:43 -07001039 size = i_size_read(mapping->host) >> HPAGE_SHIFT;
1040 if (idx >= size)
1041 goto out;
Christoph Lameter6bda6662006-01-06 00:10:49 -08001042 page = alloc_huge_page(vma, address);
Adam Litke2fc39ce2007-11-14 16:59:39 -08001043 if (IS_ERR(page)) {
1044 ret = -PTR_ERR(page);
Christoph Lameter6bda6662006-01-06 00:10:49 -08001045 goto out;
1046 }
David Gibson79ac6ba2006-03-22 00:08:51 -08001047 clear_huge_page(page, address);
Nick Piggin0ed361d2008-02-04 22:29:34 -08001048 __SetPageUptodate(page);
Hugh Dickinsac9b9c62005-10-20 16:24:28 +01001049
Christoph Lameter6bda6662006-01-06 00:10:49 -08001050 if (vma->vm_flags & VM_SHARED) {
1051 int err;
Ken Chen45c682a2007-11-14 16:59:44 -08001052 struct inode *inode = mapping->host;
Christoph Lameter6bda6662006-01-06 00:10:49 -08001053
1054 err = add_to_page_cache(page, mapping, idx, GFP_KERNEL);
1055 if (err) {
1056 put_page(page);
Christoph Lameter6bda6662006-01-06 00:10:49 -08001057 if (err == -EEXIST)
1058 goto retry;
1059 goto out;
1060 }
Ken Chen45c682a2007-11-14 16:59:44 -08001061
1062 spin_lock(&inode->i_lock);
1063 inode->i_blocks += BLOCKS_PER_HUGEPAGE;
1064 spin_unlock(&inode->i_lock);
Christoph Lameter6bda6662006-01-06 00:10:49 -08001065 } else
1066 lock_page(page);
1067 }
David Gibson1e8f8892006-01-06 00:10:44 -08001068
Hugh Dickinsac9b9c62005-10-20 16:24:28 +01001069 spin_lock(&mm->page_table_lock);
Adam Litke4c887262005-10-29 18:16:46 -07001070 size = i_size_read(mapping->host) >> HPAGE_SHIFT;
1071 if (idx >= size)
1072 goto backout;
1073
Nick Piggin83c54072007-07-19 01:47:05 -07001074 ret = 0;
Gerald Schaefer7f2e9522008-04-28 02:13:29 -07001075 if (!huge_pte_none(huge_ptep_get(ptep)))
Adam Litke4c887262005-10-29 18:16:46 -07001076 goto backout;
1077
David Gibson1e8f8892006-01-06 00:10:44 -08001078 new_pte = make_huge_pte(vma, page, ((vma->vm_flags & VM_WRITE)
1079 && (vma->vm_flags & VM_SHARED)));
1080 set_huge_pte_at(mm, address, ptep, new_pte);
1081
1082 if (write_access && !(vma->vm_flags & VM_SHARED)) {
1083 /* Optimization, do the COW without a second fault */
1084 ret = hugetlb_cow(mm, vma, address, ptep, new_pte);
1085 }
1086
Hugh Dickinsac9b9c62005-10-20 16:24:28 +01001087 spin_unlock(&mm->page_table_lock);
Adam Litke4c887262005-10-29 18:16:46 -07001088 unlock_page(page);
1089out:
Hugh Dickinsac9b9c62005-10-20 16:24:28 +01001090 return ret;
Adam Litke4c887262005-10-29 18:16:46 -07001091
1092backout:
1093 spin_unlock(&mm->page_table_lock);
Adam Litke4c887262005-10-29 18:16:46 -07001094 unlock_page(page);
1095 put_page(page);
1096 goto out;
Hugh Dickinsac9b9c62005-10-20 16:24:28 +01001097}
1098
Adam Litke86e52162006-01-06 00:10:43 -08001099int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
1100 unsigned long address, int write_access)
1101{
1102 pte_t *ptep;
1103 pte_t entry;
David Gibson1e8f8892006-01-06 00:10:44 -08001104 int ret;
David Gibson3935baa2006-03-22 00:08:53 -08001105 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
Adam Litke86e52162006-01-06 00:10:43 -08001106
1107 ptep = huge_pte_alloc(mm, address);
1108 if (!ptep)
1109 return VM_FAULT_OOM;
1110
David Gibson3935baa2006-03-22 00:08:53 -08001111 /*
1112 * Serialize hugepage allocation and instantiation, so that we don't
1113 * get spurious allocation failures if two CPUs race to instantiate
1114 * the same page in the page cache.
1115 */
1116 mutex_lock(&hugetlb_instantiation_mutex);
Gerald Schaefer7f2e9522008-04-28 02:13:29 -07001117 entry = huge_ptep_get(ptep);
1118 if (huge_pte_none(entry)) {
David Gibson3935baa2006-03-22 00:08:53 -08001119 ret = hugetlb_no_page(mm, vma, address, ptep, write_access);
1120 mutex_unlock(&hugetlb_instantiation_mutex);
1121 return ret;
1122 }
Adam Litke86e52162006-01-06 00:10:43 -08001123
Nick Piggin83c54072007-07-19 01:47:05 -07001124 ret = 0;
David Gibson1e8f8892006-01-06 00:10:44 -08001125
1126 spin_lock(&mm->page_table_lock);
1127 /* Check for a racing update before calling hugetlb_cow */
Gerald Schaefer7f2e9522008-04-28 02:13:29 -07001128 if (likely(pte_same(entry, huge_ptep_get(ptep))))
David Gibson1e8f8892006-01-06 00:10:44 -08001129 if (write_access && !pte_write(entry))
1130 ret = hugetlb_cow(mm, vma, address, ptep, entry);
1131 spin_unlock(&mm->page_table_lock);
David Gibson3935baa2006-03-22 00:08:53 -08001132 mutex_unlock(&hugetlb_instantiation_mutex);
David Gibson1e8f8892006-01-06 00:10:44 -08001133
1134 return ret;
Adam Litke86e52162006-01-06 00:10:43 -08001135}
1136
David Gibson63551ae2005-06-21 17:14:44 -07001137int follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
1138 struct page **pages, struct vm_area_struct **vmas,
Adam Litke5b23dbe2007-11-14 16:59:33 -08001139 unsigned long *position, int *length, int i,
1140 int write)
David Gibson63551ae2005-06-21 17:14:44 -07001141{
Chen, Kenneth Wd5d4b0a2006-03-22 00:09:03 -08001142 unsigned long pfn_offset;
1143 unsigned long vaddr = *position;
David Gibson63551ae2005-06-21 17:14:44 -07001144 int remainder = *length;
1145
Hugh Dickins1c598272005-10-19 21:23:43 -07001146 spin_lock(&mm->page_table_lock);
David Gibson63551ae2005-06-21 17:14:44 -07001147 while (vaddr < vma->vm_end && remainder) {
Adam Litke4c887262005-10-29 18:16:46 -07001148 pte_t *pte;
1149 struct page *page;
1150
1151 /*
1152 * Some archs (sparc64, sh*) have multiple pte_ts to
1153 * each hugepage. We have to make * sure we get the
1154 * first, for the page indexing below to work.
1155 */
1156 pte = huge_pte_offset(mm, vaddr & HPAGE_MASK);
1157
Gerald Schaefer7f2e9522008-04-28 02:13:29 -07001158 if (!pte || huge_pte_none(huge_ptep_get(pte)) ||
1159 (write && !pte_write(huge_ptep_get(pte)))) {
Adam Litke4c887262005-10-29 18:16:46 -07001160 int ret;
1161
1162 spin_unlock(&mm->page_table_lock);
Adam Litke5b23dbe2007-11-14 16:59:33 -08001163 ret = hugetlb_fault(mm, vma, vaddr, write);
Adam Litke4c887262005-10-29 18:16:46 -07001164 spin_lock(&mm->page_table_lock);
Adam Litkea89182c2007-08-22 14:01:51 -07001165 if (!(ret & VM_FAULT_ERROR))
Adam Litke4c887262005-10-29 18:16:46 -07001166 continue;
1167
1168 remainder = 0;
1169 if (!i)
1170 i = -EFAULT;
1171 break;
1172 }
David Gibson63551ae2005-06-21 17:14:44 -07001173
Chen, Kenneth Wd5d4b0a2006-03-22 00:09:03 -08001174 pfn_offset = (vaddr & ~HPAGE_MASK) >> PAGE_SHIFT;
Gerald Schaefer7f2e9522008-04-28 02:13:29 -07001175 page = pte_page(huge_ptep_get(pte));
Chen, Kenneth Wd5d4b0a2006-03-22 00:09:03 -08001176same_page:
Chen, Kenneth Wd6692182006-03-31 02:29:57 -08001177 if (pages) {
1178 get_page(page);
Chen, Kenneth Wd5d4b0a2006-03-22 00:09:03 -08001179 pages[i] = page + pfn_offset;
Chen, Kenneth Wd6692182006-03-31 02:29:57 -08001180 }
David Gibson63551ae2005-06-21 17:14:44 -07001181
1182 if (vmas)
1183 vmas[i] = vma;
1184
1185 vaddr += PAGE_SIZE;
Chen, Kenneth Wd5d4b0a2006-03-22 00:09:03 -08001186 ++pfn_offset;
David Gibson63551ae2005-06-21 17:14:44 -07001187 --remainder;
1188 ++i;
Chen, Kenneth Wd5d4b0a2006-03-22 00:09:03 -08001189 if (vaddr < vma->vm_end && remainder &&
1190 pfn_offset < HPAGE_SIZE/PAGE_SIZE) {
1191 /*
1192 * We use pfn_offset to avoid touching the pageframes
1193 * of this compound page.
1194 */
1195 goto same_page;
1196 }
David Gibson63551ae2005-06-21 17:14:44 -07001197 }
Hugh Dickins1c598272005-10-19 21:23:43 -07001198 spin_unlock(&mm->page_table_lock);
David Gibson63551ae2005-06-21 17:14:44 -07001199 *length = remainder;
1200 *position = vaddr;
1201
1202 return i;
1203}
Zhang, Yanmin8f860592006-03-22 00:08:50 -08001204
1205void hugetlb_change_protection(struct vm_area_struct *vma,
1206 unsigned long address, unsigned long end, pgprot_t newprot)
1207{
1208 struct mm_struct *mm = vma->vm_mm;
1209 unsigned long start = address;
1210 pte_t *ptep;
1211 pte_t pte;
1212
1213 BUG_ON(address >= end);
1214 flush_cache_range(vma, address, end);
1215
Chen, Kenneth W39dde652006-12-06 20:32:03 -08001216 spin_lock(&vma->vm_file->f_mapping->i_mmap_lock);
Zhang, Yanmin8f860592006-03-22 00:08:50 -08001217 spin_lock(&mm->page_table_lock);
1218 for (; address < end; address += HPAGE_SIZE) {
1219 ptep = huge_pte_offset(mm, address);
1220 if (!ptep)
1221 continue;
Chen, Kenneth W39dde652006-12-06 20:32:03 -08001222 if (huge_pmd_unshare(mm, &address, ptep))
1223 continue;
Gerald Schaefer7f2e9522008-04-28 02:13:29 -07001224 if (!huge_pte_none(huge_ptep_get(ptep))) {
Zhang, Yanmin8f860592006-03-22 00:08:50 -08001225 pte = huge_ptep_get_and_clear(mm, address, ptep);
1226 pte = pte_mkhuge(pte_modify(pte, newprot));
1227 set_huge_pte_at(mm, address, ptep, pte);
Zhang, Yanmin8f860592006-03-22 00:08:50 -08001228 }
1229 }
1230 spin_unlock(&mm->page_table_lock);
Chen, Kenneth W39dde652006-12-06 20:32:03 -08001231 spin_unlock(&vma->vm_file->f_mapping->i_mmap_lock);
Zhang, Yanmin8f860592006-03-22 00:08:50 -08001232
1233 flush_tlb_range(vma, start, end);
1234}
1235
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -07001236struct file_region {
1237 struct list_head link;
1238 long from;
1239 long to;
1240};
1241
1242static long region_add(struct list_head *head, long f, long t)
1243{
1244 struct file_region *rg, *nrg, *trg;
1245
1246 /* Locate the region we are either in or before. */
1247 list_for_each_entry(rg, head, link)
1248 if (f <= rg->to)
1249 break;
1250
1251 /* Round our left edge to the current segment if it encloses us. */
1252 if (f > rg->from)
1253 f = rg->from;
1254
1255 /* Check for and consume any regions we now overlap with. */
1256 nrg = rg;
1257 list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
1258 if (&rg->link == head)
1259 break;
1260 if (rg->from > t)
1261 break;
1262
1263 /* If this area reaches higher then extend our area to
1264 * include it completely. If this is not the first area
1265 * which we intend to reuse, free it. */
1266 if (rg->to > t)
1267 t = rg->to;
1268 if (rg != nrg) {
1269 list_del(&rg->link);
1270 kfree(rg);
1271 }
1272 }
1273 nrg->from = f;
1274 nrg->to = t;
1275 return 0;
1276}
1277
1278static long region_chg(struct list_head *head, long f, long t)
1279{
1280 struct file_region *rg, *nrg;
1281 long chg = 0;
1282
1283 /* Locate the region we are before or in. */
1284 list_for_each_entry(rg, head, link)
1285 if (f <= rg->to)
1286 break;
1287
1288 /* If we are below the current region then a new region is required.
1289 * Subtle, allocate a new region at the position but make it zero
Simon Arlott183ff222007-10-20 01:27:18 +02001290 * size such that we can guarantee to record the reservation. */
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -07001291 if (&rg->link == head || t < rg->from) {
1292 nrg = kmalloc(sizeof(*nrg), GFP_KERNEL);
Stephen Hemmingerc80544d2007-10-18 03:07:05 -07001293 if (!nrg)
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -07001294 return -ENOMEM;
1295 nrg->from = f;
1296 nrg->to = f;
1297 INIT_LIST_HEAD(&nrg->link);
1298 list_add(&nrg->link, rg->link.prev);
1299
1300 return t - f;
1301 }
1302
1303 /* Round our left edge to the current segment if it encloses us. */
1304 if (f > rg->from)
1305 f = rg->from;
1306 chg = t - f;
1307
1308 /* Check for and consume any regions we now overlap with. */
1309 list_for_each_entry(rg, rg->link.prev, link) {
1310 if (&rg->link == head)
1311 break;
1312 if (rg->from > t)
1313 return chg;
1314
1315 /* We overlap with this area, if it extends futher than
1316 * us then we must extend ourselves. Account for its
1317 * existing reservation. */
1318 if (rg->to > t) {
1319 chg += rg->to - t;
1320 t = rg->to;
1321 }
1322 chg -= rg->to - rg->from;
1323 }
1324 return chg;
1325}
1326
1327static long region_truncate(struct list_head *head, long end)
1328{
1329 struct file_region *rg, *trg;
1330 long chg = 0;
1331
1332 /* Locate the region we are either in or before. */
1333 list_for_each_entry(rg, head, link)
1334 if (end <= rg->to)
1335 break;
1336 if (&rg->link == head)
1337 return 0;
1338
1339 /* If we are in the middle of a region then adjust it. */
1340 if (end > rg->from) {
1341 chg = rg->to - end;
1342 rg->to = end;
1343 rg = list_entry(rg->link.next, typeof(*rg), link);
1344 }
1345
1346 /* Drop any remaining regions. */
1347 list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
1348 if (&rg->link == head)
1349 break;
1350 chg += rg->to - rg->from;
1351 list_del(&rg->link);
1352 kfree(rg);
1353 }
1354 return chg;
1355}
1356
Mel Gormana1e78772008-07-23 21:27:23 -07001357int hugetlb_reserve_pages(struct inode *inode,
1358 long from, long to,
1359 struct vm_area_struct *vma)
Adam Litkee4e574b2007-10-16 01:26:19 -07001360{
1361 long ret, chg;
1362
Mel Gormana1e78772008-07-23 21:27:23 -07001363 /*
1364 * Shared mappings base their reservation on the number of pages that
1365 * are already allocated on behalf of the file. Private mappings need
1366 * to reserve the full area even if read-only as mprotect() may be
1367 * called to make the mapping read-write. Assume !vma is a shm mapping
1368 */
1369 if (!vma || vma->vm_flags & VM_SHARED)
1370 chg = region_chg(&inode->i_mapping->private_list, from, to);
1371 else {
1372 chg = to - from;
1373 set_vma_resv_huge_pages(vma, chg);
1374 }
1375
Adam Litkee4e574b2007-10-16 01:26:19 -07001376 if (chg < 0)
1377 return chg;
Ken Chen8a630112007-05-09 02:33:34 -07001378
Adam Litke90d8b7e2007-11-14 16:59:42 -08001379 if (hugetlb_get_quota(inode->i_mapping, chg))
1380 return -ENOSPC;
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -07001381 ret = hugetlb_acct_memory(chg);
Ken Chen68842c92008-01-14 00:55:19 -08001382 if (ret < 0) {
1383 hugetlb_put_quota(inode->i_mapping, chg);
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -07001384 return ret;
Ken Chen68842c92008-01-14 00:55:19 -08001385 }
Mel Gormana1e78772008-07-23 21:27:23 -07001386 if (!vma || vma->vm_flags & VM_SHARED)
1387 region_add(&inode->i_mapping->private_list, from, to);
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -07001388 return 0;
1389}
1390
1391void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
1392{
1393 long chg = region_truncate(&inode->i_mapping->private_list, offset);
Ken Chen45c682a2007-11-14 16:59:44 -08001394
1395 spin_lock(&inode->i_lock);
1396 inode->i_blocks -= BLOCKS_PER_HUGEPAGE * freed;
1397 spin_unlock(&inode->i_lock);
1398
Adam Litke90d8b7e2007-11-14 16:59:42 -08001399 hugetlb_put_quota(inode->i_mapping, (chg - freed));
1400 hugetlb_acct_memory(-(chg - freed));
Chen, Kenneth Wa43a8c32006-06-23 02:03:15 -07001401}