]> bbs.cooldavid.org Git - net-next-2.6.git/blame - mm/bootmem.c
hugetlb: quota is not freed for unused reserved private huge pages
[net-next-2.6.git] / mm / bootmem.c
CommitLineData
1da177e4
LT
1/*
2 * linux/mm/bootmem.c
3 *
4 * Copyright (C) 1999 Ingo Molnar
5 * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
6 *
7 * simple boot-time physical memory area allocator and
8 * free memory collector. It's used to deal with reserved
9 * system memory and memory holes as well.
10 */
1da177e4 11#include <linux/init.h>
bbc7b92e 12#include <linux/pfn.h>
1da177e4 13#include <linux/bootmem.h>
1da177e4 14#include <linux/module.h>
e786e86a
FBH
15
16#include <asm/bug.h>
1da177e4 17#include <asm/io.h>
dfd54cbc 18#include <asm/processor.h>
e786e86a 19
1da177e4
LT
20#include "internal.h"
21
22/*
23 * Access to this subsystem has to be serialized externally. (this is
24 * true for the boot process anyway)
25 */
26unsigned long max_low_pfn;
27unsigned long min_low_pfn;
28unsigned long max_pfn;
29
679bc9fb 30static LIST_HEAD(bdata_list);
92aa63a5
VG
31#ifdef CONFIG_CRASH_DUMP
32/*
33 * If we have booted due to a crash, max_pfn will be a very low value. We need
34 * to know the amount of memory that the previous kernel used.
35 */
36unsigned long saved_max_pfn;
37#endif
38
b61bfa3c
JW
39bootmem_data_t bootmem_node_data[MAX_NUMNODES] __initdata;
40
1da177e4 41/* return the number of _pages_ that will be allocated for the boot bitmap */
f71bf0ca 42unsigned long __init bootmem_bootmap_pages(unsigned long pages)
1da177e4
LT
43{
44 unsigned long mapsize;
45
46 mapsize = (pages+7)/8;
47 mapsize = (mapsize + ~PAGE_MASK) & PAGE_MASK;
48 mapsize >>= PAGE_SHIFT;
49
50 return mapsize;
51}
f71bf0ca 52
679bc9fb
KH
53/*
54 * link bdata in order
55 */
69d49e68 56static void __init link_bootmem(bootmem_data_t *bdata)
679bc9fb
KH
57{
58 bootmem_data_t *ent;
f71bf0ca 59
679bc9fb
KH
60 if (list_empty(&bdata_list)) {
61 list_add(&bdata->list, &bdata_list);
62 return;
63 }
64 /* insert in order */
65 list_for_each_entry(ent, &bdata_list, list) {
66 if (bdata->node_boot_start < ent->node_boot_start) {
67 list_add_tail(&bdata->list, &ent->list);
68 return;
69 }
70 }
71 list_add_tail(&bdata->list, &bdata_list);
679bc9fb
KH
72}
73
bbc7b92e
FBH
74/*
75 * Given an initialised bdata, it returns the size of the boot bitmap
76 */
77static unsigned long __init get_mapsize(bootmem_data_t *bdata)
78{
79 unsigned long mapsize;
80 unsigned long start = PFN_DOWN(bdata->node_boot_start);
81 unsigned long end = bdata->node_low_pfn;
82
83 mapsize = ((end - start) + 7) / 8;
84 return ALIGN(mapsize, sizeof(long));
85}
1da177e4
LT
86
87/*
88 * Called once to set up the allocator itself.
89 */
8ae04463 90static unsigned long __init init_bootmem_core(bootmem_data_t *bdata,
1da177e4
LT
91 unsigned long mapstart, unsigned long start, unsigned long end)
92{
bbc7b92e 93 unsigned long mapsize;
1da177e4 94
2dbb51c4 95 mminit_validate_memmodel_limits(&start, &end);
bbc7b92e
FBH
96 bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart));
97 bdata->node_boot_start = PFN_PHYS(start);
1da177e4 98 bdata->node_low_pfn = end;
679bc9fb 99 link_bootmem(bdata);
1da177e4
LT
100
101 /*
102 * Initially all pages are reserved - setup_arch() has to
103 * register free RAM areas explicitly.
104 */
bbc7b92e 105 mapsize = get_mapsize(bdata);
1da177e4
LT
106 memset(bdata->node_bootmem_map, 0xff, mapsize);
107
108 return mapsize;
109}
110
111/*
112 * Marks a particular physical memory range as unallocatable. Usable RAM
113 * might be used for boot-time allocations - or it might get added
114 * to the free page pool later on.
115 */
a5645a61 116static int __init can_reserve_bootmem_core(bootmem_data_t *bdata,
72a7fe39 117 unsigned long addr, unsigned long size, int flags)
1da177e4 118{
bbc7b92e 119 unsigned long sidx, eidx;
1da177e4 120 unsigned long i;
a5645a61
YL
121
122 BUG_ON(!size);
123
124 /* out of range, don't hold other */
125 if (addr + size < bdata->node_boot_start ||
126 PFN_DOWN(addr) > bdata->node_low_pfn)
127 return 0;
bbc7b92e 128
1da177e4 129 /*
a5645a61 130 * Round up to index to the range.
1da177e4 131 */
a5645a61
YL
132 if (addr > bdata->node_boot_start)
133 sidx= PFN_DOWN(addr - bdata->node_boot_start);
134 else
135 sidx = 0;
136
137 eidx = PFN_UP(addr + size - bdata->node_boot_start);
138 if (eidx > bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start))
139 eidx = bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start);
140
141 for (i = sidx; i < eidx; i++) {
142 if (test_bit(i, bdata->node_bootmem_map)) {
143 if (flags & BOOTMEM_EXCLUSIVE)
144 return -EBUSY;
145 }
146 }
147
148 return 0;
149
150}
151
152static void __init reserve_bootmem_core(bootmem_data_t *bdata,
153 unsigned long addr, unsigned long size, int flags)
154{
155 unsigned long sidx, eidx;
156 unsigned long i;
157
1da177e4 158 BUG_ON(!size);
bbc7b92e 159
a5645a61
YL
160 /* out of range */
161 if (addr + size < bdata->node_boot_start ||
162 PFN_DOWN(addr) > bdata->node_low_pfn)
163 return;
164
165 /*
166 * Round up to index to the range.
167 */
168 if (addr > bdata->node_boot_start)
169 sidx= PFN_DOWN(addr - bdata->node_boot_start);
170 else
171 sidx = 0;
172
bbc7b92e 173 eidx = PFN_UP(addr + size - bdata->node_boot_start);
a5645a61
YL
174 if (eidx > bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start))
175 eidx = bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start);
1da177e4 176
a5645a61 177 for (i = sidx; i < eidx; i++) {
1da177e4
LT
178 if (test_and_set_bit(i, bdata->node_bootmem_map)) {
179#ifdef CONFIG_DEBUG_BOOTMEM
180 printk("hm, page %08lx reserved twice.\n", i*PAGE_SIZE);
181#endif
182 }
a5645a61 183 }
1da177e4
LT
184}
185
bb0923a6
FBH
186static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
187 unsigned long size)
1da177e4 188{
bbc7b92e 189 unsigned long sidx, eidx;
1da177e4 190 unsigned long i;
bbc7b92e 191
5a982cbc
YL
192 BUG_ON(!size);
193
194 /* out range */
195 if (addr + size < bdata->node_boot_start ||
196 PFN_DOWN(addr) > bdata->node_low_pfn)
197 return;
1da177e4
LT
198 /*
199 * round down end of usable mem, partially free pages are
200 * considered reserved.
201 */
1da177e4 202
5a982cbc 203 if (addr >= bdata->node_boot_start && addr < bdata->last_success)
1da177e4
LT
204 bdata->last_success = addr;
205
206 /*
5a982cbc 207 * Round up to index to the range.
1da177e4 208 */
5a982cbc
YL
209 if (PFN_UP(addr) > PFN_DOWN(bdata->node_boot_start))
210 sidx = PFN_UP(addr) - PFN_DOWN(bdata->node_boot_start);
211 else
212 sidx = 0;
213
bbc7b92e 214 eidx = PFN_DOWN(addr + size - bdata->node_boot_start);
5a982cbc
YL
215 if (eidx > bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start))
216 eidx = bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start);
1da177e4
LT
217
218 for (i = sidx; i < eidx; i++) {
219 if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map)))
220 BUG();
221 }
222}
223
224/*
225 * We 'merge' subsequent allocations to save space. We might 'lose'
226 * some fraction of a page if allocations cannot be satisfied due to
227 * size constraints on boxes where there is physical RAM space
228 * fragmentation - in these cases (mostly large memory boxes) this
229 * is not a problem.
230 *
231 * On low memory boxes we get it right in 100% of the cases.
232 *
233 * alignment has to be a power of 2 value.
234 *
235 * NOTE: This function is _not_ reentrant.
236 */
ffc6421f
JW
237static void * __init
238alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size,
239 unsigned long align, unsigned long goal, unsigned long limit)
1da177e4 240{
9a2dc04c 241 unsigned long areasize, preferred;
bbc7b92e 242 unsigned long i, start = 0, incr, eidx, end_pfn;
1da177e4 243 void *ret;
9a2dc04c
YL
244 unsigned long node_boot_start;
245 void *node_bootmem_map;
1da177e4 246
f71bf0ca 247 if (!size) {
ffc6421f 248 printk("alloc_bootmem_core(): zero-sized request\n");
1da177e4
LT
249 BUG();
250 }
251 BUG_ON(align & (align-1));
252
7c309a64
CK
253 /* on nodes without memory - bootmem_map is NULL */
254 if (!bdata->node_bootmem_map)
255 return NULL;
256
9a2dc04c
YL
257 /* bdata->node_boot_start is supposed to be (12+6)bits alignment on x86_64 ? */
258 node_boot_start = bdata->node_boot_start;
259 node_bootmem_map = bdata->node_bootmem_map;
260 if (align) {
261 node_boot_start = ALIGN(bdata->node_boot_start, align);
262 if (node_boot_start > bdata->node_boot_start)
263 node_bootmem_map = (unsigned long *)bdata->node_bootmem_map +
264 PFN_DOWN(node_boot_start - bdata->node_boot_start)/BITS_PER_LONG;
265 }
266
267 if (limit && node_boot_start >= limit)
268 return NULL;
269
bbc7b92e
FBH
270 end_pfn = bdata->node_low_pfn;
271 limit = PFN_DOWN(limit);
281dd25c
YG
272 if (limit && end_pfn > limit)
273 end_pfn = limit;
274
9a2dc04c 275 eidx = end_pfn - PFN_DOWN(node_boot_start);
1da177e4
LT
276
277 /*
278 * We try to allocate bootmem pages above 'goal'
279 * first, then we try to allocate lower pages.
280 */
ad09315c
YL
281 preferred = 0;
282 if (goal && PFN_DOWN(goal) < end_pfn) {
9a2dc04c
YL
283 if (goal > node_boot_start)
284 preferred = goal - node_boot_start;
1da177e4 285
9a2dc04c
YL
286 if (bdata->last_success > node_boot_start &&
287 bdata->last_success - node_boot_start >= preferred)
281dd25c 288 if (!limit || (limit && limit > bdata->last_success))
9a2dc04c 289 preferred = bdata->last_success - node_boot_start;
ad09315c 290 }
1da177e4 291
9a2dc04c 292 preferred = PFN_DOWN(ALIGN(preferred, align));
bbc7b92e 293 areasize = (size + PAGE_SIZE-1) / PAGE_SIZE;
1da177e4
LT
294 incr = align >> PAGE_SHIFT ? : 1;
295
296restart_scan:
ad09315c 297 for (i = preferred; i < eidx;) {
1da177e4 298 unsigned long j;
ad09315c 299
9a2dc04c 300 i = find_next_zero_bit(node_bootmem_map, eidx, i);
1da177e4 301 i = ALIGN(i, incr);
66d43e98
HM
302 if (i >= eidx)
303 break;
9a2dc04c 304 if (test_bit(i, node_bootmem_map)) {
ad09315c 305 i += incr;
1da177e4 306 continue;
ad09315c 307 }
1da177e4
LT
308 for (j = i + 1; j < i + areasize; ++j) {
309 if (j >= eidx)
310 goto fail_block;
9a2dc04c 311 if (test_bit(j, node_bootmem_map))
1da177e4
LT
312 goto fail_block;
313 }
314 start = i;
315 goto found;
316 fail_block:
317 i = ALIGN(j, incr);
ad09315c
YL
318 if (i == j)
319 i += incr;
1da177e4
LT
320 }
321
9a2dc04c
YL
322 if (preferred > 0) {
323 preferred = 0;
1da177e4
LT
324 goto restart_scan;
325 }
326 return NULL;
327
328found:
9a2dc04c 329 bdata->last_success = PFN_PHYS(start) + node_boot_start;
1da177e4
LT
330 BUG_ON(start >= eidx);
331
332 /*
333 * Is the next page of the previous allocation-end the start
334 * of this allocation's buffer? If yes then we can 'merge'
335 * the previous partial page with this allocation.
336 */
337 if (align < PAGE_SIZE &&
338 bdata->last_offset && bdata->last_pos+1 == start) {
9a2dc04c 339 unsigned long offset, remaining_size;
8c0e33c1 340 offset = ALIGN(bdata->last_offset, align);
1da177e4 341 BUG_ON(offset > PAGE_SIZE);
f71bf0ca 342 remaining_size = PAGE_SIZE - offset;
1da177e4
LT
343 if (size < remaining_size) {
344 areasize = 0;
345 /* last_pos unchanged */
f71bf0ca
FBH
346 bdata->last_offset = offset + size;
347 ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
9a2dc04c 348 offset + node_boot_start);
1da177e4
LT
349 } else {
350 remaining_size = size - remaining_size;
f71bf0ca
FBH
351 areasize = (remaining_size + PAGE_SIZE-1) / PAGE_SIZE;
352 ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
9a2dc04c 353 offset + node_boot_start);
f71bf0ca 354 bdata->last_pos = start + areasize - 1;
1da177e4
LT
355 bdata->last_offset = remaining_size;
356 }
357 bdata->last_offset &= ~PAGE_MASK;
358 } else {
359 bdata->last_pos = start + areasize - 1;
360 bdata->last_offset = size & ~PAGE_MASK;
9a2dc04c 361 ret = phys_to_virt(start * PAGE_SIZE + node_boot_start);
1da177e4
LT
362 }
363
364 /*
365 * Reserve the area now:
366 */
f71bf0ca 367 for (i = start; i < start + areasize; i++)
9a2dc04c 368 if (unlikely(test_and_set_bit(i, node_bootmem_map)))
1da177e4
LT
369 BUG();
370 memset(ret, 0, size);
371 return ret;
372}
373
8ae04463 374static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata)
1da177e4
LT
375{
376 struct page *page;
d41dee36 377 unsigned long pfn;
6b312c0e 378 unsigned long i, count;
1da177e4
LT
379 unsigned long idx;
380 unsigned long *map;
381 int gofast = 0;
382
383 BUG_ON(!bdata->node_bootmem_map);
384
385 count = 0;
386 /* first extant page of the node */
bbc7b92e
FBH
387 pfn = PFN_DOWN(bdata->node_boot_start);
388 idx = bdata->node_low_pfn - pfn;
1da177e4 389 map = bdata->node_bootmem_map;
6b312c0e
JW
390 /*
391 * Check if we are aligned to BITS_PER_LONG pages. If so, we might
392 * be able to free page orders of that size at once.
393 */
394 if (!(pfn & (BITS_PER_LONG-1)))
1da177e4 395 gofast = 1;
6b312c0e 396
1da177e4
LT
397 for (i = 0; i < idx; ) {
398 unsigned long v = ~map[i / BITS_PER_LONG];
d41dee36 399
1da177e4 400 if (gofast && v == ~0UL) {
a226f6c8 401 int order;
1da177e4 402
d41dee36 403 page = pfn_to_page(pfn);
1da177e4 404 count += BITS_PER_LONG;
1da177e4 405 order = ffs(BITS_PER_LONG) - 1;
a226f6c8 406 __free_pages_bootmem(page, order);
1da177e4
LT
407 i += BITS_PER_LONG;
408 page += BITS_PER_LONG;
409 } else if (v) {
410 unsigned long m;
d41dee36
AW
411
412 page = pfn_to_page(pfn);
1da177e4
LT
413 for (m = 1; m && i < idx; m<<=1, page++, i++) {
414 if (v & m) {
415 count++;
a226f6c8 416 __free_pages_bootmem(page, 0);
1da177e4
LT
417 }
418 }
419 } else {
f71bf0ca 420 i += BITS_PER_LONG;
1da177e4 421 }
d41dee36 422 pfn += BITS_PER_LONG;
1da177e4 423 }
1da177e4
LT
424
425 /*
426 * Now free the allocator bitmap itself, it's not
427 * needed anymore:
428 */
429 page = virt_to_page(bdata->node_bootmem_map);
bbc7b92e 430 idx = (get_mapsize(bdata) + PAGE_SIZE-1) >> PAGE_SHIFT;
6b312c0e 431 for (i = 0; i < idx; i++, page++)
a226f6c8 432 __free_pages_bootmem(page, 0);
6b312c0e 433 count += i;
1da177e4
LT
434 bdata->node_bootmem_map = NULL;
435
6b312c0e 436 return count;
1da177e4
LT
437}
438
f71bf0ca 439unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn,
bb0923a6 440 unsigned long startpfn, unsigned long endpfn)
1da177e4 441{
8ae04463 442 return init_bootmem_core(pgdat->bdata, freepfn, startpfn, endpfn);
1da177e4
LT
443}
444
71c2742f 445int __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
72a7fe39 446 unsigned long size, int flags)
1da177e4 447{
a5645a61
YL
448 int ret;
449
450 ret = can_reserve_bootmem_core(pgdat->bdata, physaddr, size, flags);
451 if (ret < 0)
71c2742f 452 return -ENOMEM;
72a7fe39 453 reserve_bootmem_core(pgdat->bdata, physaddr, size, flags);
71c2742f
BW
454
455 return 0;
1da177e4
LT
456}
457
f71bf0ca
FBH
458void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
459 unsigned long size)
1da177e4
LT
460{
461 free_bootmem_core(pgdat->bdata, physaddr, size);
462}
463
f71bf0ca 464unsigned long __init free_all_bootmem_node(pg_data_t *pgdat)
1da177e4 465{
04753278 466 register_page_bootmem_info_node(pgdat);
8ae04463 467 return free_all_bootmem_core(pgdat->bdata);
1da177e4
LT
468}
469
f71bf0ca 470unsigned long __init init_bootmem(unsigned long start, unsigned long pages)
1da177e4
LT
471{
472 max_low_pfn = pages;
473 min_low_pfn = start;
8ae04463 474 return init_bootmem_core(NODE_DATA(0)->bdata, start, 0, pages);
1da177e4
LT
475}
476
477#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
72a7fe39
BW
478int __init reserve_bootmem(unsigned long addr, unsigned long size,
479 int flags)
1da177e4 480{
a5645a61
YL
481 bootmem_data_t *bdata;
482 int ret;
483
484 list_for_each_entry(bdata, &bdata_list, list) {
485 ret = can_reserve_bootmem_core(bdata, addr, size, flags);
486 if (ret < 0)
487 return ret;
488 }
489 list_for_each_entry(bdata, &bdata_list, list)
490 reserve_bootmem_core(bdata, addr, size, flags);
491
492 return 0;
1da177e4
LT
493}
494#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
495
f71bf0ca 496void __init free_bootmem(unsigned long addr, unsigned long size)
1da177e4 497{
5a982cbc
YL
498 bootmem_data_t *bdata;
499 list_for_each_entry(bdata, &bdata_list, list)
500 free_bootmem_core(bdata, addr, size);
1da177e4
LT
501}
502
f71bf0ca 503unsigned long __init free_all_bootmem(void)
1da177e4 504{
8ae04463 505 return free_all_bootmem_core(NODE_DATA(0)->bdata);
1da177e4
LT
506}
507
bb0923a6
FBH
508void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
509 unsigned long goal)
1da177e4 510{
679bc9fb 511 bootmem_data_t *bdata;
1da177e4
LT
512 void *ptr;
513
f71bf0ca 514 list_for_each_entry(bdata, &bdata_list, list) {
ffc6421f 515 ptr = alloc_bootmem_core(bdata, size, align, goal, 0);
f71bf0ca
FBH
516 if (ptr)
517 return ptr;
518 }
a8062231
AK
519 return NULL;
520}
1da177e4 521
bb0923a6
FBH
522void * __init __alloc_bootmem(unsigned long size, unsigned long align,
523 unsigned long goal)
a8062231
AK
524{
525 void *mem = __alloc_bootmem_nopanic(size,align,goal);
f71bf0ca 526
a8062231
AK
527 if (mem)
528 return mem;
1da177e4
LT
529 /*
530 * Whoops, we cannot satisfy the allocation request.
531 */
532 printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size);
533 panic("Out of memory");
534 return NULL;
535}
536
281dd25c 537
bb0923a6
FBH
538void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
539 unsigned long align, unsigned long goal)
1da177e4
LT
540{
541 void *ptr;
542
ffc6421f 543 ptr = alloc_bootmem_core(pgdat->bdata, size, align, goal, 0);
1da177e4 544 if (ptr)
f71bf0ca 545 return ptr;
1da177e4 546
008857c1 547 return __alloc_bootmem(size, align, goal);
1da177e4
LT
548}
549
e70260aa
YG
550#ifdef CONFIG_SPARSEMEM
551void * __init alloc_bootmem_section(unsigned long size,
552 unsigned long section_nr)
553{
554 void *ptr;
555 unsigned long limit, goal, start_nr, end_nr, pfn;
556 struct pglist_data *pgdat;
557
558 pfn = section_nr_to_pfn(section_nr);
559 goal = PFN_PHYS(pfn);
560 limit = PFN_PHYS(section_nr_to_pfn(section_nr + 1)) - 1;
561 pgdat = NODE_DATA(early_pfn_to_nid(pfn));
ffc6421f
JW
562 ptr = alloc_bootmem_core(pgdat->bdata, size, SMP_CACHE_BYTES, goal,
563 limit);
e70260aa
YG
564
565 if (!ptr)
566 return NULL;
567
568 start_nr = pfn_to_section_nr(PFN_DOWN(__pa(ptr)));
569 end_nr = pfn_to_section_nr(PFN_DOWN(__pa(ptr) + size));
570 if (start_nr != section_nr || end_nr != section_nr) {
571 printk(KERN_WARNING "alloc_bootmem failed on section %ld.\n",
572 section_nr);
573 free_bootmem_core(pgdat->bdata, __pa(ptr), size);
574 ptr = NULL;
575 }
576
577 return ptr;
578}
579#endif
580
b54bbf7b
AK
581void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size,
582 unsigned long align, unsigned long goal)
583{
584 void *ptr;
585
586 ptr = alloc_bootmem_core(pgdat->bdata, size, align, goal, 0);
587 if (ptr)
588 return ptr;
589
590 return __alloc_bootmem_nopanic(size, align, goal);
591}
592
dfd54cbc
HC
593#ifndef ARCH_LOW_ADDRESS_LIMIT
594#define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
595#endif
008857c1 596
bb0923a6
FBH
597void * __init __alloc_bootmem_low(unsigned long size, unsigned long align,
598 unsigned long goal)
008857c1 599{
679bc9fb 600 bootmem_data_t *bdata;
008857c1
RT
601 void *ptr;
602
f71bf0ca 603 list_for_each_entry(bdata, &bdata_list, list) {
ffc6421f
JW
604 ptr = alloc_bootmem_core(bdata, size, align, goal,
605 ARCH_LOW_ADDRESS_LIMIT);
f71bf0ca
FBH
606 if (ptr)
607 return ptr;
608 }
008857c1
RT
609
610 /*
611 * Whoops, we cannot satisfy the allocation request.
612 */
613 printk(KERN_ALERT "low bootmem alloc of %lu bytes failed!\n", size);
614 panic("Out of low memory");
615 return NULL;
616}
617
618void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size,
619 unsigned long align, unsigned long goal)
620{
ffc6421f
JW
621 return alloc_bootmem_core(pgdat->bdata, size, align, goal,
622 ARCH_LOW_ADDRESS_LIMIT);
008857c1 623}