numa_64.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * Generic VM initialization for x86-64 NUMA setups.
  3. * Copyright 2002,2003 Andi Kleen, SuSE Labs.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/mm.h>
  7. #include <linux/string.h>
  8. #include <linux/init.h>
  9. #include <linux/bootmem.h>
  10. #include <linux/memblock.h>
  11. #include <linux/mmzone.h>
  12. #include <linux/ctype.h>
  13. #include <linux/module.h>
  14. #include <linux/nodemask.h>
  15. #include <linux/sched.h>
  16. #include <linux/acpi.h>
  17. #include <asm/e820.h>
  18. #include <asm/proto.h>
  19. #include <asm/dma.h>
  20. #include <asm/acpi.h>
  21. #include <asm/amd_nb.h>
  22. #include "numa_internal.h"
  23. struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
  24. EXPORT_SYMBOL(node_data);
  25. nodemask_t numa_nodes_parsed __initdata;
  26. struct memnode memnode;
  27. static unsigned long __initdata nodemap_addr;
  28. static unsigned long __initdata nodemap_size;
  29. static struct numa_meminfo numa_meminfo __initdata;
  30. static int numa_distance_cnt;
  31. static u8 *numa_distance;
  32. /*
  33. * Given a shift value, try to populate memnodemap[]
  34. * Returns :
  35. * 1 if OK
  36. * 0 if memnodmap[] too small (of shift too small)
  37. * -1 if node overlap or lost ram (shift too big)
  38. */
  39. static int __init populate_memnodemap(const struct numa_meminfo *mi, int shift)
  40. {
  41. unsigned long addr, end;
  42. int i, res = -1;
  43. memset(memnodemap, 0xff, sizeof(s16)*memnodemapsize);
  44. for (i = 0; i < mi->nr_blks; i++) {
  45. addr = mi->blk[i].start;
  46. end = mi->blk[i].end;
  47. if (addr >= end)
  48. continue;
  49. if ((end >> shift) >= memnodemapsize)
  50. return 0;
  51. do {
  52. if (memnodemap[addr >> shift] != NUMA_NO_NODE)
  53. return -1;
  54. memnodemap[addr >> shift] = mi->blk[i].nid;
  55. addr += (1UL << shift);
  56. } while (addr < end);
  57. res = 1;
  58. }
  59. return res;
  60. }
  61. static int __init allocate_cachealigned_memnodemap(void)
  62. {
  63. unsigned long addr;
  64. memnodemap = memnode.embedded_map;
  65. if (memnodemapsize <= ARRAY_SIZE(memnode.embedded_map))
  66. return 0;
  67. addr = 0x8000;
  68. nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
  69. nodemap_addr = memblock_find_in_range(addr, get_max_mapped(),
  70. nodemap_size, L1_CACHE_BYTES);
  71. if (nodemap_addr == MEMBLOCK_ERROR) {
  72. printk(KERN_ERR
  73. "NUMA: Unable to allocate Memory to Node hash map\n");
  74. nodemap_addr = nodemap_size = 0;
  75. return -1;
  76. }
  77. memnodemap = phys_to_virt(nodemap_addr);
  78. memblock_x86_reserve_range(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
  79. printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
  80. nodemap_addr, nodemap_addr + nodemap_size);
  81. return 0;
  82. }
  83. /*
  84. * The LSB of all start and end addresses in the node map is the value of the
  85. * maximum possible shift.
  86. */
  87. static int __init extract_lsb_from_nodes(const struct numa_meminfo *mi)
  88. {
  89. int i, nodes_used = 0;
  90. unsigned long start, end;
  91. unsigned long bitfield = 0, memtop = 0;
  92. for (i = 0; i < mi->nr_blks; i++) {
  93. start = mi->blk[i].start;
  94. end = mi->blk[i].end;
  95. if (start >= end)
  96. continue;
  97. bitfield |= start;
  98. nodes_used++;
  99. if (end > memtop)
  100. memtop = end;
  101. }
  102. if (nodes_used <= 1)
  103. i = 63;
  104. else
  105. i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
  106. memnodemapsize = (memtop >> i)+1;
  107. return i;
  108. }
  109. static int __init compute_hash_shift(const struct numa_meminfo *mi)
  110. {
  111. int shift;
  112. shift = extract_lsb_from_nodes(mi);
  113. if (allocate_cachealigned_memnodemap())
  114. return -1;
  115. printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
  116. shift);
  117. if (populate_memnodemap(mi, shift) != 1) {
  118. printk(KERN_INFO "Your memory is not aligned you need to "
  119. "rebuild your kernel with a bigger NODEMAPSIZE "
  120. "shift=%d\n", shift);
  121. return -1;
  122. }
  123. return shift;
  124. }
  125. int __meminit __early_pfn_to_nid(unsigned long pfn)
  126. {
  127. return phys_to_nid(pfn << PAGE_SHIFT);
  128. }
  129. static void * __init early_node_mem(int nodeid, unsigned long start,
  130. unsigned long end, unsigned long size,
  131. unsigned long align)
  132. {
  133. unsigned long mem;
  134. /*
  135. * put it on high as possible
  136. * something will go with NODE_DATA
  137. */
  138. if (start < (MAX_DMA_PFN<<PAGE_SHIFT))
  139. start = MAX_DMA_PFN<<PAGE_SHIFT;
  140. if (start < (MAX_DMA32_PFN<<PAGE_SHIFT) &&
  141. end > (MAX_DMA32_PFN<<PAGE_SHIFT))
  142. start = MAX_DMA32_PFN<<PAGE_SHIFT;
  143. mem = memblock_x86_find_in_range_node(nodeid, start, end, size, align);
  144. if (mem != MEMBLOCK_ERROR)
  145. return __va(mem);
  146. /* extend the search scope */
  147. end = max_pfn_mapped << PAGE_SHIFT;
  148. start = MAX_DMA_PFN << PAGE_SHIFT;
  149. mem = memblock_find_in_range(start, end, size, align);
  150. if (mem != MEMBLOCK_ERROR)
  151. return __va(mem);
  152. printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
  153. size, nodeid);
  154. return NULL;
  155. }
  156. static int __init numa_add_memblk_to(int nid, u64 start, u64 end,
  157. struct numa_meminfo *mi)
  158. {
  159. /* ignore zero length blks */
  160. if (start == end)
  161. return 0;
  162. /* whine about and ignore invalid blks */
  163. if (start > end || nid < 0 || nid >= MAX_NUMNODES) {
  164. pr_warning("NUMA: Warning: invalid memblk node %d (%Lx-%Lx)\n",
  165. nid, start, end);
  166. return 0;
  167. }
  168. if (mi->nr_blks >= NR_NODE_MEMBLKS) {
  169. pr_err("NUMA: too many memblk ranges\n");
  170. return -EINVAL;
  171. }
  172. mi->blk[mi->nr_blks].start = start;
  173. mi->blk[mi->nr_blks].end = end;
  174. mi->blk[mi->nr_blks].nid = nid;
  175. mi->nr_blks++;
  176. return 0;
  177. }
  178. /**
  179. * numa_remove_memblk_from - Remove one numa_memblk from a numa_meminfo
  180. * @idx: Index of memblk to remove
  181. * @mi: numa_meminfo to remove memblk from
  182. *
  183. * Remove @idx'th numa_memblk from @mi by shifting @mi->blk[] and
  184. * decrementing @mi->nr_blks.
  185. */
  186. void __init numa_remove_memblk_from(int idx, struct numa_meminfo *mi)
  187. {
  188. mi->nr_blks--;
  189. memmove(&mi->blk[idx], &mi->blk[idx + 1],
  190. (mi->nr_blks - idx) * sizeof(mi->blk[0]));
  191. }
  192. /**
  193. * numa_add_memblk - Add one numa_memblk to numa_meminfo
  194. * @nid: NUMA node ID of the new memblk
  195. * @start: Start address of the new memblk
  196. * @end: End address of the new memblk
  197. *
  198. * Add a new memblk to the default numa_meminfo.
  199. *
  200. * RETURNS:
  201. * 0 on success, -errno on failure.
  202. */
  203. int __init numa_add_memblk(int nid, u64 start, u64 end)
  204. {
  205. return numa_add_memblk_to(nid, start, end, &numa_meminfo);
  206. }
  207. /* Initialize bootmem allocator for a node */
  208. void __init
  209. setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
  210. {
  211. unsigned long start_pfn, last_pfn, nodedata_phys;
  212. const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
  213. int nid;
  214. if (!end)
  215. return;
  216. /*
  217. * Don't confuse VM with a node that doesn't have the
  218. * minimum amount of memory:
  219. */
  220. if (end && (end - start) < NODE_MIN_SIZE)
  221. return;
  222. start = roundup(start, ZONE_ALIGN);
  223. printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n", nodeid,
  224. start, end);
  225. start_pfn = start >> PAGE_SHIFT;
  226. last_pfn = end >> PAGE_SHIFT;
  227. node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size,
  228. SMP_CACHE_BYTES);
  229. if (node_data[nodeid] == NULL)
  230. return;
  231. nodedata_phys = __pa(node_data[nodeid]);
  232. memblock_x86_reserve_range(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
  233. printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
  234. nodedata_phys + pgdat_size - 1);
  235. nid = phys_to_nid(nodedata_phys);
  236. if (nid != nodeid)
  237. printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid, nid);
  238. memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
  239. NODE_DATA(nodeid)->node_id = nodeid;
  240. NODE_DATA(nodeid)->node_start_pfn = start_pfn;
  241. NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;
  242. node_set_online(nodeid);
  243. }
  244. /**
  245. * numa_cleanup_meminfo - Cleanup a numa_meminfo
  246. * @mi: numa_meminfo to clean up
  247. *
  248. * Sanitize @mi by merging and removing unncessary memblks. Also check for
  249. * conflicts and clear unused memblks.
  250. *
  251. * RETURNS:
  252. * 0 on success, -errno on failure.
  253. */
  254. int __init numa_cleanup_meminfo(struct numa_meminfo *mi)
  255. {
  256. const u64 low = 0;
  257. const u64 high = (u64)max_pfn << PAGE_SHIFT;
  258. int i, j, k;
  259. for (i = 0; i < mi->nr_blks; i++) {
  260. struct numa_memblk *bi = &mi->blk[i];
  261. /* make sure all blocks are inside the limits */
  262. bi->start = max(bi->start, low);
  263. bi->end = min(bi->end, high);
  264. /* and there's no empty block */
  265. if (bi->start == bi->end) {
  266. numa_remove_memblk_from(i--, mi);
  267. continue;
  268. }
  269. for (j = i + 1; j < mi->nr_blks; j++) {
  270. struct numa_memblk *bj = &mi->blk[j];
  271. unsigned long start, end;
  272. /*
  273. * See whether there are overlapping blocks. Whine
  274. * about but allow overlaps of the same nid. They
  275. * will be merged below.
  276. */
  277. if (bi->end > bj->start && bi->start < bj->end) {
  278. if (bi->nid != bj->nid) {
  279. pr_err("NUMA: node %d (%Lx-%Lx) overlaps with node %d (%Lx-%Lx)\n",
  280. bi->nid, bi->start, bi->end,
  281. bj->nid, bj->start, bj->end);
  282. return -EINVAL;
  283. }
  284. pr_warning("NUMA: Warning: node %d (%Lx-%Lx) overlaps with itself (%Lx-%Lx)\n",
  285. bi->nid, bi->start, bi->end,
  286. bj->start, bj->end);
  287. }
  288. /*
  289. * Join together blocks on the same node, holes
  290. * between which don't overlap with memory on other
  291. * nodes.
  292. */
  293. if (bi->nid != bj->nid)
  294. continue;
  295. start = max(min(bi->start, bj->start), low);
  296. end = min(max(bi->end, bj->end), high);
  297. for (k = 0; k < mi->nr_blks; k++) {
  298. struct numa_memblk *bk = &mi->blk[k];
  299. if (bi->nid == bk->nid)
  300. continue;
  301. if (start < bk->end && end > bk->start)
  302. break;
  303. }
  304. if (k < mi->nr_blks)
  305. continue;
  306. printk(KERN_INFO "NUMA: Node %d [%Lx,%Lx) + [%Lx,%Lx) -> [%lx,%lx)\n",
  307. bi->nid, bi->start, bi->end, bj->start, bj->end,
  308. start, end);
  309. bi->start = start;
  310. bi->end = end;
  311. numa_remove_memblk_from(j--, mi);
  312. }
  313. }
  314. for (i = mi->nr_blks; i < ARRAY_SIZE(mi->blk); i++) {
  315. mi->blk[i].start = mi->blk[i].end = 0;
  316. mi->blk[i].nid = NUMA_NO_NODE;
  317. }
  318. return 0;
  319. }
  320. /*
  321. * Set nodes, which have memory in @mi, in *@nodemask.
  322. */
  323. static void __init numa_nodemask_from_meminfo(nodemask_t *nodemask,
  324. const struct numa_meminfo *mi)
  325. {
  326. int i;
  327. for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
  328. if (mi->blk[i].start != mi->blk[i].end &&
  329. mi->blk[i].nid != NUMA_NO_NODE)
  330. node_set(mi->blk[i].nid, *nodemask);
  331. }
  332. /**
  333. * numa_reset_distance - Reset NUMA distance table
  334. *
  335. * The current table is freed. The next numa_set_distance() call will
  336. * create a new one.
  337. */
  338. void __init numa_reset_distance(void)
  339. {
  340. size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]);
  341. if (numa_distance_cnt)
  342. memblock_x86_free_range(__pa(numa_distance),
  343. __pa(numa_distance) + size);
  344. numa_distance_cnt = 0;
  345. numa_distance = NULL;
  346. }
  347. static int __init numa_alloc_distance(void)
  348. {
  349. nodemask_t nodes_parsed;
  350. size_t size;
  351. int i, j, cnt = 0;
  352. u64 phys;
  353. /* size the new table and allocate it */
  354. nodes_parsed = numa_nodes_parsed;
  355. numa_nodemask_from_meminfo(&nodes_parsed, &numa_meminfo);
  356. for_each_node_mask(i, nodes_parsed)
  357. cnt = i;
  358. cnt++;
  359. size = cnt * cnt * sizeof(numa_distance[0]);
  360. phys = memblock_find_in_range(0, (u64)max_pfn_mapped << PAGE_SHIFT,
  361. size, PAGE_SIZE);
  362. if (phys == MEMBLOCK_ERROR) {
  363. pr_warning("NUMA: Warning: can't allocate distance table!\n");
  364. /* don't retry until explicitly reset */
  365. numa_distance = (void *)1LU;
  366. return -ENOMEM;
  367. }
  368. memblock_x86_reserve_range(phys, phys + size, "NUMA DIST");
  369. numa_distance = __va(phys);
  370. numa_distance_cnt = cnt;
  371. /* fill with the default distances */
  372. for (i = 0; i < cnt; i++)
  373. for (j = 0; j < cnt; j++)
  374. numa_distance[i * cnt + j] = i == j ?
  375. LOCAL_DISTANCE : REMOTE_DISTANCE;
  376. printk(KERN_DEBUG "NUMA: Initialized distance table, cnt=%d\n", cnt);
  377. return 0;
  378. }
  379. /**
  380. * numa_set_distance - Set NUMA distance from one NUMA to another
  381. * @from: the 'from' node to set distance
  382. * @to: the 'to' node to set distance
  383. * @distance: NUMA distance
  384. *
  385. * Set the distance from node @from to @to to @distance. If distance table
  386. * doesn't exist, one which is large enough to accomodate all the currently
  387. * known nodes will be created.
  388. */
  389. void __init numa_set_distance(int from, int to, int distance)
  390. {
  391. if (!numa_distance && numa_alloc_distance() < 0)
  392. return;
  393. if (from >= numa_distance_cnt || to >= numa_distance_cnt) {
  394. printk_once(KERN_DEBUG "NUMA: Debug: distance out of bound, from=%d to=%d distance=%d\n",
  395. from, to, distance);
  396. return;
  397. }
  398. if ((u8)distance != distance ||
  399. (from == to && distance != LOCAL_DISTANCE)) {
  400. pr_warn_once("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n",
  401. from, to, distance);
  402. return;
  403. }
  404. numa_distance[from * numa_distance_cnt + to] = distance;
  405. }
  406. int __node_distance(int from, int to)
  407. {
  408. if (from >= numa_distance_cnt || to >= numa_distance_cnt)
  409. return from == to ? LOCAL_DISTANCE : REMOTE_DISTANCE;
  410. return numa_distance[from * numa_distance_cnt + to];
  411. }
  412. EXPORT_SYMBOL(__node_distance);
  413. /*
  414. * Sanity check to catch more bad NUMA configurations (they are amazingly
  415. * common). Make sure the nodes cover all memory.
  416. */
  417. static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
  418. {
  419. unsigned long numaram, e820ram;
  420. int i;
  421. numaram = 0;
  422. for (i = 0; i < mi->nr_blks; i++) {
  423. unsigned long s = mi->blk[i].start >> PAGE_SHIFT;
  424. unsigned long e = mi->blk[i].end >> PAGE_SHIFT;
  425. numaram += e - s;
  426. numaram -= __absent_pages_in_range(mi->blk[i].nid, s, e);
  427. if ((long)numaram < 0)
  428. numaram = 0;
  429. }
  430. e820ram = max_pfn - (memblock_x86_hole_size(0,
  431. max_pfn << PAGE_SHIFT) >> PAGE_SHIFT);
  432. /* We seem to lose 3 pages somewhere. Allow 1M of slack. */
  433. if ((long)(e820ram - numaram) >= (1 << (20 - PAGE_SHIFT))) {
  434. printk(KERN_ERR "NUMA: nodes only cover %luMB of your %luMB e820 RAM. Not used.\n",
  435. (numaram << PAGE_SHIFT) >> 20,
  436. (e820ram << PAGE_SHIFT) >> 20);
  437. return false;
  438. }
  439. return true;
  440. }
  441. static int __init numa_register_memblks(struct numa_meminfo *mi)
  442. {
  443. int i, nid;
  444. /* Account for nodes with cpus and no memory */
  445. node_possible_map = numa_nodes_parsed;
  446. numa_nodemask_from_meminfo(&node_possible_map, mi);
  447. if (WARN_ON(nodes_empty(node_possible_map)))
  448. return -EINVAL;
  449. memnode_shift = compute_hash_shift(mi);
  450. if (memnode_shift < 0) {
  451. printk(KERN_ERR "NUMA: No NUMA node hash function found. Contact maintainer\n");
  452. return -EINVAL;
  453. }
  454. for (i = 0; i < mi->nr_blks; i++)
  455. memblock_x86_register_active_regions(mi->blk[i].nid,
  456. mi->blk[i].start >> PAGE_SHIFT,
  457. mi->blk[i].end >> PAGE_SHIFT);
  458. /* for out of order entries */
  459. sort_node_map();
  460. if (!numa_meminfo_cover_memory(mi))
  461. return -EINVAL;
  462. init_memory_mapping_high();
  463. /* Finally register nodes. */
  464. for_each_node_mask(nid, node_possible_map) {
  465. u64 start = (u64)max_pfn << PAGE_SHIFT;
  466. u64 end = 0;
  467. for (i = 0; i < mi->nr_blks; i++) {
  468. if (nid != mi->blk[i].nid)
  469. continue;
  470. start = min(mi->blk[i].start, start);
  471. end = max(mi->blk[i].end, end);
  472. }
  473. if (start < end)
  474. setup_node_bootmem(nid, start, end);
  475. }
  476. return 0;
  477. }
  478. static int __init dummy_numa_init(void)
  479. {
  480. printk(KERN_INFO "%s\n",
  481. numa_off ? "NUMA turned off" : "No NUMA configuration found");
  482. printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
  483. 0LU, max_pfn << PAGE_SHIFT);
  484. node_set(0, numa_nodes_parsed);
  485. numa_add_memblk(0, 0, (u64)max_pfn << PAGE_SHIFT);
  486. return 0;
  487. }
  488. void __init initmem_init(void)
  489. {
  490. int (*numa_init[])(void) = { [2] = dummy_numa_init };
  491. int i, j;
  492. if (!numa_off) {
  493. #ifdef CONFIG_ACPI_NUMA
  494. numa_init[0] = x86_acpi_numa_init;
  495. #endif
  496. #ifdef CONFIG_AMD_NUMA
  497. numa_init[1] = amd_numa_init;
  498. #endif
  499. }
  500. for (i = 0; i < ARRAY_SIZE(numa_init); i++) {
  501. if (!numa_init[i])
  502. continue;
  503. for (j = 0; j < MAX_LOCAL_APIC; j++)
  504. set_apicid_to_node(j, NUMA_NO_NODE);
  505. nodes_clear(numa_nodes_parsed);
  506. nodes_clear(node_possible_map);
  507. nodes_clear(node_online_map);
  508. memset(&numa_meminfo, 0, sizeof(numa_meminfo));
  509. remove_all_active_ranges();
  510. numa_reset_distance();
  511. if (numa_init[i]() < 0)
  512. continue;
  513. if (numa_cleanup_meminfo(&numa_meminfo) < 0)
  514. continue;
  515. numa_emulation(&numa_meminfo, numa_distance_cnt);
  516. if (numa_register_memblks(&numa_meminfo) < 0)
  517. continue;
  518. for (j = 0; j < nr_cpu_ids; j++) {
  519. int nid = early_cpu_to_node(j);
  520. if (nid == NUMA_NO_NODE)
  521. continue;
  522. if (!node_online(nid))
  523. numa_clear_node(j);
  524. }
  525. numa_init_array();
  526. return;
  527. }
  528. BUG();
  529. }
  530. unsigned long __init numa_free_all_bootmem(void)
  531. {
  532. unsigned long pages = 0;
  533. int i;
  534. for_each_online_node(i)
  535. pages += free_all_bootmem_node(NODE_DATA(i));
  536. pages += free_all_memory_core_early(MAX_NUMNODES);
  537. return pages;
  538. }
  539. int __cpuinit numa_cpu_node(int cpu)
  540. {
  541. int apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
  542. if (apicid != BAD_APICID)
  543. return __apicid_to_node[apicid];
  544. return NUMA_NO_NODE;
  545. }