13 #include <linux/slab.h>
15 #include <linux/export.h>
22 #include <asm/processor.h>
26 #ifndef CONFIG_NEED_MULTIPLE_NODES
41 static int bootmem_debug;
43 static int __init bootmem_debug_setup(
char *
buf)
50 #define bdebug(fmt, args...) ({ \
51 if (unlikely(bootmem_debug)) \
57 static unsigned long __init bootmap_bytes(
unsigned long pages)
61 return ALIGN(bytes,
sizeof(
long));
70 unsigned long bytes = bootmap_bytes(pages);
96 unsigned long mapstart,
unsigned long start,
unsigned long end)
98 unsigned long mapsize;
110 mapsize = bootmap_bytes(end - start);
113 bdebug(
"nid=%td start=%lx map=%lx end=%lx mapsize=%lx\n",
114 bdata - bootmem_node_data, start, mapstart, end, mapsize);
129 unsigned long startpfn,
unsigned long endpfn)
131 return init_bootmem_core(pgdat->
bdata, freepfn, startpfn, endpfn);
145 return init_bootmem_core(
NODE_DATA(0)->bdata, start, 0, pages);
159 unsigned long cursor,
end;
166 for (; cursor <
end; cursor++) {
183 bdebug(
"nid=%td start=%lx end=%lx\n",
184 bdata - bootmem_node_data, start, end);
186 while (start < end) {
187 unsigned long *
map,
idx, vec;
204 unsigned long off = 0;
227 bdebug(
"nid=%td released=%lx\n", bdata - bootmem_node_data, count);
240 register_page_bootmem_info_node(pgdat);
241 return free_all_bootmem_core(pgdat->
bdata);
251 unsigned long total_pages = 0;
255 total_pages += free_all_bootmem_core(bdata);
261 unsigned long sidx,
unsigned long eidx)
265 bdebug(
"nid=%td start=%lx end=%lx\n", bdata - bootmem_node_data,
272 for (idx = sidx; idx < eidx; idx++)
278 unsigned long eidx,
int flags)
283 bdebug(
"nid=%td start=%lx end=%lx flags=%x\n",
284 bdata - bootmem_node_data,
289 for (idx = sidx; idx < eidx; idx++)
292 __free(bdata, sidx, idx);
295 bdebug(
"silent double reserve of PFN %lx\n",
302 unsigned long start,
unsigned long end,
305 unsigned long sidx, eidx;
307 bdebug(
"nid=%td start=%lx end=%lx reserve=%d flags=%x\n",
308 bdata - bootmem_node_data, start, end, reserve, flags);
310 BUG_ON(start < bdata->node_min_pfn);
317 return __reserve(bdata, sidx, eidx, flags);
319 __free(bdata, sidx, eidx);
323 static int __init mark_bootmem(
unsigned long start,
unsigned long end,
324 int reserve,
int flags)
334 if (pos < bdata->node_min_pfn ||
342 err = mark_bootmem_node(bdata, pos, max, reserve, flags);
343 if (reserve && err) {
344 mark_bootmem(start, pos, 0, 0);
375 mark_bootmem_node(pgdat->
bdata, start, end, 0, 0);
396 mark_bootmem(start, end, 0, 0);
411 unsigned long size,
int flags)
416 end =
PFN_UP(physaddr + size);
418 return mark_bootmem_node(pgdat->
bdata, start, end, 1, flags);
437 end =
PFN_UP(addr + size);
439 return mark_bootmem(start, end, 1, flags);
449 unsigned long idx,
unsigned long step)
458 return ALIGN(base + idx, step) - base;
462 unsigned long off,
unsigned long align)
468 return ALIGN(base + off, align) - base;
473 unsigned long goal,
unsigned long limit)
475 unsigned long fallback = 0;
478 bdebug(
"nid=%td size=%lx [%lu pages] align=%lx goal=%lx limit=%lx\n",
483 BUG_ON(align & (align - 1));
484 BUG_ON(limit && goal + size > limit);
495 if (limit && max > limit)
502 if (goal && min < goal && goal < max)
503 start =
ALIGN(goal, step);
505 start =
ALIGN(min, step);
516 sidx = align_idx(bdata, bdata->
hint_idx, step);
522 unsigned long eidx,
i, start_off, end_off;
525 sidx = align_idx(bdata, sidx, step);
526 eidx = sidx +
PFN_UP(size);
528 if (sidx >= midx || eidx > midx)
531 for (i = sidx; i < eidx; i++)
533 sidx = align_idx(bdata, i, step);
541 start_off = align_off(bdata, bdata->
last_end_off, align);
546 end_off = start_off +
size;
554 if (__reserve(bdata,
PFN_DOWN(start_off) + merge,
555 PFN_UP(end_off), BOOTMEM_EXCLUSIVE))
570 sidx = align_idx(bdata, fallback - 1, step);
579 unsigned long size,
unsigned long align,
580 unsigned long goal,
unsigned long limit)
585 #ifdef CONFIG_HAVE_ARCH_BOOTMEM
589 p_bdata = bootmem_arch_preferred_node(bdata, size, align,
592 return alloc_bootmem_bdata(p_bdata, size, align,
599 static void *
__init alloc_bootmem_core(
unsigned long size,
607 region = alloc_arch_preferred_bootmem(
NULL, size, align, goal, limit);
617 region = alloc_bootmem_bdata(bdata, size, align, goal, limit);
625 static void *
__init ___alloc_bootmem_nopanic(
unsigned long size,
633 ptr = alloc_bootmem_core(size, align, goal, limit);
660 unsigned long limit = 0;
662 return ___alloc_bootmem_nopanic(size, align, goal, limit);
665 static void *
__init ___alloc_bootmem(
unsigned long size,
unsigned long align,
666 unsigned long goal,
unsigned long limit)
668 void *
mem = ___alloc_bootmem_nopanic(size, align, goal, limit);
676 panic(
"Out of memory");
696 unsigned long limit = 0;
698 return ___alloc_bootmem(size, align, goal, limit);
702 unsigned long size,
unsigned long align,
703 unsigned long goal,
unsigned long limit)
708 ptr = alloc_arch_preferred_bootmem(pgdat->
bdata, size,
714 if (limit && goal + size > limit)
717 ptr = alloc_bootmem_bdata(pgdat->
bdata, size, align, goal, limit);
721 ptr = alloc_bootmem_core(size, align, goal, limit);
734 unsigned long align,
unsigned long goal)
743 unsigned long align,
unsigned long goal,
753 panic(
"Out of memory");
773 unsigned long align,
unsigned long goal)
782 unsigned long align,
unsigned long goal)
785 unsigned long end_pfn;
796 unsigned long new_goal;
799 ptr = alloc_bootmem_bdata(pgdat->
bdata, size, align,
810 #ifndef ARCH_LOW_ADDRESS_LIMIT
811 #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
849 unsigned long align,
unsigned long goal)