Blame view
mm/bootmem.c
17.8 KB
1da177e4c Linux-2.6.12-rc2 |
1 |
/* |
57cfc29ef bootmem: clean up... |
2 |
* bootmem - A boot-time physical memory allocator and configurator |
1da177e4c Linux-2.6.12-rc2 |
3 4 |
* * Copyright (C) 1999 Ingo Molnar |
57cfc29ef bootmem: clean up... |
5 6 |
* 1999 Kanoj Sarcar, SGI * 2008 Johannes Weiner |
1da177e4c Linux-2.6.12-rc2 |
7 |
* |
57cfc29ef bootmem: clean up... |
8 9 |
* Access to this subsystem has to be serialized externally (which is true * for the boot process anyway). |
1da177e4c Linux-2.6.12-rc2 |
10 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
11 |
#include <linux/init.h> |
bbc7b92e3 [PATCH] bootmem: ... |
12 |
#include <linux/pfn.h> |
1da177e4c Linux-2.6.12-rc2 |
13 |
#include <linux/bootmem.h> |
1da177e4c Linux-2.6.12-rc2 |
14 |
#include <linux/module.h> |
e786e86a5 [PATCH] bootmem: ... |
15 16 |
#include <asm/bug.h> |
1da177e4c Linux-2.6.12-rc2 |
17 |
#include <asm/io.h> |
dfd54cbcc [PATCH] bootmem: ... |
18 |
#include <asm/processor.h> |
e786e86a5 [PATCH] bootmem: ... |
19 |
|
1da177e4c Linux-2.6.12-rc2 |
20 |
#include "internal.h" |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 |
unsigned long max_low_pfn; unsigned long min_low_pfn; unsigned long max_pfn; |
92aa63a5a [PATCH] kdump: Re... |
24 25 26 27 28 29 30 |
#ifdef CONFIG_CRASH_DUMP /* * If we have booted due to a crash, max_pfn will be a very low value. We need * to know the amount of memory that the previous kernel used. */ unsigned long saved_max_pfn; #endif |
b61bfa3c4 mm: move bootmem ... |
31 |
bootmem_data_t bootmem_node_data[MAX_NUMNODES] __initdata; |
636cc40cb bootmem: revisit ... |
32 |
static struct list_head bdata_list __initdata = LIST_HEAD_INIT(bdata_list); |
2e5237daf bootmem: add debu... |
33 34 35 36 37 38 39 40 41 42 43 44 45 |
static int bootmem_debug; static int __init bootmem_debug_setup(char *buf) { bootmem_debug = 1; return 0; } early_param("bootmem_debug", bootmem_debug_setup); #define bdebug(fmt, args...) ({ \ if (unlikely(bootmem_debug)) \ printk(KERN_INFO \ "bootmem::%s " fmt, \ |
80a914dc0 misc: replace __F... |
46 |
__func__, ## args); \ |
2e5237daf bootmem: add debu... |
47 |
}) |
df049a5f4 bootmem: revisit ... |
48 |
static unsigned long __init bootmap_bytes(unsigned long pages) |
223e8dc92 bootmem: reorder ... |
49 |
{ |
df049a5f4 bootmem: revisit ... |
50 |
unsigned long bytes = (pages + 7) / 8; |
223e8dc92 bootmem: reorder ... |
51 |
|
df049a5f4 bootmem: revisit ... |
52 |
return ALIGN(bytes, sizeof(long)); |
223e8dc92 bootmem: reorder ... |
53 |
} |
a66fd7dae bootmem: add docu... |
54 55 56 57 |
/** * bootmem_bootmap_pages - calculate bitmap size in pages * @pages: number of pages the bitmap has to represent */ |
f71bf0cac [PATCH] bootmem: ... |
58 |
unsigned long __init bootmem_bootmap_pages(unsigned long pages) |
1da177e4c Linux-2.6.12-rc2 |
59 |
{ |
df049a5f4 bootmem: revisit ... |
60 |
unsigned long bytes = bootmap_bytes(pages); |
1da177e4c Linux-2.6.12-rc2 |
61 |
|
df049a5f4 bootmem: revisit ... |
62 |
return PAGE_ALIGN(bytes) >> PAGE_SHIFT; |
1da177e4c Linux-2.6.12-rc2 |
63 |
} |
f71bf0cac [PATCH] bootmem: ... |
64 |
|
679bc9fbb [PATCH] for_each_... |
65 66 67 |
/* * link bdata in order */ |
69d49e681 [PATCH] bootmem: ... |
68 |
static void __init link_bootmem(bootmem_data_t *bdata) |
679bc9fbb [PATCH] for_each_... |
69 |
{ |
636cc40cb bootmem: revisit ... |
70 |
struct list_head *iter; |
f71bf0cac [PATCH] bootmem: ... |
71 |
|
636cc40cb bootmem: revisit ... |
72 73 74 75 |
list_for_each(iter, &bdata_list) { bootmem_data_t *ent; ent = list_entry(iter, bootmem_data_t, list); |
3560e249a bootmem: replace ... |
76 |
if (bdata->node_min_pfn < ent->node_min_pfn) |
636cc40cb bootmem: revisit ... |
77 |
break; |
679bc9fbb [PATCH] for_each_... |
78 |
} |
636cc40cb bootmem: revisit ... |
79 |
list_add_tail(&bdata->list, iter); |
679bc9fbb [PATCH] for_each_... |
80 |
} |
bbc7b92e3 [PATCH] bootmem: ... |
81 |
/* |
1da177e4c Linux-2.6.12-rc2 |
82 83 |
* Called once to set up the allocator itself. */ |
8ae044630 mm: normalize int... |
84 |
static unsigned long __init init_bootmem_core(bootmem_data_t *bdata, |
1da177e4c Linux-2.6.12-rc2 |
85 86 |
unsigned long mapstart, unsigned long start, unsigned long end) { |
bbc7b92e3 [PATCH] bootmem: ... |
87 |
unsigned long mapsize; |
1da177e4c Linux-2.6.12-rc2 |
88 |
|
2dbb51c49 mm: make defensiv... |
89 |
mminit_validate_memmodel_limits(&start, &end); |
bbc7b92e3 [PATCH] bootmem: ... |
90 |
bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart)); |
3560e249a bootmem: replace ... |
91 |
bdata->node_min_pfn = start; |
1da177e4c Linux-2.6.12-rc2 |
92 |
bdata->node_low_pfn = end; |
679bc9fbb [PATCH] for_each_... |
93 |
link_bootmem(bdata); |
1da177e4c Linux-2.6.12-rc2 |
94 95 96 97 98 |
/* * Initially all pages are reserved - setup_arch() has to * register free RAM areas explicitly. */ |
df049a5f4 bootmem: revisit ... |
99 |
mapsize = bootmap_bytes(end - start); |
1da177e4c Linux-2.6.12-rc2 |
100 |
memset(bdata->node_bootmem_map, 0xff, mapsize); |
2e5237daf bootmem: add debu... |
101 102 103 |
bdebug("nid=%td start=%lx map=%lx end=%lx mapsize=%lx ", bdata - bootmem_node_data, start, mapstart, end, mapsize); |
1da177e4c Linux-2.6.12-rc2 |
104 105 |
return mapsize; } |
a66fd7dae bootmem: add docu... |
106 107 108 109 110 111 112 113 114 |
/** * init_bootmem_node - register a node as boot memory * @pgdat: node to register * @freepfn: pfn where the bitmap for this node is to be placed * @startpfn: first pfn on the node * @endpfn: first pfn after the node * * Returns the number of bytes needed to hold the bitmap for this node. */ |
223e8dc92 bootmem: reorder ... |
115 116 117 118 119 |
unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn) { return init_bootmem_core(pgdat->bdata, freepfn, startpfn, endpfn); } |
a66fd7dae bootmem: add docu... |
120 121 122 123 124 125 126 |
/** * init_bootmem - register boot memory * @start: pfn where the bitmap is to be placed * @pages: number of available physical pages * * Returns the number of bytes needed to hold the bitmap. */ |
223e8dc92 bootmem: reorder ... |
127 128 129 130 131 132 133 134 135 |
unsigned long __init init_bootmem(unsigned long start, unsigned long pages) { max_low_pfn = pages; min_low_pfn = start; return init_bootmem_core(NODE_DATA(0)->bdata, start, 0, pages); } static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata) { |
41546c174 bootmem: clean up... |
136 |
int aligned; |
223e8dc92 bootmem: reorder ... |
137 |
struct page *page; |
41546c174 bootmem: clean up... |
138 139 140 141 |
unsigned long start, end, pages, count = 0; if (!bdata->node_bootmem_map) return 0; |
3560e249a bootmem: replace ... |
142 |
start = bdata->node_min_pfn; |
41546c174 bootmem: clean up... |
143 |
end = bdata->node_low_pfn; |
223e8dc92 bootmem: reorder ... |
144 |
/* |
41546c174 bootmem: clean up... |
145 146 |
* If the start is aligned to the machines wordsize, we might * be able to free pages in bulks of that order. |
223e8dc92 bootmem: reorder ... |
147 |
*/ |
41546c174 bootmem: clean up... |
148 |
aligned = !(start & (BITS_PER_LONG - 1)); |
223e8dc92 bootmem: reorder ... |
149 |
|
41546c174 bootmem: clean up... |
150 151 152 |
bdebug("nid=%td start=%lx end=%lx aligned=%d ", bdata - bootmem_node_data, start, end, aligned); |
223e8dc92 bootmem: reorder ... |
153 |
|
41546c174 bootmem: clean up... |
154 155 |
while (start < end) { unsigned long *map, idx, vec; |
223e8dc92 bootmem: reorder ... |
156 |
|
41546c174 bootmem: clean up... |
157 |
map = bdata->node_bootmem_map; |
3560e249a bootmem: replace ... |
158 |
idx = start - bdata->node_min_pfn; |
41546c174 bootmem: clean up... |
159 160 161 162 163 164 |
vec = ~map[idx / BITS_PER_LONG]; if (aligned && vec == ~0UL && start + BITS_PER_LONG < end) { int order = ilog2(BITS_PER_LONG); __free_pages_bootmem(pfn_to_page(start), order); |
223e8dc92 bootmem: reorder ... |
165 |
count += BITS_PER_LONG; |
41546c174 bootmem: clean up... |
166 167 168 169 170 171 |
} else { unsigned long off = 0; while (vec && off < BITS_PER_LONG) { if (vec & 1) { page = pfn_to_page(start + off); |
223e8dc92 bootmem: reorder ... |
172 |
__free_pages_bootmem(page, 0); |
41546c174 bootmem: clean up... |
173 |
count++; |
223e8dc92 bootmem: reorder ... |
174 |
} |
41546c174 bootmem: clean up... |
175 176 |
vec >>= 1; off++; |
223e8dc92 bootmem: reorder ... |
177 |
} |
223e8dc92 bootmem: reorder ... |
178 |
} |
41546c174 bootmem: clean up... |
179 |
start += BITS_PER_LONG; |
223e8dc92 bootmem: reorder ... |
180 |
} |
223e8dc92 bootmem: reorder ... |
181 |
page = virt_to_page(bdata->node_bootmem_map); |
3560e249a bootmem: replace ... |
182 |
pages = bdata->node_low_pfn - bdata->node_min_pfn; |
41546c174 bootmem: clean up... |
183 184 185 186 |
pages = bootmem_bootmap_pages(pages); count += pages; while (pages--) __free_pages_bootmem(page++, 0); |
223e8dc92 bootmem: reorder ... |
187 |
|
2e5237daf bootmem: add debu... |
188 189 |
bdebug("nid=%td released=%lx ", bdata - bootmem_node_data, count); |
223e8dc92 bootmem: reorder ... |
190 191 |
return count; } |
a66fd7dae bootmem: add docu... |
192 193 194 195 196 197 |
/** * free_all_bootmem_node - release a node's free pages to the buddy allocator * @pgdat: node to be released * * Returns the number of pages actually released. */ |
223e8dc92 bootmem: reorder ... |
198 199 200 201 202 |
unsigned long __init free_all_bootmem_node(pg_data_t *pgdat) { register_page_bootmem_info_node(pgdat); return free_all_bootmem_core(pgdat->bdata); } |
a66fd7dae bootmem: add docu... |
203 204 205 206 207 |
/** * free_all_bootmem - release free pages to the buddy allocator * * Returns the number of pages actually released. */ |
223e8dc92 bootmem: reorder ... |
208 209 210 211 |
unsigned long __init free_all_bootmem(void) { return free_all_bootmem_core(NODE_DATA(0)->bdata); } |
d747fa4bc bootmem: free/res... |
212 213 214 215 216 217 218 |
static void __init __free(bootmem_data_t *bdata, unsigned long sidx, unsigned long eidx) { unsigned long idx; bdebug("nid=%td start=%lx end=%lx ", bdata - bootmem_node_data, |
3560e249a bootmem: replace ... |
219 220 |
sidx + bdata->node_min_pfn, eidx + bdata->node_min_pfn); |
d747fa4bc bootmem: free/res... |
221 |
|
e2bf3cae5 bootmem: factor o... |
222 223 |
if (bdata->hint_idx > sidx) bdata->hint_idx = sidx; |
d747fa4bc bootmem: free/res... |
224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
for (idx = sidx; idx < eidx; idx++) if (!test_and_clear_bit(idx, bdata->node_bootmem_map)) BUG(); } static int __init __reserve(bootmem_data_t *bdata, unsigned long sidx, unsigned long eidx, int flags) { unsigned long idx; int exclusive = flags & BOOTMEM_EXCLUSIVE; bdebug("nid=%td start=%lx end=%lx flags=%x ", bdata - bootmem_node_data, |
3560e249a bootmem: replace ... |
238 239 |
sidx + bdata->node_min_pfn, eidx + bdata->node_min_pfn, |
d747fa4bc bootmem: free/res... |
240 241 242 243 244 245 246 247 248 249 |
flags); for (idx = sidx; idx < eidx; idx++) if (test_and_set_bit(idx, bdata->node_bootmem_map)) { if (exclusive) { __free(bdata, sidx, idx); return -EBUSY; } bdebug("silent double reserve of PFN %lx ", |
3560e249a bootmem: replace ... |
250 |
idx + bdata->node_min_pfn); |
d747fa4bc bootmem: free/res... |
251 252 253 |
} return 0; } |
e2bf3cae5 bootmem: factor o... |
254 255 256 |
static int __init mark_bootmem_node(bootmem_data_t *bdata, unsigned long start, unsigned long end, int reserve, int flags) |
223e8dc92 bootmem: reorder ... |
257 258 |
{ unsigned long sidx, eidx; |
223e8dc92 bootmem: reorder ... |
259 |
|
e2bf3cae5 bootmem: factor o... |
260 261 262 |
bdebug("nid=%td start=%lx end=%lx reserve=%d flags=%x ", bdata - bootmem_node_data, start, end, reserve, flags); |
223e8dc92 bootmem: reorder ... |
263 |
|
3560e249a bootmem: replace ... |
264 |
BUG_ON(start < bdata->node_min_pfn); |
e2bf3cae5 bootmem: factor o... |
265 |
BUG_ON(end > bdata->node_low_pfn); |
223e8dc92 bootmem: reorder ... |
266 |
|
3560e249a bootmem: replace ... |
267 268 |
sidx = start - bdata->node_min_pfn; eidx = end - bdata->node_min_pfn; |
223e8dc92 bootmem: reorder ... |
269 |
|
e2bf3cae5 bootmem: factor o... |
270 271 |
if (reserve) return __reserve(bdata, sidx, eidx, flags); |
223e8dc92 bootmem: reorder ... |
272 |
else |
e2bf3cae5 bootmem: factor o... |
273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
__free(bdata, sidx, eidx); return 0; } static int __init mark_bootmem(unsigned long start, unsigned long end, int reserve, int flags) { unsigned long pos; bootmem_data_t *bdata; pos = start; list_for_each_entry(bdata, &bdata_list, list) { int err; unsigned long max; |
3560e249a bootmem: replace ... |
287 288 |
if (pos < bdata->node_min_pfn || pos >= bdata->node_low_pfn) { |
e2bf3cae5 bootmem: factor o... |
289 290 291 292 293 |
BUG_ON(pos != start); continue; } max = min(bdata->node_low_pfn, end); |
223e8dc92 bootmem: reorder ... |
294 |
|
e2bf3cae5 bootmem: factor o... |
295 296 297 298 299 |
err = mark_bootmem_node(bdata, pos, max, reserve, flags); if (reserve && err) { mark_bootmem(start, pos, 0, 0); return err; } |
223e8dc92 bootmem: reorder ... |
300 |
|
e2bf3cae5 bootmem: factor o... |
301 302 303 304 305 |
if (max == end) return 0; pos = bdata->node_low_pfn; } BUG(); |
223e8dc92 bootmem: reorder ... |
306 |
} |
a66fd7dae bootmem: add docu... |
307 308 309 310 311 312 313 314 |
/** * free_bootmem_node - mark a page range as usable * @pgdat: node the range resides on * @physaddr: starting address of the range * @size: size of the range in bytes * * Partial pages will be considered reserved and left as they are. * |
e2bf3cae5 bootmem: factor o... |
315 |
* The range must reside completely on the specified node. |
a66fd7dae bootmem: add docu... |
316 |
*/ |
223e8dc92 bootmem: reorder ... |
317 318 319 |
void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, unsigned long size) { |
e2bf3cae5 bootmem: factor o... |
320 321 322 323 324 325 |
unsigned long start, end; start = PFN_UP(physaddr); end = PFN_DOWN(physaddr + size); mark_bootmem_node(pgdat->bdata, start, end, 0, 0); |
223e8dc92 bootmem: reorder ... |
326 |
} |
a66fd7dae bootmem: add docu... |
327 328 329 330 331 332 333 |
/** * free_bootmem - mark a page range as usable * @addr: starting address of the range * @size: size of the range in bytes * * Partial pages will be considered reserved and left as they are. * |
e2bf3cae5 bootmem: factor o... |
334 |
* The range must be contiguous but may span node boundaries. |
a66fd7dae bootmem: add docu... |
335 |
*/ |
223e8dc92 bootmem: reorder ... |
336 337 |
void __init free_bootmem(unsigned long addr, unsigned long size) { |
e2bf3cae5 bootmem: factor o... |
338 |
unsigned long start, end; |
a5645a61b mm: allow reserve... |
339 |
|
e2bf3cae5 bootmem: factor o... |
340 341 |
start = PFN_UP(addr); end = PFN_DOWN(addr + size); |
1da177e4c Linux-2.6.12-rc2 |
342 |
|
e2bf3cae5 bootmem: factor o... |
343 |
mark_bootmem(start, end, 0, 0); |
1da177e4c Linux-2.6.12-rc2 |
344 |
} |
a66fd7dae bootmem: add docu... |
345 346 347 348 349 350 351 352 353 |
/** * reserve_bootmem_node - mark a page range as reserved * @pgdat: node the range resides on * @physaddr: starting address of the range * @size: size of the range in bytes * @flags: reservation flags (see linux/bootmem.h) * * Partial pages will be reserved. * |
e2bf3cae5 bootmem: factor o... |
354 |
* The range must reside completely on the specified node. |
a66fd7dae bootmem: add docu... |
355 |
*/ |
223e8dc92 bootmem: reorder ... |
356 357 |
int __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, unsigned long size, int flags) |
1da177e4c Linux-2.6.12-rc2 |
358 |
{ |
e2bf3cae5 bootmem: factor o... |
359 |
unsigned long start, end; |
1da177e4c Linux-2.6.12-rc2 |
360 |
|
e2bf3cae5 bootmem: factor o... |
361 362 363 364 |
start = PFN_DOWN(physaddr); end = PFN_UP(physaddr + size); return mark_bootmem_node(pgdat->bdata, start, end, 1, flags); |
223e8dc92 bootmem: reorder ... |
365 |
} |
5a982cbc7 mm: fix boundary ... |
366 |
|
223e8dc92 bootmem: reorder ... |
367 |
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE |
a66fd7dae bootmem: add docu... |
368 369 370 371 372 373 374 375 |
/** * reserve_bootmem - mark a page range as usable * @addr: starting address of the range * @size: size of the range in bytes * @flags: reservation flags (see linux/bootmem.h) * * Partial pages will be reserved. * |
e2bf3cae5 bootmem: factor o... |
376 |
* The range must be contiguous but may span node boundaries. |
a66fd7dae bootmem: add docu... |
377 |
*/ |
223e8dc92 bootmem: reorder ... |
378 379 380 |
int __init reserve_bootmem(unsigned long addr, unsigned long size, int flags) { |
e2bf3cae5 bootmem: factor o... |
381 |
unsigned long start, end; |
1da177e4c Linux-2.6.12-rc2 |
382 |
|
e2bf3cae5 bootmem: factor o... |
383 384 |
start = PFN_DOWN(addr); end = PFN_UP(addr + size); |
223e8dc92 bootmem: reorder ... |
385 |
|
e2bf3cae5 bootmem: factor o... |
386 |
return mark_bootmem(start, end, 1, flags); |
1da177e4c Linux-2.6.12-rc2 |
387 |
} |
223e8dc92 bootmem: reorder ... |
388 |
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */ |
1da177e4c Linux-2.6.12-rc2 |
389 |
|
481ebd0d7 bootmem: fix alig... |
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
static unsigned long align_idx(struct bootmem_data *bdata, unsigned long idx, unsigned long step) { unsigned long base = bdata->node_min_pfn; /* * Align the index with respect to the node start so that the * combination of both satisfies the requested alignment. */ return ALIGN(base + idx, step) - base; } static unsigned long align_off(struct bootmem_data *bdata, unsigned long off, unsigned long align) { unsigned long base = PFN_PHYS(bdata->node_min_pfn); /* Same as align_idx for byte offsets */ return ALIGN(base + off, align) - base; } |
5f2809e69 bootmem: clean up... |
412 413 414 |
static void * __init alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size, unsigned long align, unsigned long goal, unsigned long limit) |
1da177e4c Linux-2.6.12-rc2 |
415 |
{ |
0f3caba21 bootmem: respect ... |
416 |
unsigned long fallback = 0; |
5f2809e69 bootmem: clean up... |
417 418 419 420 421 |
unsigned long min, max, start, sidx, midx, step; BUG_ON(!size); BUG_ON(align & (align - 1)); BUG_ON(limit && goal + size > limit); |
1da177e4c Linux-2.6.12-rc2 |
422 |
|
7c309a64d [PATCH] enable bo... |
423 424 |
if (!bdata->node_bootmem_map) return NULL; |
2e5237daf bootmem: add debu... |
425 426 427 428 |
bdebug("nid=%td size=%lx [%lu pages] align=%lx goal=%lx limit=%lx ", bdata - bootmem_node_data, size, PAGE_ALIGN(size) >> PAGE_SHIFT, align, goal, limit); |
3560e249a bootmem: replace ... |
429 |
min = bdata->node_min_pfn; |
5f2809e69 bootmem: clean up... |
430 |
max = bdata->node_low_pfn; |
9a2dc04cf mm: offset align ... |
431 |
|
5f2809e69 bootmem: clean up... |
432 433 434 435 436 437 |
goal >>= PAGE_SHIFT; limit >>= PAGE_SHIFT; if (limit && max > limit) max = limit; if (max <= min) |
9a2dc04cf mm: offset align ... |
438 |
return NULL; |
5f2809e69 bootmem: clean up... |
439 |
step = max(align >> PAGE_SHIFT, 1UL); |
281dd25cd [PATCH] swiotlb: ... |
440 |
|
5f2809e69 bootmem: clean up... |
441 442 443 444 |
if (goal && min < goal && goal < max) start = ALIGN(goal, step); else start = ALIGN(min, step); |
1da177e4c Linux-2.6.12-rc2 |
445 |
|
481ebd0d7 bootmem: fix alig... |
446 |
sidx = start - bdata->node_min_pfn; |
3560e249a bootmem: replace ... |
447 |
midx = max - bdata->node_min_pfn; |
1da177e4c Linux-2.6.12-rc2 |
448 |
|
5f2809e69 bootmem: clean up... |
449 |
if (bdata->hint_idx > sidx) { |
0f3caba21 bootmem: respect ... |
450 451 452 453 454 |
/* * Handle the valid case of sidx being zero and still * catch the fallback below. */ fallback = sidx + 1; |
481ebd0d7 bootmem: fix alig... |
455 |
sidx = align_idx(bdata, bdata->hint_idx, step); |
5f2809e69 bootmem: clean up... |
456 |
} |
1da177e4c Linux-2.6.12-rc2 |
457 |
|
5f2809e69 bootmem: clean up... |
458 459 460 461 462 463 |
while (1) { int merge; void *region; unsigned long eidx, i, start_off, end_off; find_block: sidx = find_next_zero_bit(bdata->node_bootmem_map, midx, sidx); |
481ebd0d7 bootmem: fix alig... |
464 |
sidx = align_idx(bdata, sidx, step); |
5f2809e69 bootmem: clean up... |
465 |
eidx = sidx + PFN_UP(size); |
ad09315ca mm: fix alloc_boo... |
466 |
|
5f2809e69 bootmem: clean up... |
467 |
if (sidx >= midx || eidx > midx) |
66d43e98e [PATCH] fix in __... |
468 |
break; |
1da177e4c Linux-2.6.12-rc2 |
469 |
|
5f2809e69 bootmem: clean up... |
470 471 |
for (i = sidx; i < eidx; i++) if (test_bit(i, bdata->node_bootmem_map)) { |
481ebd0d7 bootmem: fix alig... |
472 |
sidx = align_idx(bdata, i, step); |
5f2809e69 bootmem: clean up... |
473 474 475 476 |
if (sidx == i) sidx += step; goto find_block; } |
1da177e4c Linux-2.6.12-rc2 |
477 |
|
627240aaa bootmem allocator... |
478 |
if (bdata->last_end_off & (PAGE_SIZE - 1) && |
5f2809e69 bootmem: clean up... |
479 |
PFN_DOWN(bdata->last_end_off) + 1 == sidx) |
481ebd0d7 bootmem: fix alig... |
480 |
start_off = align_off(bdata, bdata->last_end_off, align); |
5f2809e69 bootmem: clean up... |
481 482 483 484 485 486 487 488 489 490 491 492 |
else start_off = PFN_PHYS(sidx); merge = PFN_DOWN(start_off) < sidx; end_off = start_off + size; bdata->last_end_off = end_off; bdata->hint_idx = PFN_UP(end_off); /* * Reserve the area now: */ |
d747fa4bc bootmem: free/res... |
493 494 495 |
if (__reserve(bdata, PFN_DOWN(start_off) + merge, PFN_UP(end_off), BOOTMEM_EXCLUSIVE)) BUG(); |
5f2809e69 bootmem: clean up... |
496 |
|
3560e249a bootmem: replace ... |
497 498 |
region = phys_to_virt(PFN_PHYS(bdata->node_min_pfn) + start_off); |
5f2809e69 bootmem: clean up... |
499 500 |
memset(region, 0, size); return region; |
1da177e4c Linux-2.6.12-rc2 |
501 |
} |
0f3caba21 bootmem: respect ... |
502 |
if (fallback) { |
481ebd0d7 bootmem: fix alig... |
503 |
sidx = align_idx(bdata, fallback - 1, step); |
0f3caba21 bootmem: respect ... |
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
fallback = 0; goto find_block; } return NULL; } static void * __init ___alloc_bootmem_nopanic(unsigned long size, unsigned long align, unsigned long goal, unsigned long limit) { bootmem_data_t *bdata; restart: list_for_each_entry(bdata, &bdata_list, list) { void *region; if (goal && bdata->node_low_pfn <= PFN_DOWN(goal)) continue; |
3560e249a bootmem: replace ... |
524 |
if (limit && bdata->node_min_pfn >= PFN_DOWN(limit)) |
0f3caba21 bootmem: respect ... |
525 526 527 528 529 530 |
break; region = alloc_bootmem_core(bdata, size, align, goal, limit); if (region) return region; } |
5f2809e69 bootmem: clean up... |
531 532 |
if (goal) { goal = 0; |
0f3caba21 bootmem: respect ... |
533 |
goto restart; |
5f2809e69 bootmem: clean up... |
534 |
} |
2e5237daf bootmem: add debu... |
535 |
|
5f2809e69 bootmem: clean up... |
536 |
return NULL; |
1da177e4c Linux-2.6.12-rc2 |
537 |
} |
a66fd7dae bootmem: add docu... |
538 539 540 541 542 543 544 545 546 547 548 549 550 |
/** * __alloc_bootmem_nopanic - allocate boot memory without panicking * @size: size of the request in bytes * @align: alignment of the region * @goal: preferred starting address of the region * * The goal is dropped if it can not be satisfied and the allocation will * fall back to memory below @goal. * * Allocation may happen on any node in the system. * * Returns NULL on failure. */ |
bb0923a66 [PATCH] bootmem: ... |
551 |
void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align, |
0f3caba21 bootmem: respect ... |
552 |
unsigned long goal) |
1da177e4c Linux-2.6.12-rc2 |
553 |
{ |
0f3caba21 bootmem: respect ... |
554 555 |
return ___alloc_bootmem_nopanic(size, align, goal, 0); } |
1da177e4c Linux-2.6.12-rc2 |
556 |
|
0f3caba21 bootmem: respect ... |
557 558 559 560 561 562 563 564 565 566 567 568 569 |
static void * __init ___alloc_bootmem(unsigned long size, unsigned long align, unsigned long goal, unsigned long limit) { void *mem = ___alloc_bootmem_nopanic(size, align, goal, limit); if (mem) return mem; /* * Whoops, we cannot satisfy the allocation request. */ printk(KERN_ALERT "bootmem alloc of %lu bytes failed! ", size); panic("Out of memory"); |
a8062231d [PATCH] x86_64: H... |
570 571 |
return NULL; } |
1da177e4c Linux-2.6.12-rc2 |
572 |
|
a66fd7dae bootmem: add docu... |
573 574 575 576 577 578 579 580 581 582 583 584 585 |
/** * __alloc_bootmem - allocate boot memory * @size: size of the request in bytes * @align: alignment of the region * @goal: preferred starting address of the region * * The goal is dropped if it can not be satisfied and the allocation will * fall back to memory below @goal. * * Allocation may happen on any node in the system. * * The function panics if the request can not be satisfied. */ |
bb0923a66 [PATCH] bootmem: ... |
586 587 |
void * __init __alloc_bootmem(unsigned long size, unsigned long align, unsigned long goal) |
a8062231d [PATCH] x86_64: H... |
588 |
{ |
0f3caba21 bootmem: respect ... |
589 |
return ___alloc_bootmem(size, align, goal, 0); |
1da177e4c Linux-2.6.12-rc2 |
590 |
} |
4cc278b72 bootmem: Make __a... |
591 592 593 594 595 596 597 598 599 600 601 602 |
static void * __init ___alloc_bootmem_node(bootmem_data_t *bdata, unsigned long size, unsigned long align, unsigned long goal, unsigned long limit) { void *ptr; ptr = alloc_bootmem_core(bdata, size, align, goal, limit); if (ptr) return ptr; return ___alloc_bootmem(size, align, goal, limit); } |
a66fd7dae bootmem: add docu... |
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
/** * __alloc_bootmem_node - allocate boot memory from a specific node * @pgdat: node to allocate from * @size: size of the request in bytes * @align: alignment of the region * @goal: preferred starting address of the region * * The goal is dropped if it can not be satisfied and the allocation will * fall back to memory below @goal. * * Allocation may fall back to any node in the system if the specified node * can not hold the requested memory. * * The function panics if the request can not be satisfied. */ |
bb0923a66 [PATCH] bootmem: ... |
618 619 |
void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal) |
1da177e4c Linux-2.6.12-rc2 |
620 |
{ |
4cc278b72 bootmem: Make __a... |
621 |
return ___alloc_bootmem_node(pgdat->bdata, size, align, goal, 0); |
1da177e4c Linux-2.6.12-rc2 |
622 |
} |
e70260aab memory hotplug: m... |
623 |
#ifdef CONFIG_SPARSEMEM |
a66fd7dae bootmem: add docu... |
624 625 626 627 628 629 630 |
/** * alloc_bootmem_section - allocate boot memory from a specific section * @size: size of the request in bytes * @section_nr: sparse map section to allocate from * * Return NULL on failure. */ |
e70260aab memory hotplug: m... |
631 632 633 |
void * __init alloc_bootmem_section(unsigned long size, unsigned long section_nr) { |
75a56cfe9 bootmem: revisit ... |
634 635 |
bootmem_data_t *bdata; unsigned long pfn, goal, limit; |
e70260aab memory hotplug: m... |
636 637 |
pfn = section_nr_to_pfn(section_nr); |
75a56cfe9 bootmem: revisit ... |
638 639 640 |
goal = pfn << PAGE_SHIFT; limit = section_nr_to_pfn(section_nr + 1) << PAGE_SHIFT; bdata = &bootmem_node_data[early_pfn_to_nid(pfn)]; |
e70260aab memory hotplug: m... |
641 |
|
75a56cfe9 bootmem: revisit ... |
642 |
return alloc_bootmem_core(bdata, size, SMP_CACHE_BYTES, goal, limit); |
e70260aab memory hotplug: m... |
643 644 |
} #endif |
b54bbf7b8 mm: introduce non... |
645 646 647 648 649 650 651 652 653 654 655 |
void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal) { void *ptr; ptr = alloc_bootmem_core(pgdat->bdata, size, align, goal, 0); if (ptr) return ptr; return __alloc_bootmem_nopanic(size, align, goal); } |
dfd54cbcc [PATCH] bootmem: ... |
656 657 658 |
#ifndef ARCH_LOW_ADDRESS_LIMIT #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL #endif |
008857c1a [PATCH] Cleanup b... |
659 |
|
a66fd7dae bootmem: add docu... |
660 661 662 663 664 665 666 667 668 669 670 671 672 |
/** * __alloc_bootmem_low - allocate low boot memory * @size: size of the request in bytes * @align: alignment of the region * @goal: preferred starting address of the region * * The goal is dropped if it can not be satisfied and the allocation will * fall back to memory below @goal. * * Allocation may happen on any node in the system. * * The function panics if the request can not be satisfied. */ |
bb0923a66 [PATCH] bootmem: ... |
673 674 |
void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, unsigned long goal) |
008857c1a [PATCH] Cleanup b... |
675 |
{ |
0f3caba21 bootmem: respect ... |
676 |
return ___alloc_bootmem(size, align, goal, ARCH_LOW_ADDRESS_LIMIT); |
008857c1a [PATCH] Cleanup b... |
677 |
} |
a66fd7dae bootmem: add docu... |
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
/** * __alloc_bootmem_low_node - allocate low boot memory from a specific node * @pgdat: node to allocate from * @size: size of the request in bytes * @align: alignment of the region * @goal: preferred starting address of the region * * The goal is dropped if it can not be satisfied and the allocation will * fall back to memory below @goal. * * Allocation may fall back to any node in the system if the specified node * can not hold the requested memory. * * The function panics if the request can not be satisfied. */ |
008857c1a [PATCH] Cleanup b... |
693 694 695 |
void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal) { |
4cc278b72 bootmem: Make __a... |
696 697 |
return ___alloc_bootmem_node(pgdat->bdata, size, align, goal, ARCH_LOW_ADDRESS_LIMIT); |
008857c1a [PATCH] Cleanup b... |
698 |
} |