Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * bootmem - A boot-time physical memory allocator and configurator |
| 3 | * |
| 4 | * Copyright (C) 1999 Ingo Molnar |
| 5 | * 1999 Kanoj Sarcar, SGI |
| 6 | * 2008 Johannes Weiner |
| 7 | * |
| 8 | * Access to this subsystem has to be serialized externally (which is true |
| 9 | * for the boot process anyway). |
| 10 | */ |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/pfn.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/bootmem.h> |
Paul Gortmaker | b95f1b31 | 2011-10-16 02:01:52 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 16 | #include <linux/kmemleak.h> |
| 17 | #include <linux/range.h> |
| 18 | #include <linux/memblock.h> |
| 19 | |
| 20 | #include <asm/bug.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/processor.h> |
| 23 | |
| 24 | #include "internal.h" |
| 25 | |
Yinghai Lu | e782ab4 | 2011-02-24 14:43:06 +0100 | [diff] [blame] | 26 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
| 27 | struct pglist_data __refdata contig_page_data; |
| 28 | EXPORT_SYMBOL(contig_page_data); |
| 29 | #endif |
| 30 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 31 | unsigned long max_low_pfn; |
| 32 | unsigned long min_low_pfn; |
| 33 | unsigned long max_pfn; |
| 34 | |
Yinghai Lu | 8bc1f91 | 2011-02-24 14:43:06 +0100 | [diff] [blame] | 35 | static void * __init __alloc_memory_core_early(int nid, u64 size, u64 align, |
| 36 | u64 goal, u64 limit) |
| 37 | { |
| 38 | void *ptr; |
| 39 | u64 addr; |
Tony Luck | a3f5baf | 2015-06-24 16:58:12 -0700 | [diff] [blame] | 40 | ulong flags = choose_memblock_flags(); |
Yinghai Lu | 8bc1f91 | 2011-02-24 14:43:06 +0100 | [diff] [blame] | 41 | |
| 42 | if (limit > memblock.current_limit) |
| 43 | limit = memblock.current_limit; |
| 44 | |
Tony Luck | a3f5baf | 2015-06-24 16:58:12 -0700 | [diff] [blame] | 45 | again: |
Tony Luck | fc6daaf | 2015-06-24 16:58:09 -0700 | [diff] [blame] | 46 | addr = memblock_find_in_range_node(size, align, goal, limit, nid, |
Tony Luck | a3f5baf | 2015-06-24 16:58:12 -0700 | [diff] [blame] | 47 | flags); |
| 48 | if (!addr && (flags & MEMBLOCK_MIRROR)) { |
| 49 | flags &= ~MEMBLOCK_MIRROR; |
| 50 | pr_warn("Could not allocate %pap bytes of mirrored memory\n", |
| 51 | &size); |
| 52 | goto again; |
| 53 | } |
Tejun Heo | 1f5026a | 2011-07-12 09:58:09 +0200 | [diff] [blame] | 54 | if (!addr) |
Yinghai Lu | 8bc1f91 | 2011-02-24 14:43:06 +0100 | [diff] [blame] | 55 | return NULL; |
| 56 | |
Philipp Hachtmann | 87379ec | 2014-01-23 15:53:10 -0800 | [diff] [blame] | 57 | if (memblock_reserve(addr, size)) |
| 58 | return NULL; |
| 59 | |
Yinghai Lu | 8bc1f91 | 2011-02-24 14:43:06 +0100 | [diff] [blame] | 60 | ptr = phys_to_virt(addr); |
| 61 | memset(ptr, 0, size); |
Yinghai Lu | 8bc1f91 | 2011-02-24 14:43:06 +0100 | [diff] [blame] | 62 | /* |
| 63 | * The min_count is set to 0 so that bootmem allocated blocks |
| 64 | * are never reported as leaks. |
| 65 | */ |
| 66 | kmemleak_alloc(ptr, size, 0, 0); |
| 67 | return ptr; |
| 68 | } |
| 69 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 70 | /* |
| 71 | * free_bootmem_late - free bootmem pages directly to page allocator |
| 72 | * @addr: starting address of the range |
| 73 | * @size: size of the range in bytes |
| 74 | * |
| 75 | * This is only useful when the bootmem allocator has already been torn |
| 76 | * down, but we are still initializing the system. Pages are given directly |
| 77 | * to the page allocator, no bootmem metadata is updated because it is gone. |
| 78 | */ |
| 79 | void __init free_bootmem_late(unsigned long addr, unsigned long size) |
| 80 | { |
| 81 | unsigned long cursor, end; |
| 82 | |
| 83 | kmemleak_free_part(__va(addr), size); |
| 84 | |
| 85 | cursor = PFN_UP(addr); |
| 86 | end = PFN_DOWN(addr + size); |
| 87 | |
| 88 | for (; cursor < end; cursor++) { |
| 89 | __free_pages_bootmem(pfn_to_page(cursor), 0); |
| 90 | totalram_pages++; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static void __init __free_pages_memory(unsigned long start, unsigned long end) |
| 95 | { |
Robin Holt | 309d0b3 | 2013-11-12 15:07:23 -0800 | [diff] [blame] | 96 | int order; |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 97 | |
Robin Holt | 309d0b3 | 2013-11-12 15:07:23 -0800 | [diff] [blame] | 98 | while (start < end) { |
| 99 | order = min(MAX_ORDER - 1UL, __ffs(start)); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 100 | |
Robin Holt | 309d0b3 | 2013-11-12 15:07:23 -0800 | [diff] [blame] | 101 | while (start + (1UL << order) > end) |
| 102 | order--; |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 103 | |
Robin Holt | 309d0b3 | 2013-11-12 15:07:23 -0800 | [diff] [blame] | 104 | __free_pages_bootmem(pfn_to_page(start), order); |
| 105 | |
| 106 | start += (1UL << order); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 107 | } |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Yinghai Lu | 29f6738 | 2012-07-11 14:02:56 -0700 | [diff] [blame] | 110 | static unsigned long __init __free_memory_core(phys_addr_t start, |
| 111 | phys_addr_t end) |
| 112 | { |
| 113 | unsigned long start_pfn = PFN_UP(start); |
| 114 | unsigned long end_pfn = min_t(unsigned long, |
| 115 | PFN_DOWN(end), max_low_pfn); |
| 116 | |
| 117 | if (start_pfn > end_pfn) |
| 118 | return 0; |
| 119 | |
| 120 | __free_pages_memory(start_pfn, end_pfn); |
| 121 | |
| 122 | return end_pfn - start_pfn; |
| 123 | } |
| 124 | |
Joonsoo Kim | b4def35 | 2013-04-29 15:08:52 -0700 | [diff] [blame] | 125 | static unsigned long __init free_low_memory_core_early(void) |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 126 | { |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 127 | unsigned long count = 0; |
Philipp Hachtmann | 354f17e | 2014-01-23 15:53:24 -0800 | [diff] [blame] | 128 | phys_addr_t start, end; |
Tejun Heo | 8a9ca34 | 2011-07-12 11:16:02 +0200 | [diff] [blame] | 129 | u64 i; |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 130 | |
Xishi Qiu | 0a313a9 | 2014-09-09 14:50:46 -0700 | [diff] [blame] | 131 | memblock_clear_hotplug(0, -1); |
| 132 | |
Tony Luck | fc6daaf | 2015-06-24 16:58:09 -0700 | [diff] [blame] | 133 | for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end, |
| 134 | NULL) |
Yinghai Lu | 29f6738 | 2012-07-11 14:02:56 -0700 | [diff] [blame] | 135 | count += __free_memory_core(start, end); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 136 | |
Philipp Hachtmann | 5e270e2 | 2014-01-23 15:53:11 -0800 | [diff] [blame] | 137 | #ifdef CONFIG_ARCH_DISCARD_MEMBLOCK |
Philipp Hachtmann | 354f17e | 2014-01-23 15:53:24 -0800 | [diff] [blame] | 138 | { |
| 139 | phys_addr_t size; |
Philipp Hachtmann | 5e270e2 | 2014-01-23 15:53:11 -0800 | [diff] [blame] | 140 | |
Philipp Hachtmann | 354f17e | 2014-01-23 15:53:24 -0800 | [diff] [blame] | 141 | /* Free memblock.reserved array if it was allocated */ |
| 142 | size = get_allocated_memblock_reserved_regions_info(&start); |
| 143 | if (size) |
| 144 | count += __free_memory_core(start, start + size); |
| 145 | |
| 146 | /* Free memblock.memory array if it was allocated */ |
| 147 | size = get_allocated_memblock_memory_regions_info(&start); |
| 148 | if (size) |
| 149 | count += __free_memory_core(start, start + size); |
| 150 | } |
Philipp Hachtmann | 5e270e2 | 2014-01-23 15:53:11 -0800 | [diff] [blame] | 151 | #endif |
| 152 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 153 | return count; |
| 154 | } |
| 155 | |
Jiang Liu | 7b4b2a0 | 2013-07-03 15:03:11 -0700 | [diff] [blame] | 156 | static int reset_managed_pages_done __initdata; |
| 157 | |
Tang Chen | f784a3f | 2014-11-13 15:19:39 -0800 | [diff] [blame] | 158 | void reset_node_managed_pages(pg_data_t *pgdat) |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 159 | { |
| 160 | struct zone *z; |
| 161 | |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 162 | for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) |
Jiang Liu | 7b4b2a0 | 2013-07-03 15:03:11 -0700 | [diff] [blame] | 163 | z->managed_pages = 0; |
| 164 | } |
| 165 | |
| 166 | void __init reset_all_zones_managed_pages(void) |
| 167 | { |
| 168 | struct pglist_data *pgdat; |
| 169 | |
Tang Chen | f784a3f | 2014-11-13 15:19:39 -0800 | [diff] [blame] | 170 | if (reset_managed_pages_done) |
| 171 | return; |
| 172 | |
Jiang Liu | 7b4b2a0 | 2013-07-03 15:03:11 -0700 | [diff] [blame] | 173 | for_each_online_pgdat(pgdat) |
| 174 | reset_node_managed_pages(pgdat); |
Tang Chen | f784a3f | 2014-11-13 15:19:39 -0800 | [diff] [blame] | 175 | |
Jiang Liu | 7b4b2a0 | 2013-07-03 15:03:11 -0700 | [diff] [blame] | 176 | reset_managed_pages_done = 1; |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 179 | /** |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 180 | * free_all_bootmem - release free pages to the buddy allocator |
| 181 | * |
| 182 | * Returns the number of pages actually released. |
| 183 | */ |
| 184 | unsigned long __init free_all_bootmem(void) |
| 185 | { |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 186 | unsigned long pages; |
| 187 | |
Jiang Liu | 7b4b2a0 | 2013-07-03 15:03:11 -0700 | [diff] [blame] | 188 | reset_all_zones_managed_pages(); |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 189 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 190 | /* |
Grygorii Strashko | b115423 | 2014-01-21 15:50:16 -0800 | [diff] [blame] | 191 | * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 192 | * because in some case like Node0 doesn't have RAM installed |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 193 | * low ram will be on Node1 |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 194 | */ |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 195 | pages = free_low_memory_core_early(); |
| 196 | totalram_pages += pages; |
| 197 | |
| 198 | return pages; |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /** |
| 202 | * free_bootmem_node - mark a page range as usable |
| 203 | * @pgdat: node the range resides on |
| 204 | * @physaddr: starting address of the range |
| 205 | * @size: size of the range in bytes |
| 206 | * |
| 207 | * Partial pages will be considered reserved and left as they are. |
| 208 | * |
| 209 | * The range must reside completely on the specified node. |
| 210 | */ |
| 211 | void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, |
| 212 | unsigned long size) |
| 213 | { |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 214 | memblock_free(physaddr, size); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /** |
| 218 | * free_bootmem - mark a page range as usable |
| 219 | * @addr: starting address of the range |
| 220 | * @size: size of the range in bytes |
| 221 | * |
| 222 | * Partial pages will be considered reserved and left as they are. |
| 223 | * |
| 224 | * The range must be contiguous but may span node boundaries. |
| 225 | */ |
| 226 | void __init free_bootmem(unsigned long addr, unsigned long size) |
| 227 | { |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 228 | memblock_free(addr, size); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | static void * __init ___alloc_bootmem_nopanic(unsigned long size, |
| 232 | unsigned long align, |
| 233 | unsigned long goal, |
| 234 | unsigned long limit) |
| 235 | { |
| 236 | void *ptr; |
| 237 | |
| 238 | if (WARN_ON_ONCE(slab_is_available())) |
| 239 | return kzalloc(size, GFP_NOWAIT); |
| 240 | |
| 241 | restart: |
| 242 | |
Grygorii Strashko | b115423 | 2014-01-21 15:50:16 -0800 | [diff] [blame] | 243 | ptr = __alloc_memory_core_early(NUMA_NO_NODE, size, align, goal, limit); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 244 | |
| 245 | if (ptr) |
| 246 | return ptr; |
| 247 | |
| 248 | if (goal != 0) { |
| 249 | goal = 0; |
| 250 | goto restart; |
| 251 | } |
| 252 | |
| 253 | return NULL; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * __alloc_bootmem_nopanic - allocate boot memory without panicking |
| 258 | * @size: size of the request in bytes |
| 259 | * @align: alignment of the region |
| 260 | * @goal: preferred starting address of the region |
| 261 | * |
| 262 | * The goal is dropped if it can not be satisfied and the allocation will |
| 263 | * fall back to memory below @goal. |
| 264 | * |
| 265 | * Allocation may happen on any node in the system. |
| 266 | * |
| 267 | * Returns NULL on failure. |
| 268 | */ |
| 269 | void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align, |
| 270 | unsigned long goal) |
| 271 | { |
| 272 | unsigned long limit = -1UL; |
| 273 | |
| 274 | return ___alloc_bootmem_nopanic(size, align, goal, limit); |
| 275 | } |
| 276 | |
| 277 | static void * __init ___alloc_bootmem(unsigned long size, unsigned long align, |
| 278 | unsigned long goal, unsigned long limit) |
| 279 | { |
| 280 | void *mem = ___alloc_bootmem_nopanic(size, align, goal, limit); |
| 281 | |
| 282 | if (mem) |
| 283 | return mem; |
| 284 | /* |
| 285 | * Whoops, we cannot satisfy the allocation request. |
| 286 | */ |
| 287 | printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size); |
| 288 | panic("Out of memory"); |
| 289 | return NULL; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * __alloc_bootmem - allocate boot memory |
| 294 | * @size: size of the request in bytes |
| 295 | * @align: alignment of the region |
| 296 | * @goal: preferred starting address of the region |
| 297 | * |
| 298 | * The goal is dropped if it can not be satisfied and the allocation will |
| 299 | * fall back to memory below @goal. |
| 300 | * |
| 301 | * Allocation may happen on any node in the system. |
| 302 | * |
| 303 | * The function panics if the request can not be satisfied. |
| 304 | */ |
| 305 | void * __init __alloc_bootmem(unsigned long size, unsigned long align, |
| 306 | unsigned long goal) |
| 307 | { |
| 308 | unsigned long limit = -1UL; |
| 309 | |
| 310 | return ___alloc_bootmem(size, align, goal, limit); |
| 311 | } |
| 312 | |
Yinghai Lu | 99ab7b1 | 2012-07-11 14:02:53 -0700 | [diff] [blame] | 313 | void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat, |
Johannes Weiner | ba53986 | 2012-05-29 15:06:35 -0700 | [diff] [blame] | 314 | unsigned long size, |
| 315 | unsigned long align, |
| 316 | unsigned long goal, |
| 317 | unsigned long limit) |
| 318 | { |
| 319 | void *ptr; |
| 320 | |
| 321 | again: |
| 322 | ptr = __alloc_memory_core_early(pgdat->node_id, size, align, |
| 323 | goal, limit); |
| 324 | if (ptr) |
| 325 | return ptr; |
| 326 | |
Grygorii Strashko | b115423 | 2014-01-21 15:50:16 -0800 | [diff] [blame] | 327 | ptr = __alloc_memory_core_early(NUMA_NO_NODE, size, align, |
Johannes Weiner | ba53986 | 2012-05-29 15:06:35 -0700 | [diff] [blame] | 328 | goal, limit); |
| 329 | if (ptr) |
| 330 | return ptr; |
| 331 | |
| 332 | if (goal) { |
| 333 | goal = 0; |
| 334 | goto again; |
| 335 | } |
| 336 | |
| 337 | return NULL; |
| 338 | } |
| 339 | |
| 340 | void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size, |
| 341 | unsigned long align, unsigned long goal) |
| 342 | { |
| 343 | if (WARN_ON_ONCE(slab_is_available())) |
| 344 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
| 345 | |
| 346 | return ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, 0); |
| 347 | } |
| 348 | |
Rashika Kheria | de49850 | 2014-04-03 14:48:06 -0700 | [diff] [blame] | 349 | static void * __init ___alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, |
Johannes Weiner | ba53986 | 2012-05-29 15:06:35 -0700 | [diff] [blame] | 350 | unsigned long align, unsigned long goal, |
| 351 | unsigned long limit) |
| 352 | { |
| 353 | void *ptr; |
| 354 | |
| 355 | ptr = ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, limit); |
| 356 | if (ptr) |
| 357 | return ptr; |
| 358 | |
| 359 | printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size); |
| 360 | panic("Out of memory"); |
| 361 | return NULL; |
| 362 | } |
| 363 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 364 | /** |
| 365 | * __alloc_bootmem_node - allocate boot memory from a specific node |
| 366 | * @pgdat: node to allocate from |
| 367 | * @size: size of the request in bytes |
| 368 | * @align: alignment of the region |
| 369 | * @goal: preferred starting address of the region |
| 370 | * |
| 371 | * The goal is dropped if it can not be satisfied and the allocation will |
| 372 | * fall back to memory below @goal. |
| 373 | * |
| 374 | * Allocation may fall back to any node in the system if the specified node |
| 375 | * can not hold the requested memory. |
| 376 | * |
| 377 | * The function panics if the request can not be satisfied. |
| 378 | */ |
| 379 | void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, |
| 380 | unsigned long align, unsigned long goal) |
| 381 | { |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 382 | if (WARN_ON_ONCE(slab_is_available())) |
| 383 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
| 384 | |
Johannes Weiner | ba53986 | 2012-05-29 15:06:35 -0700 | [diff] [blame] | 385 | return ___alloc_bootmem_node(pgdat, size, align, goal, 0); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size, |
| 389 | unsigned long align, unsigned long goal) |
| 390 | { |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 391 | return __alloc_bootmem_node(pgdat, size, align, goal); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 394 | #ifndef ARCH_LOW_ADDRESS_LIMIT |
| 395 | #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL |
| 396 | #endif |
| 397 | |
| 398 | /** |
| 399 | * __alloc_bootmem_low - allocate low boot memory |
| 400 | * @size: size of the request in bytes |
| 401 | * @align: alignment of the region |
| 402 | * @goal: preferred starting address of the region |
| 403 | * |
| 404 | * The goal is dropped if it can not be satisfied and the allocation will |
| 405 | * fall back to memory below @goal. |
| 406 | * |
| 407 | * Allocation may happen on any node in the system. |
| 408 | * |
| 409 | * The function panics if the request can not be satisfied. |
| 410 | */ |
| 411 | void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, |
| 412 | unsigned long goal) |
| 413 | { |
| 414 | return ___alloc_bootmem(size, align, goal, ARCH_LOW_ADDRESS_LIMIT); |
| 415 | } |
| 416 | |
Yinghai Lu | 38fa417 | 2013-01-24 12:20:15 -0800 | [diff] [blame] | 417 | void * __init __alloc_bootmem_low_nopanic(unsigned long size, |
| 418 | unsigned long align, |
| 419 | unsigned long goal) |
| 420 | { |
| 421 | return ___alloc_bootmem_nopanic(size, align, goal, |
| 422 | ARCH_LOW_ADDRESS_LIMIT); |
| 423 | } |
| 424 | |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 425 | /** |
| 426 | * __alloc_bootmem_low_node - allocate low boot memory from a specific node |
| 427 | * @pgdat: node to allocate from |
| 428 | * @size: size of the request in bytes |
| 429 | * @align: alignment of the region |
| 430 | * @goal: preferred starting address of the region |
| 431 | * |
| 432 | * The goal is dropped if it can not be satisfied and the allocation will |
| 433 | * fall back to memory below @goal. |
| 434 | * |
| 435 | * Allocation may fall back to any node in the system if the specified node |
| 436 | * can not hold the requested memory. |
| 437 | * |
| 438 | * The function panics if the request can not be satisfied. |
| 439 | */ |
| 440 | void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size, |
| 441 | unsigned long align, unsigned long goal) |
| 442 | { |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 443 | if (WARN_ON_ONCE(slab_is_available())) |
| 444 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
| 445 | |
Johannes Weiner | ba53986 | 2012-05-29 15:06:35 -0700 | [diff] [blame] | 446 | return ___alloc_bootmem_node(pgdat, size, align, goal, |
| 447 | ARCH_LOW_ADDRESS_LIMIT); |
Yinghai Lu | 0932587 | 2011-02-24 14:43:05 +0100 | [diff] [blame] | 448 | } |