Blame view
mm/bootmem.c
20.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> |
5a0e3ad6a include cleanup: ... |
13 |
#include <linux/slab.h> |
1da177e4c Linux-2.6.12-rc2 |
14 |
#include <linux/bootmem.h> |
b95f1b31b mm: Map most file... |
15 |
#include <linux/export.h> |
ec3a354bd kmemleak: Add cal... |
16 |
#include <linux/kmemleak.h> |
08677214e x86: Make 64 bit ... |
17 |
#include <linux/range.h> |
72d7c3b33 x86: Use memblock... |
18 |
#include <linux/memblock.h> |
e786e86a5 [PATCH] bootmem: ... |
19 20 |
#include <asm/bug.h> |
1da177e4c Linux-2.6.12-rc2 |
21 |
#include <asm/io.h> |
dfd54cbcc [PATCH] bootmem: ... |
22 |
#include <asm/processor.h> |
e786e86a5 [PATCH] bootmem: ... |
23 |
|
1da177e4c Linux-2.6.12-rc2 |
24 |
#include "internal.h" |
e782ab421 bootmem: Move con... |
25 26 27 28 29 30 |
#ifndef CONFIG_NEED_MULTIPLE_NODES struct pglist_data __refdata contig_page_data = { .bdata = &bootmem_node_data[0] }; EXPORT_SYMBOL(contig_page_data); #endif |
1da177e4c Linux-2.6.12-rc2 |
31 32 33 |
unsigned long max_low_pfn; unsigned long min_low_pfn; unsigned long max_pfn; |
b61bfa3c4 mm: move bootmem ... |
34 |
bootmem_data_t bootmem_node_data[MAX_NUMNODES] __initdata; |
636cc40cb bootmem: revisit ... |
35 |
static struct list_head bdata_list __initdata = LIST_HEAD_INIT(bdata_list); |
2e5237daf bootmem: add debu... |
36 37 38 39 40 41 42 43 44 45 46 47 48 |
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... |
49 |
__func__, ## args); \ |
2e5237daf bootmem: add debu... |
50 |
}) |
df049a5f4 bootmem: revisit ... |
51 |
static unsigned long __init bootmap_bytes(unsigned long pages) |
223e8dc92 bootmem: reorder ... |
52 |
{ |
9571a9829 bootmem: micro op... |
53 |
unsigned long bytes = DIV_ROUND_UP(pages, 8); |
223e8dc92 bootmem: reorder ... |
54 |
|
df049a5f4 bootmem: revisit ... |
55 |
return ALIGN(bytes, sizeof(long)); |
223e8dc92 bootmem: reorder ... |
56 |
} |
a66fd7dae bootmem: add docu... |
57 58 59 60 |
/** * bootmem_bootmap_pages - calculate bitmap size in pages * @pages: number of pages the bitmap has to represent */ |
f71bf0cac [PATCH] bootmem: ... |
61 |
unsigned long __init bootmem_bootmap_pages(unsigned long pages) |
1da177e4c Linux-2.6.12-rc2 |
62 |
{ |
df049a5f4 bootmem: revisit ... |
63 |
unsigned long bytes = bootmap_bytes(pages); |
1da177e4c Linux-2.6.12-rc2 |
64 |
|
df049a5f4 bootmem: revisit ... |
65 |
return PAGE_ALIGN(bytes) >> PAGE_SHIFT; |
1da177e4c Linux-2.6.12-rc2 |
66 |
} |
f71bf0cac [PATCH] bootmem: ... |
67 |
|
679bc9fbb [PATCH] for_each_... |
68 69 70 |
/* * link bdata in order */ |
69d49e681 [PATCH] bootmem: ... |
71 |
static void __init link_bootmem(bootmem_data_t *bdata) |
679bc9fbb [PATCH] for_each_... |
72 |
{ |
636cc40cb bootmem: revisit ... |
73 |
struct list_head *iter; |
f71bf0cac [PATCH] bootmem: ... |
74 |
|
636cc40cb bootmem: revisit ... |
75 76 77 78 |
list_for_each(iter, &bdata_list) { bootmem_data_t *ent; ent = list_entry(iter, bootmem_data_t, list); |
3560e249a bootmem: replace ... |
79 |
if (bdata->node_min_pfn < ent->node_min_pfn) |
636cc40cb bootmem: revisit ... |
80 |
break; |
679bc9fbb [PATCH] for_each_... |
81 |
} |
636cc40cb bootmem: revisit ... |
82 |
list_add_tail(&bdata->list, iter); |
679bc9fbb [PATCH] for_each_... |
83 |
} |
bbc7b92e3 [PATCH] bootmem: ... |
84 |
/* |
1da177e4c Linux-2.6.12-rc2 |
85 86 |
* Called once to set up the allocator itself. */ |
8ae044630 mm: normalize int... |
87 |
static unsigned long __init init_bootmem_core(bootmem_data_t *bdata, |
1da177e4c Linux-2.6.12-rc2 |
88 89 |
unsigned long mapstart, unsigned long start, unsigned long end) { |
bbc7b92e3 [PATCH] bootmem: ... |
90 |
unsigned long mapsize; |
1da177e4c Linux-2.6.12-rc2 |
91 |
|
2dbb51c49 mm: make defensiv... |
92 |
mminit_validate_memmodel_limits(&start, &end); |
bbc7b92e3 [PATCH] bootmem: ... |
93 |
bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart)); |
3560e249a bootmem: replace ... |
94 |
bdata->node_min_pfn = start; |
1da177e4c Linux-2.6.12-rc2 |
95 |
bdata->node_low_pfn = end; |
679bc9fbb [PATCH] for_each_... |
96 |
link_bootmem(bdata); |
1da177e4c Linux-2.6.12-rc2 |
97 98 99 100 101 |
/* * Initially all pages are reserved - setup_arch() has to * register free RAM areas explicitly. */ |
df049a5f4 bootmem: revisit ... |
102 |
mapsize = bootmap_bytes(end - start); |
1da177e4c Linux-2.6.12-rc2 |
103 |
memset(bdata->node_bootmem_map, 0xff, mapsize); |
2e5237daf bootmem: add debu... |
104 105 106 |
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 |
107 108 |
return mapsize; } |
a66fd7dae bootmem: add docu... |
109 110 111 112 113 114 115 116 117 |
/** * 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 ... |
118 119 120 121 122 |
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... |
123 124 125 126 127 128 129 |
/** * 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 ... |
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); } |
093258732 bootmem: Separate... |
136 |
|
9f993ac3f bootmem: Add free... |
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
/* * free_bootmem_late - free bootmem pages directly to page allocator * @addr: starting address of the range * @size: size of the range in bytes * * This is only useful when the bootmem allocator has already been torn * down, but we are still initializing the system. Pages are given directly * to the page allocator, no bootmem metadata is updated because it is gone. */ void __init free_bootmem_late(unsigned long addr, unsigned long size) { unsigned long cursor, end; kmemleak_free_part(__va(addr), size); cursor = PFN_UP(addr); end = PFN_DOWN(addr + size); for (; cursor < end; cursor++) { __free_pages_bootmem(pfn_to_page(cursor), 0); totalram_pages++; } } |
223e8dc92 bootmem: reorder ... |
160 161 162 |
static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata) { struct page *page; |
41546c174 bootmem: clean up... |
163 164 165 166 |
unsigned long start, end, pages, count = 0; if (!bdata->node_bootmem_map) return 0; |
3560e249a bootmem: replace ... |
167 |
start = bdata->node_min_pfn; |
41546c174 bootmem: clean up... |
168 |
end = bdata->node_low_pfn; |
799f933a8 mm: bootmem: try ... |
169 170 171 |
bdebug("nid=%td start=%lx end=%lx ", bdata - bootmem_node_data, start, end); |
223e8dc92 bootmem: reorder ... |
172 |
|
41546c174 bootmem: clean up... |
173 174 |
while (start < end) { unsigned long *map, idx, vec; |
223e8dc92 bootmem: reorder ... |
175 |
|
41546c174 bootmem: clean up... |
176 |
map = bdata->node_bootmem_map; |
3560e249a bootmem: replace ... |
177 |
idx = start - bdata->node_min_pfn; |
41546c174 bootmem: clean up... |
178 |
vec = ~map[idx / BITS_PER_LONG]; |
799f933a8 mm: bootmem: try ... |
179 180 181 182 183 184 |
/* * If we have a properly aligned and fully unreserved * BITS_PER_LONG block of pages in front of us, free * it in one go. */ if (IS_ALIGNED(start, BITS_PER_LONG) && vec == ~0UL) { |
41546c174 bootmem: clean up... |
185 186 187 |
int order = ilog2(BITS_PER_LONG); __free_pages_bootmem(pfn_to_page(start), order); |
223e8dc92 bootmem: reorder ... |
188 |
count += BITS_PER_LONG; |
799f933a8 mm: bootmem: try ... |
189 |
start += BITS_PER_LONG; |
41546c174 bootmem: clean up... |
190 191 192 193 194 195 |
} else { unsigned long off = 0; while (vec && off < BITS_PER_LONG) { if (vec & 1) { page = pfn_to_page(start + off); |
223e8dc92 bootmem: reorder ... |
196 |
__free_pages_bootmem(page, 0); |
41546c174 bootmem: clean up... |
197 |
count++; |
223e8dc92 bootmem: reorder ... |
198 |
} |
41546c174 bootmem: clean up... |
199 200 |
vec >>= 1; off++; |
223e8dc92 bootmem: reorder ... |
201 |
} |
799f933a8 mm: bootmem: try ... |
202 |
start = ALIGN(start + 1, BITS_PER_LONG); |
223e8dc92 bootmem: reorder ... |
203 |
} |
223e8dc92 bootmem: reorder ... |
204 |
} |
223e8dc92 bootmem: reorder ... |
205 |
page = virt_to_page(bdata->node_bootmem_map); |
3560e249a bootmem: replace ... |
206 |
pages = bdata->node_low_pfn - bdata->node_min_pfn; |
41546c174 bootmem: clean up... |
207 208 209 210 |
pages = bootmem_bootmap_pages(pages); count += pages; while (pages--) __free_pages_bootmem(page++, 0); |
223e8dc92 bootmem: reorder ... |
211 |
|
2e5237daf bootmem: add debu... |
212 213 |
bdebug("nid=%td released=%lx ", bdata - bootmem_node_data, count); |
223e8dc92 bootmem: reorder ... |
214 215 |
return count; } |
a66fd7dae bootmem: add docu... |
216 217 218 219 220 221 |
/** * 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 ... |
222 223 224 225 226 |
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... |
227 228 229 230 231 |
/** * free_all_bootmem - release free pages to the buddy allocator * * Returns the number of pages actually released. */ |
223e8dc92 bootmem: reorder ... |
232 233 |
unsigned long __init free_all_bootmem(void) { |
aa235fc71 bootmem, x86: Fix... |
234 235 236 237 238 239 240 |
unsigned long total_pages = 0; bootmem_data_t *bdata; list_for_each_entry(bdata, &bdata_list, list) total_pages += free_all_bootmem_core(bdata); return total_pages; |
223e8dc92 bootmem: reorder ... |
241 |
} |
d747fa4bc bootmem: free/res... |
242 243 244 245 246 247 248 |
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 ... |
249 250 |
sidx + bdata->node_min_pfn, eidx + bdata->node_min_pfn); |
d747fa4bc bootmem: free/res... |
251 |
|
e2bf3cae5 bootmem: factor o... |
252 253 |
if (bdata->hint_idx > sidx) bdata->hint_idx = sidx; |
d747fa4bc bootmem: free/res... |
254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
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 ... |
268 269 |
sidx + bdata->node_min_pfn, eidx + bdata->node_min_pfn, |
d747fa4bc bootmem: free/res... |
270 271 272 273 274 275 276 277 278 279 |
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 ... |
280 |
idx + bdata->node_min_pfn); |
d747fa4bc bootmem: free/res... |
281 282 283 |
} return 0; } |
e2bf3cae5 bootmem: factor o... |
284 285 286 |
static int __init mark_bootmem_node(bootmem_data_t *bdata, unsigned long start, unsigned long end, int reserve, int flags) |
223e8dc92 bootmem: reorder ... |
287 288 |
{ unsigned long sidx, eidx; |
223e8dc92 bootmem: reorder ... |
289 |
|
e2bf3cae5 bootmem: factor o... |
290 291 292 |
bdebug("nid=%td start=%lx end=%lx reserve=%d flags=%x ", bdata - bootmem_node_data, start, end, reserve, flags); |
223e8dc92 bootmem: reorder ... |
293 |
|
3560e249a bootmem: replace ... |
294 |
BUG_ON(start < bdata->node_min_pfn); |
e2bf3cae5 bootmem: factor o... |
295 |
BUG_ON(end > bdata->node_low_pfn); |
223e8dc92 bootmem: reorder ... |
296 |
|
3560e249a bootmem: replace ... |
297 298 |
sidx = start - bdata->node_min_pfn; eidx = end - bdata->node_min_pfn; |
223e8dc92 bootmem: reorder ... |
299 |
|
e2bf3cae5 bootmem: factor o... |
300 301 |
if (reserve) return __reserve(bdata, sidx, eidx, flags); |
223e8dc92 bootmem: reorder ... |
302 |
else |
e2bf3cae5 bootmem: factor o... |
303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
__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 ... |
317 318 |
if (pos < bdata->node_min_pfn || pos >= bdata->node_low_pfn) { |
e2bf3cae5 bootmem: factor o... |
319 320 321 322 323 |
BUG_ON(pos != start); continue; } max = min(bdata->node_low_pfn, end); |
223e8dc92 bootmem: reorder ... |
324 |
|
e2bf3cae5 bootmem: factor o... |
325 326 327 328 329 |
err = mark_bootmem_node(bdata, pos, max, reserve, flags); if (reserve && err) { mark_bootmem(start, pos, 0, 0); return err; } |
223e8dc92 bootmem: reorder ... |
330 |
|
e2bf3cae5 bootmem: factor o... |
331 332 333 334 335 |
if (max == end) return 0; pos = bdata->node_low_pfn; } BUG(); |
223e8dc92 bootmem: reorder ... |
336 |
} |
a66fd7dae bootmem: add docu... |
337 338 339 340 341 342 343 344 |
/** * 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... |
345 |
* The range must reside completely on the specified node. |
a66fd7dae bootmem: add docu... |
346 |
*/ |
223e8dc92 bootmem: reorder ... |
347 348 349 |
void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, unsigned long size) { |
e2bf3cae5 bootmem: factor o... |
350 |
unsigned long start, end; |
ec3a354bd kmemleak: Add cal... |
351 |
kmemleak_free_part(__va(physaddr), size); |
e2bf3cae5 bootmem: factor o... |
352 353 354 355 |
start = PFN_UP(physaddr); end = PFN_DOWN(physaddr + size); mark_bootmem_node(pgdat->bdata, start, end, 0, 0); |
223e8dc92 bootmem: reorder ... |
356 |
} |
a66fd7dae bootmem: add docu... |
357 358 359 360 361 362 363 |
/** * 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... |
364 |
* The range must be contiguous but may span node boundaries. |
a66fd7dae bootmem: add docu... |
365 |
*/ |
223e8dc92 bootmem: reorder ... |
366 367 |
void __init free_bootmem(unsigned long addr, unsigned long size) { |
e2bf3cae5 bootmem: factor o... |
368 |
unsigned long start, end; |
a5645a61b mm: allow reserve... |
369 |
|
ec3a354bd kmemleak: Add cal... |
370 |
kmemleak_free_part(__va(addr), size); |
e2bf3cae5 bootmem: factor o... |
371 372 |
start = PFN_UP(addr); end = PFN_DOWN(addr + size); |
1da177e4c Linux-2.6.12-rc2 |
373 |
|
e2bf3cae5 bootmem: factor o... |
374 |
mark_bootmem(start, end, 0, 0); |
1da177e4c Linux-2.6.12-rc2 |
375 |
} |
a66fd7dae bootmem: add docu... |
376 377 378 379 380 381 382 383 384 |
/** * 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... |
385 |
* The range must reside completely on the specified node. |
a66fd7dae bootmem: add docu... |
386 |
*/ |
223e8dc92 bootmem: reorder ... |
387 388 |
int __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, unsigned long size, int flags) |
1da177e4c Linux-2.6.12-rc2 |
389 |
{ |
e2bf3cae5 bootmem: factor o... |
390 |
unsigned long start, end; |
1da177e4c Linux-2.6.12-rc2 |
391 |
|
e2bf3cae5 bootmem: factor o... |
392 393 394 395 |
start = PFN_DOWN(physaddr); end = PFN_UP(physaddr + size); return mark_bootmem_node(pgdat->bdata, start, end, 1, flags); |
223e8dc92 bootmem: reorder ... |
396 |
} |
5a982cbc7 mm: fix boundary ... |
397 |
|
a66fd7dae bootmem: add docu... |
398 399 400 401 402 403 404 405 |
/** * 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... |
406 |
* The range must be contiguous but may span node boundaries. |
a66fd7dae bootmem: add docu... |
407 |
*/ |
223e8dc92 bootmem: reorder ... |
408 409 410 |
int __init reserve_bootmem(unsigned long addr, unsigned long size, int flags) { |
e2bf3cae5 bootmem: factor o... |
411 |
unsigned long start, end; |
1da177e4c Linux-2.6.12-rc2 |
412 |
|
e2bf3cae5 bootmem: factor o... |
413 414 |
start = PFN_DOWN(addr); end = PFN_UP(addr + size); |
223e8dc92 bootmem: reorder ... |
415 |
|
e2bf3cae5 bootmem: factor o... |
416 |
return mark_bootmem(start, end, 1, flags); |
1da177e4c Linux-2.6.12-rc2 |
417 |
} |
f88eff74a bootmem, x86: Add... |
418 419 420 421 422 |
int __weak __init reserve_bootmem_generic(unsigned long phys, unsigned long len, int flags) { return reserve_bootmem(phys, len, flags); } |
8aa043d74 mm/bootmem.c: pro... |
423 424 |
static unsigned long __init align_idx(struct bootmem_data *bdata, unsigned long idx, unsigned long step) |
481ebd0d7 bootmem: fix alig... |
425 426 427 428 429 430 431 432 433 434 |
{ 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; } |
8aa043d74 mm/bootmem.c: pro... |
435 436 |
static unsigned long __init align_off(struct bootmem_data *bdata, unsigned long off, unsigned long align) |
481ebd0d7 bootmem: fix alig... |
437 438 439 440 441 442 443 |
{ unsigned long base = PFN_PHYS(bdata->node_min_pfn); /* Same as align_idx for byte offsets */ return ALIGN(base + off, align) - base; } |
d0c4f5702 bootmem, x86: fur... |
444 445 446 |
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 |
447 |
{ |
0f3caba21 bootmem: respect ... |
448 |
unsigned long fallback = 0; |
5f2809e69 bootmem: clean up... |
449 |
unsigned long min, max, start, sidx, midx, step; |
594fe1a04 bootmem: print re... |
450 451 452 453 |
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); |
5f2809e69 bootmem: clean up... |
454 455 456 |
BUG_ON(!size); BUG_ON(align & (align - 1)); BUG_ON(limit && goal + size > limit); |
1da177e4c Linux-2.6.12-rc2 |
457 |
|
7c309a64d [PATCH] enable bo... |
458 459 |
if (!bdata->node_bootmem_map) return NULL; |
3560e249a bootmem: replace ... |
460 |
min = bdata->node_min_pfn; |
5f2809e69 bootmem: clean up... |
461 |
max = bdata->node_low_pfn; |
9a2dc04cf mm: offset align ... |
462 |
|
5f2809e69 bootmem: clean up... |
463 464 465 466 467 468 |
goal >>= PAGE_SHIFT; limit >>= PAGE_SHIFT; if (limit && max > limit) max = limit; if (max <= min) |
9a2dc04cf mm: offset align ... |
469 |
return NULL; |
5f2809e69 bootmem: clean up... |
470 |
step = max(align >> PAGE_SHIFT, 1UL); |
281dd25cd [PATCH] swiotlb: ... |
471 |
|
5f2809e69 bootmem: clean up... |
472 473 474 475 |
if (goal && min < goal && goal < max) start = ALIGN(goal, step); else start = ALIGN(min, step); |
1da177e4c Linux-2.6.12-rc2 |
476 |
|
481ebd0d7 bootmem: fix alig... |
477 |
sidx = start - bdata->node_min_pfn; |
3560e249a bootmem: replace ... |
478 |
midx = max - bdata->node_min_pfn; |
1da177e4c Linux-2.6.12-rc2 |
479 |
|
5f2809e69 bootmem: clean up... |
480 |
if (bdata->hint_idx > sidx) { |
0f3caba21 bootmem: respect ... |
481 482 483 484 485 |
/* * Handle the valid case of sidx being zero and still * catch the fallback below. */ fallback = sidx + 1; |
481ebd0d7 bootmem: fix alig... |
486 |
sidx = align_idx(bdata, bdata->hint_idx, step); |
5f2809e69 bootmem: clean up... |
487 |
} |
1da177e4c Linux-2.6.12-rc2 |
488 |
|
5f2809e69 bootmem: clean up... |
489 490 491 492 493 494 |
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... |
495 |
sidx = align_idx(bdata, sidx, step); |
5f2809e69 bootmem: clean up... |
496 |
eidx = sidx + PFN_UP(size); |
ad09315ca mm: fix alloc_boo... |
497 |
|
5f2809e69 bootmem: clean up... |
498 |
if (sidx >= midx || eidx > midx) |
66d43e98e [PATCH] fix in __... |
499 |
break; |
1da177e4c Linux-2.6.12-rc2 |
500 |
|
5f2809e69 bootmem: clean up... |
501 502 |
for (i = sidx; i < eidx; i++) if (test_bit(i, bdata->node_bootmem_map)) { |
481ebd0d7 bootmem: fix alig... |
503 |
sidx = align_idx(bdata, i, step); |
5f2809e69 bootmem: clean up... |
504 505 506 507 |
if (sidx == i) sidx += step; goto find_block; } |
1da177e4c Linux-2.6.12-rc2 |
508 |
|
627240aaa bootmem allocator... |
509 |
if (bdata->last_end_off & (PAGE_SIZE - 1) && |
5f2809e69 bootmem: clean up... |
510 |
PFN_DOWN(bdata->last_end_off) + 1 == sidx) |
481ebd0d7 bootmem: fix alig... |
511 |
start_off = align_off(bdata, bdata->last_end_off, align); |
5f2809e69 bootmem: clean up... |
512 513 514 515 516 517 518 519 520 521 522 523 |
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... |
524 525 526 |
if (__reserve(bdata, PFN_DOWN(start_off) + merge, PFN_UP(end_off), BOOTMEM_EXCLUSIVE)) BUG(); |
5f2809e69 bootmem: clean up... |
527 |
|
3560e249a bootmem: replace ... |
528 529 |
region = phys_to_virt(PFN_PHYS(bdata->node_min_pfn) + start_off); |
5f2809e69 bootmem: clean up... |
530 |
memset(region, 0, size); |
008139d91 kmemleak: Do not ... |
531 532 533 534 535 |
/* * The min_count is set to 0 so that bootmem allocated blocks * are never reported as leaks. */ kmemleak_alloc(region, size, 0, 0); |
5f2809e69 bootmem: clean up... |
536 |
return region; |
1da177e4c Linux-2.6.12-rc2 |
537 |
} |
0f3caba21 bootmem: respect ... |
538 |
if (fallback) { |
481ebd0d7 bootmem: fix alig... |
539 |
sidx = align_idx(bdata, fallback - 1, step); |
0f3caba21 bootmem: respect ... |
540 541 542 543 544 545 |
fallback = 0; goto find_block; } return NULL; } |
d0c4f5702 bootmem, x86: fur... |
546 547 548 549 |
static void * __init alloc_arch_preferred_bootmem(bootmem_data_t *bdata, unsigned long size, unsigned long align, unsigned long goal, unsigned long limit) { |
441c7e0a2 bootmem: use slab... |
550 551 |
if (WARN_ON_ONCE(slab_is_available())) return kzalloc(size, GFP_NOWAIT); |
d0c4f5702 bootmem, x86: fur... |
552 |
#ifdef CONFIG_HAVE_ARCH_BOOTMEM |
433f13a72 bootmem.c: avoid ... |
553 554 555 556 557 558 559 560 561 |
{ bootmem_data_t *p_bdata; p_bdata = bootmem_arch_preferred_node(bdata, size, align, goal, limit); if (p_bdata) return alloc_bootmem_core(p_bdata, size, align, goal, limit); } |
d0c4f5702 bootmem, x86: fur... |
562 563 564 |
#endif return NULL; } |
0f3caba21 bootmem: respect ... |
565 566 567 568 569 570 |
static void * __init ___alloc_bootmem_nopanic(unsigned long size, unsigned long align, unsigned long goal, unsigned long limit) { bootmem_data_t *bdata; |
d0c4f5702 bootmem, x86: fur... |
571 |
void *region; |
0f3caba21 bootmem: respect ... |
572 573 |
restart: |
d0c4f5702 bootmem, x86: fur... |
574 575 576 |
region = alloc_arch_preferred_bootmem(NULL, size, align, goal, limit); if (region) return region; |
0f3caba21 bootmem: respect ... |
577 |
|
d0c4f5702 bootmem, x86: fur... |
578 |
list_for_each_entry(bdata, &bdata_list, list) { |
0f3caba21 bootmem: respect ... |
579 580 |
if (goal && bdata->node_low_pfn <= PFN_DOWN(goal)) continue; |
3560e249a bootmem: replace ... |
581 |
if (limit && bdata->node_min_pfn >= PFN_DOWN(limit)) |
0f3caba21 bootmem: respect ... |
582 583 584 585 586 587 |
break; region = alloc_bootmem_core(bdata, size, align, goal, limit); if (region) return region; } |
5f2809e69 bootmem: clean up... |
588 589 |
if (goal) { goal = 0; |
0f3caba21 bootmem: respect ... |
590 |
goto restart; |
5f2809e69 bootmem: clean up... |
591 |
} |
2e5237daf bootmem: add debu... |
592 |
|
5f2809e69 bootmem: clean up... |
593 |
return NULL; |
1da177e4c Linux-2.6.12-rc2 |
594 |
} |
a66fd7dae bootmem: add docu... |
595 596 597 598 599 600 601 602 603 604 605 606 607 |
/** * __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: ... |
608 |
void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align, |
0f3caba21 bootmem: respect ... |
609 |
unsigned long goal) |
1da177e4c Linux-2.6.12-rc2 |
610 |
{ |
08677214e x86: Make 64 bit ... |
611 |
unsigned long limit = 0; |
08677214e x86: Make 64 bit ... |
612 |
return ___alloc_bootmem_nopanic(size, align, goal, limit); |
0f3caba21 bootmem: respect ... |
613 |
} |
1da177e4c Linux-2.6.12-rc2 |
614 |
|
0f3caba21 bootmem: respect ... |
615 616 617 618 619 620 621 622 623 624 625 626 627 |
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... |
628 629 |
return NULL; } |
1da177e4c Linux-2.6.12-rc2 |
630 |
|
a66fd7dae bootmem: add docu... |
631 632 633 634 635 636 637 638 639 640 641 642 643 |
/** * __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: ... |
644 645 |
void * __init __alloc_bootmem(unsigned long size, unsigned long align, unsigned long goal) |
a8062231d [PATCH] x86_64: H... |
646 |
{ |
08677214e x86: Make 64 bit ... |
647 |
unsigned long limit = 0; |
08677214e x86: Make 64 bit ... |
648 |
return ___alloc_bootmem(size, align, goal, limit); |
1da177e4c Linux-2.6.12-rc2 |
649 |
} |
4cc278b72 bootmem: Make __a... |
650 651 652 653 654 |
static void * __init ___alloc_bootmem_node(bootmem_data_t *bdata, unsigned long size, unsigned long align, unsigned long goal, unsigned long limit) { void *ptr; |
d0c4f5702 bootmem, x86: fur... |
655 656 657 |
ptr = alloc_arch_preferred_bootmem(bdata, size, align, goal, limit); if (ptr) return ptr; |
4cc278b72 bootmem: Make __a... |
658 659 660 661 662 663 |
ptr = alloc_bootmem_core(bdata, size, align, goal, limit); if (ptr) return ptr; return ___alloc_bootmem(size, align, goal, limit); } |
a66fd7dae bootmem: add docu... |
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
/** * __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: ... |
679 680 |
void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal) |
1da177e4c Linux-2.6.12-rc2 |
681 |
{ |
c91c4773b bootmem: fix slab... |
682 683 |
if (WARN_ON_ONCE(slab_is_available())) return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
093258732 bootmem: Separate... |
684 |
return ___alloc_bootmem_node(pgdat->bdata, size, align, goal, 0); |
08677214e x86: Make 64 bit ... |
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
} void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal) { #ifdef MAX_DMA32_PFN unsigned long end_pfn; if (WARN_ON_ONCE(slab_is_available())) return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); /* update goal according ...MAX_DMA32_PFN */ end_pfn = pgdat->node_start_pfn + pgdat->node_spanned_pages; if (end_pfn > MAX_DMA32_PFN + (128 >> (20 - PAGE_SHIFT)) && (goal >> PAGE_SHIFT) < MAX_DMA32_PFN) { void *ptr; unsigned long new_goal; new_goal = MAX_DMA32_PFN << PAGE_SHIFT; |
08677214e x86: Make 64 bit ... |
705 706 |
ptr = alloc_bootmem_core(pgdat->bdata, size, align, new_goal, 0); |
08677214e x86: Make 64 bit ... |
707 708 709 710 711 712 |
if (ptr) return ptr; } #endif return __alloc_bootmem_node(pgdat, size, align, goal); |
1da177e4c Linux-2.6.12-rc2 |
713 |
} |
e70260aab memory hotplug: m... |
714 |
#ifdef CONFIG_SPARSEMEM |
a66fd7dae bootmem: add docu... |
715 716 717 718 719 720 721 |
/** * 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... |
722 723 724 |
void * __init alloc_bootmem_section(unsigned long size, unsigned long section_nr) { |
75a56cfe9 bootmem: revisit ... |
725 726 |
bootmem_data_t *bdata; unsigned long pfn, goal, limit; |
e70260aab memory hotplug: m... |
727 728 |
pfn = section_nr_to_pfn(section_nr); |
75a56cfe9 bootmem: revisit ... |
729 730 731 |
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... |
732 |
|
75a56cfe9 bootmem: revisit ... |
733 |
return alloc_bootmem_core(bdata, size, SMP_CACHE_BYTES, goal, limit); |
e70260aab memory hotplug: m... |
734 735 |
} #endif |
b54bbf7b8 mm: introduce non... |
736 737 738 739 |
void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal) { void *ptr; |
c91c4773b bootmem: fix slab... |
740 741 |
if (WARN_ON_ONCE(slab_is_available())) return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
d0c4f5702 bootmem, x86: fur... |
742 743 744 |
ptr = alloc_arch_preferred_bootmem(pgdat->bdata, size, align, goal, 0); if (ptr) return ptr; |
b54bbf7b8 mm: introduce non... |
745 746 747 748 749 750 |
ptr = alloc_bootmem_core(pgdat->bdata, size, align, goal, 0); if (ptr) return ptr; return __alloc_bootmem_nopanic(size, align, goal); } |
dfd54cbcc [PATCH] bootmem: ... |
751 752 753 |
#ifndef ARCH_LOW_ADDRESS_LIMIT #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL #endif |
008857c1a [PATCH] Cleanup b... |
754 |
|
a66fd7dae bootmem: add docu... |
755 756 757 758 759 760 761 762 763 764 765 766 767 |
/** * __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: ... |
768 769 |
void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, unsigned long goal) |
008857c1a [PATCH] Cleanup b... |
770 |
{ |
0f3caba21 bootmem: respect ... |
771 |
return ___alloc_bootmem(size, align, goal, ARCH_LOW_ADDRESS_LIMIT); |
008857c1a [PATCH] Cleanup b... |
772 |
} |
a66fd7dae bootmem: add docu... |
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 |
/** * __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... |
788 789 790 |
void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal) { |
c91c4773b bootmem: fix slab... |
791 792 |
if (WARN_ON_ONCE(slab_is_available())) return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
093258732 bootmem: Separate... |
793 |
return ___alloc_bootmem_node(pgdat->bdata, size, align, |
b8ab9f820 x86,nobootmem: ma... |
794 |
goal, ARCH_LOW_ADDRESS_LIMIT); |
008857c1a [PATCH] Cleanup b... |
795 |
} |