diff options
author | Johannes Weiner <hannes@cmpxchg.org> | 2012-05-29 18:06:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-29 19:22:22 -0400 |
commit | ba539868331874da02017e8dda8ed5b86af6d21a (patch) | |
tree | 27056839b40648fe3e9d121411e4745417587e89 /mm | |
parent | 2c478eae96501163c5c5d5f682bba4d34a7ea1d4 (diff) |
mm: nobootmem: unify allocation policy of (non-)panicking node allocations
While the panicking node-specific allocation function tries to satisfy
node+goal, goal, node, anywhere, the non-panicking function still does
node+goal, goal, anywhere.
Make it simpler: define the panicking version in terms of the non-panicking
one, like the node-agnostic interface, so they always behave the same way
apart from how to deal with allocation failure.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/nobootmem.c | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/mm/nobootmem.c b/mm/nobootmem.c index cca76207e61a..9f4048149f64 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c | |||
@@ -274,6 +274,57 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align, | |||
274 | return ___alloc_bootmem(size, align, goal, limit); | 274 | return ___alloc_bootmem(size, align, goal, limit); |
275 | } | 275 | } |
276 | 276 | ||
277 | static void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat, | ||
278 | unsigned long size, | ||
279 | unsigned long align, | ||
280 | unsigned long goal, | ||
281 | unsigned long limit) | ||
282 | { | ||
283 | void *ptr; | ||
284 | |||
285 | again: | ||
286 | ptr = __alloc_memory_core_early(pgdat->node_id, size, align, | ||
287 | goal, limit); | ||
288 | if (ptr) | ||
289 | return ptr; | ||
290 | |||
291 | ptr = __alloc_memory_core_early(MAX_NUMNODES, size, align, | ||
292 | goal, limit); | ||
293 | if (ptr) | ||
294 | return ptr; | ||
295 | |||
296 | if (goal) { | ||
297 | goal = 0; | ||
298 | goto again; | ||
299 | } | ||
300 | |||
301 | return NULL; | ||
302 | } | ||
303 | |||
304 | void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size, | ||
305 | unsigned long align, unsigned long goal) | ||
306 | { | ||
307 | if (WARN_ON_ONCE(slab_is_available())) | ||
308 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); | ||
309 | |||
310 | return ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, 0); | ||
311 | } | ||
312 | |||
313 | void * __init ___alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, | ||
314 | unsigned long align, unsigned long goal, | ||
315 | unsigned long limit) | ||
316 | { | ||
317 | void *ptr; | ||
318 | |||
319 | ptr = ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, limit); | ||
320 | if (ptr) | ||
321 | return ptr; | ||
322 | |||
323 | printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size); | ||
324 | panic("Out of memory"); | ||
325 | return NULL; | ||
326 | } | ||
327 | |||
277 | /** | 328 | /** |
278 | * __alloc_bootmem_node - allocate boot memory from a specific node | 329 | * __alloc_bootmem_node - allocate boot memory from a specific node |
279 | * @pgdat: node to allocate from | 330 | * @pgdat: node to allocate from |
@@ -292,30 +343,10 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align, | |||
292 | void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, | 343 | void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, |
293 | unsigned long align, unsigned long goal) | 344 | unsigned long align, unsigned long goal) |
294 | { | 345 | { |
295 | void *ptr; | ||
296 | |||
297 | if (WARN_ON_ONCE(slab_is_available())) | 346 | if (WARN_ON_ONCE(slab_is_available())) |
298 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); | 347 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
299 | 348 | ||
300 | again: | 349 | return ___alloc_bootmem_node(pgdat, size, align, goal, 0); |
301 | ptr = __alloc_memory_core_early(pgdat->node_id, size, align, | ||
302 | goal, -1ULL); | ||
303 | if (ptr) | ||
304 | return ptr; | ||
305 | |||
306 | ptr = __alloc_memory_core_early(MAX_NUMNODES, size, align, | ||
307 | goal, -1ULL); | ||
308 | if (ptr) | ||
309 | return ptr; | ||
310 | |||
311 | if (goal) { | ||
312 | goal = 0; | ||
313 | goto again; | ||
314 | } | ||
315 | |||
316 | printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size); | ||
317 | panic("Out of memory"); | ||
318 | return NULL; | ||
319 | } | 350 | } |
320 | 351 | ||
321 | void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size, | 352 | void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size, |
@@ -346,22 +377,6 @@ void * __init alloc_bootmem_section(unsigned long size, | |||
346 | } | 377 | } |
347 | #endif | 378 | #endif |
348 | 379 | ||
349 | void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size, | ||
350 | unsigned long align, unsigned long goal) | ||
351 | { | ||
352 | void *ptr; | ||
353 | |||
354 | if (WARN_ON_ONCE(slab_is_available())) | ||
355 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); | ||
356 | |||
357 | ptr = __alloc_memory_core_early(pgdat->node_id, size, align, | ||
358 | goal, -1ULL); | ||
359 | if (ptr) | ||
360 | return ptr; | ||
361 | |||
362 | return __alloc_bootmem_nopanic(size, align, goal); | ||
363 | } | ||
364 | |||
365 | #ifndef ARCH_LOW_ADDRESS_LIMIT | 380 | #ifndef ARCH_LOW_ADDRESS_LIMIT |
366 | #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL | 381 | #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL |
367 | #endif | 382 | #endif |
@@ -403,22 +418,9 @@ void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, | |||
403 | void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size, | 418 | void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size, |
404 | unsigned long align, unsigned long goal) | 419 | unsigned long align, unsigned long goal) |
405 | { | 420 | { |
406 | void *ptr; | ||
407 | |||
408 | if (WARN_ON_ONCE(slab_is_available())) | 421 | if (WARN_ON_ONCE(slab_is_available())) |
409 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); | 422 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
410 | 423 | ||
411 | ptr = __alloc_memory_core_early(pgdat->node_id, size, align, | 424 | return ___alloc_bootmem_node(pgdat, size, align, goal, |
412 | goal, ARCH_LOW_ADDRESS_LIMIT); | 425 | ARCH_LOW_ADDRESS_LIMIT); |
413 | if (ptr) | ||
414 | return ptr; | ||
415 | |||
416 | ptr = __alloc_memory_core_early(MAX_NUMNODES, size, align, | ||
417 | goal, ARCH_LOW_ADDRESS_LIMIT); | ||
418 | if (ptr) | ||
419 | return ptr; | ||
420 | |||
421 | printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size); | ||
422 | panic("Out of memory"); | ||
423 | return NULL; | ||
424 | } | 426 | } |