numa_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. /* numa_distance could be 1LU marking allocation failure, test cnt */
  342. if (numa_distance_cnt)
  343. memblock_x86_free_range(__pa(numa_distance),
  344. __pa(numa_distance) + size);
  345. numa_distance_cnt = 0;
  346. numa_distance = NULL; /* enable table creation */
  347. }
  348. static int __init numa_alloc_distance(void)
  349. {
  350. nodemask_t nodes_parsed;
  351. size_t size;
  352. int i, j, cnt = 0;
  353. u64 phys;
  354. /* size the new table and allocate it */
  355. nodes_parsed = numa_nodes_parsed;
  356. numa_nodemask_from_meminfo(&nodes_parsed, &numa_meminfo);
  357. for_each_node_mask(i, nodes_parsed)
  358. cnt = i;
  359. cnt++;
  360. size = cnt * cnt * sizeof(numa_distance[0]);
  361. phys = memblock_find_in_range(0, (u64)max_pfn_mapped << PAGE_SHIFT,
  362. size, PAGE_SIZE);
  363. if (phys == MEMBLOCK_ERROR) {
  364. pr_warning("NUMA: Warning: can't allocate distance table!\n");
  365. /* don't retry until explicitly reset */
  366. numa_distance = (void *)1LU;
  367. return -ENOMEM;
  368. }
  369. memblock_x86_reserve_range(phys, phys + size, "NUMA DIST");
  370. numa_distance = __va(phys);
  371. numa_distance_cnt = cnt;
  372. /* fill with the default distances */
  373. for (i = 0; i < cnt; i++)
  374. for (j = 0; j < cnt; j++)
  375. numa_distance[i * cnt + j] = i == j ?
  376. LOCAL_DISTANCE : REMOTE_DISTANCE;
  377. printk(KERN_DEBUG "NUMA: Initialized distance table, cnt=%d\n", cnt);
  378. return 0;
  379. }
  380. /**
  381. * numa_set_distance - Set NUMA distance from one NUMA to another
  382. * @from: the 'from' node to set distance
  383. * @to: the 'to' node to set distance
  384. * @distance: NUMA distance
  385. *
  386. * Set the distance from node @from to @to to @distance. If distance table
  387. * doesn't exist, one which is large enough to accommodate all the currently
  388. * known nodes will be created.
  389. *
  390. * If such table cannot be allocated, a warning is printed and further
  391. * calls are ignored until the distance table is reset with
  392. * numa_reset_distance().
  393. *
  394. * If @from or @to is higher than the highest known node at the time of
  395. * table creation or @distance doesn't make sense, the call is ignored.
  396. * This is to allow simplification of specific NUMA config implementations.
  397. */
  398. void __init numa_set_distance(int from, int to, int distance)
  399. {
  400. if (!numa_distance && numa_alloc_distance() < 0)
  401. return;
  402. if (from >= numa_distance_cnt || to >= numa_distance_cnt) {
  403. printk_once(KERN_DEBUG "NUMA: Debug: distance out of bound, from=%d to=%d distance=%d\n",
  404. from, to, distance);
  405. return;
  406. }
  407. if ((u8)distance != distance ||
  408. (from == to && distance != LOCAL_DISTANCE)) {
  409. pr_warn_once("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n",
  410. from, to, distance);
  411. return;
  412. }
  413. numa_distance[from * numa_distance_cnt + to] = distance;
  414. }
  415. int __node_distance(int from, int to)
  416. {
  417. if (from >= numa_distance_cnt || to >= numa_distance_cnt)
  418. return from == to ? LOCAL_DISTANCE : REMOTE_DISTANCE;
  419. return numa_distance[from * numa_distance_cnt + to];
  420. }
  421. EXPORT_SYMBOL(__node_distance);
  422. /*
  423. * Sanity check to catch more bad NUMA configurations (they are amazingly
  424. * common). Make sure the nodes cover all memory.
  425. */
  426. static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
  427. {
  428. unsigned long numaram, e820ram;
  429. int i;
  430. numaram = 0;
  431. for (i = 0; i < mi->nr_blks; i++) {
  432. unsigned long s = mi->blk[i].start >> PAGE_SHIFT;
  433. unsigned long e = mi->blk[i].end >> PAGE_SHIFT;
  434. numaram += e - s;
  435. numaram -= __absent_pages_in_range(mi->blk[i].nid, s, e);
  436. if ((long)numaram < 0)
  437. numaram = 0;
  438. }
  439. e820ram = max_pfn - (memblock_x86_hole_size(0,
  440. max_pfn << PAGE_SHIFT) >> PAGE_SHIFT);
  441. /* We seem to lose 3 pages somewhere. Allow 1M of slack. */
  442. if ((long)(e820ram - numaram) >= (1 << (20 - PAGE_SHIFT))) {
  443. printk(KERN_ERR "NUMA: nodes only cover %luMB of your %luMB e820 RAM. Not used.\n",
  444. (numaram << PAGE_SHIFT) >> 20,
  445. (e820ram << PAGE_SHIFT) >> 20);
  446. return false;
  447. }
  448. return true;
  449. }
  450. static int __init numa_register_memblks(struct numa_meminfo *mi)
  451. {
  452. int i, nid;
  453. /* Account for nodes with cpus and no memory */
  454. node_possible_map = numa_nodes_parsed;
  455. numa_nodemask_from_meminfo(&node_possible_map, mi);
  456. if (WARN_ON(nodes_empty(node_possible_map)))
  457. return -EINVAL;
  458. memnode_shift = compute_hash_shift(mi);
  459. if (memnode_shift < 0) {
  460. printk(KERN_ERR "NUMA: No NUMA node hash function found. Contact maintainer\n");
  461. return -EINVAL;
  462. }
  463. for (i = 0; i < mi->nr_blks; i++)
  464. memblock_x86_register_active_regions(mi->blk[i].nid,
  465. mi->blk[i].start >> PAGE_SHIFT,
  466. mi->blk[i].end >> PAGE_SHIFT);
  467. /* for out of order entries */
  468. sort_node_map();
  469. if (!numa_meminfo_cover_memory(mi))
  470. return -EINVAL;
  471. /* Finally register nodes. */
  472. for_each_node_mask(nid, node_possible_map) {
  473. u64 start = (u64)max_pfn << PAGE_SHIFT;
  474. u64 end = 0;
  475. for (i = 0; i < mi->nr_blks; i++) {
  476. if (nid != mi->blk[i].nid)
  477. continue;
  478. start = min(mi->blk[i].start, start);
  479. end = max(mi->blk[i].end, end);
  480. }
  481. if (start < end)
  482. setup_node_bootmem(nid, start, end);
  483. }
  484. return 0;
  485. }
  486. /**
  487. * dummy_numma_init - Fallback dummy NUMA init
  488. *
  489. * Used if there's no underlying NUMA architecture, NUMA initialization
  490. * fails, or NUMA is disabled on the command line.
  491. *
  492. * Must online at least one node and add memory blocks that cover all
  493. * allowed memory. This function must not fail.
  494. */
  495. static int __init dummy_numa_init(void)
  496. {
  497. printk(KERN_INFO "%s\n",
  498. numa_off ? "NUMA turned off" : "No NUMA configuration found");
  499. printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
  500. 0LU, max_pfn << PAGE_SHIFT);
  501. node_set(0, numa_nodes_parsed);
  502. numa_add_memblk(0, 0, (u64)max_pfn << PAGE_SHIFT);
  503. return 0;
  504. }
  505. static int __init numa_init(int (*init_func)(void))
  506. {
  507. int i;
  508. int ret;
  509. for (i = 0; i < MAX_LOCAL_APIC; i++)
  510. set_apicid_to_node(i, NUMA_NO_NODE);
  511. nodes_clear(numa_nodes_parsed);
  512. nodes_clear(node_possible_map);
  513. nodes_clear(node_online_map);
  514. memset(&numa_meminfo, 0, sizeof(numa_meminfo));
  515. remove_all_active_ranges();
  516. numa_reset_distance();
  517. ret = init_func();
  518. if (ret < 0)
  519. return ret;
  520. ret = numa_cleanup_meminfo(&numa_meminfo);
  521. if (ret < 0)
  522. return ret;
  523. numa_emulation(&numa_meminfo, numa_distance_cnt);
  524. ret = numa_register_memblks(&numa_meminfo);
  525. if (ret < 0)
  526. return ret;
  527. for (i = 0; i < nr_cpu_ids; i++) {
  528. int nid = early_cpu_to_node(i);
  529. if (nid == NUMA_NO_NODE)
  530. continue;
  531. if (!node_online(nid))
  532. numa_clear_node(i);
  533. }
  534. numa_init_array();
  535. return 0;
  536. }
  537. void __init initmem_init(void)
  538. {
  539. int ret;
  540. if (!numa_off) {
  541. #ifdef CONFIG_ACPI_NUMA
  542. ret = numa_init(x86_acpi_numa_init);
  543. if (!ret)
  544. return;
  545. #endif
  546. #ifdef CONFIG_AMD_NUMA
  547. ret = numa_init(amd_numa_init);
  548. if (!ret)
  549. return;
  550. #endif
  551. }
  552. numa_init(dummy_numa_init);
  553. }
  554. unsigned long __init numa_free_all_bootmem(void)
  555. {
  556. unsigned long pages = 0;
  557. int i;
  558. for_each_online_node(i)
  559. pages += free_all_bootmem_node(NODE_DATA(i));
  560. pages += free_all_memory_core_early(MAX_NUMNODES);
  561. return pages;
  562. }
  563. int __cpuinit numa_cpu_node(int cpu)
  564. {
  565. int apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
  566. if (apicid != BAD_APICID)
  567. return __apicid_to_node[apicid];
  568. return NUMA_NO_NODE;
  569. }