bootmem.c 18 KB

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