numa_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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/mmzone.h>
  11. #include <linux/ctype.h>
  12. #include <linux/module.h>
  13. #include <linux/nodemask.h>
  14. #include <linux/sched.h>
  15. #include <asm/e820.h>
  16. #include <asm/proto.h>
  17. #include <asm/dma.h>
  18. #include <asm/numa.h>
  19. #include <asm/acpi.h>
  20. #include <asm/k8.h>
  21. #ifndef Dprintk
  22. #define Dprintk(x...)
  23. #endif
  24. struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
  25. EXPORT_SYMBOL(node_data);
  26. bootmem_data_t plat_node_bdata[MAX_NUMNODES];
  27. struct memnode memnode;
  28. #ifdef CONFIG_SMP
  29. int x86_cpu_to_node_map_init[NR_CPUS] = {
  30. [0 ... NR_CPUS-1] = NUMA_NO_NODE
  31. };
  32. void *x86_cpu_to_node_map_early_ptr;
  33. EXPORT_SYMBOL(x86_cpu_to_node_map_early_ptr);
  34. #endif
  35. DEFINE_PER_CPU(int, x86_cpu_to_node_map) = NUMA_NO_NODE;
  36. EXPORT_PER_CPU_SYMBOL(x86_cpu_to_node_map);
  37. s16 apicid_to_node[MAX_LOCAL_APIC] __cpuinitdata = {
  38. [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
  39. };
  40. cpumask_t node_to_cpumask_map[MAX_NUMNODES] __read_mostly;
  41. EXPORT_SYMBOL(node_to_cpumask_map);
  42. int numa_off __initdata;
  43. unsigned long __initdata nodemap_addr;
  44. unsigned long __initdata nodemap_size;
  45. /*
  46. * Given a shift value, try to populate memnodemap[]
  47. * Returns :
  48. * 1 if OK
  49. * 0 if memnodmap[] too small (of shift too small)
  50. * -1 if node overlap or lost ram (shift too big)
  51. */
  52. static int __init populate_memnodemap(const struct bootnode *nodes,
  53. int numnodes, int shift, int *nodeids)
  54. {
  55. unsigned long addr, end;
  56. int i, res = -1;
  57. memset(memnodemap, 0xff, sizeof(s16)*memnodemapsize);
  58. for (i = 0; i < numnodes; i++) {
  59. addr = nodes[i].start;
  60. end = nodes[i].end;
  61. if (addr >= end)
  62. continue;
  63. if ((end >> shift) >= memnodemapsize)
  64. return 0;
  65. do {
  66. if (memnodemap[addr >> shift] != NUMA_NO_NODE)
  67. return -1;
  68. if (!nodeids)
  69. memnodemap[addr >> shift] = i;
  70. else
  71. memnodemap[addr >> shift] = nodeids[i];
  72. addr += (1UL << shift);
  73. } while (addr < end);
  74. res = 1;
  75. }
  76. return res;
  77. }
  78. static int __init allocate_cachealigned_memnodemap(void)
  79. {
  80. unsigned long addr;
  81. memnodemap = memnode.embedded_map;
  82. if (memnodemapsize <= ARRAY_SIZE(memnode.embedded_map))
  83. return 0;
  84. addr = 0x8000;
  85. nodemap_size = round_up(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
  86. nodemap_addr = find_e820_area(addr, end_pfn<<PAGE_SHIFT,
  87. nodemap_size, L1_CACHE_BYTES);
  88. if (nodemap_addr == -1UL) {
  89. printk(KERN_ERR
  90. "NUMA: Unable to allocate Memory to Node hash map\n");
  91. nodemap_addr = nodemap_size = 0;
  92. return -1;
  93. }
  94. memnodemap = phys_to_virt(nodemap_addr);
  95. reserve_early(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
  96. printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
  97. nodemap_addr, nodemap_addr + nodemap_size);
  98. return 0;
  99. }
  100. /*
  101. * The LSB of all start and end addresses in the node map is the value of the
  102. * maximum possible shift.
  103. */
  104. static int __init extract_lsb_from_nodes(const struct bootnode *nodes,
  105. int numnodes)
  106. {
  107. int i, nodes_used = 0;
  108. unsigned long start, end;
  109. unsigned long bitfield = 0, memtop = 0;
  110. for (i = 0; i < numnodes; i++) {
  111. start = nodes[i].start;
  112. end = nodes[i].end;
  113. if (start >= end)
  114. continue;
  115. bitfield |= start;
  116. nodes_used++;
  117. if (end > memtop)
  118. memtop = end;
  119. }
  120. if (nodes_used <= 1)
  121. i = 63;
  122. else
  123. i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
  124. memnodemapsize = (memtop >> i)+1;
  125. return i;
  126. }
  127. int __init compute_hash_shift(struct bootnode *nodes, int numnodes,
  128. int *nodeids)
  129. {
  130. int shift;
  131. shift = extract_lsb_from_nodes(nodes, numnodes);
  132. if (allocate_cachealigned_memnodemap())
  133. return -1;
  134. printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
  135. shift);
  136. if (populate_memnodemap(nodes, numnodes, shift, nodeids) != 1) {
  137. printk(KERN_INFO "Your memory is not aligned you need to "
  138. "rebuild your kernel with a bigger NODEMAPSIZE "
  139. "shift=%d\n", shift);
  140. return -1;
  141. }
  142. return shift;
  143. }
  144. int early_pfn_to_nid(unsigned long pfn)
  145. {
  146. return phys_to_nid(pfn << PAGE_SHIFT);
  147. }
  148. static void * __init early_node_mem(int nodeid, unsigned long start,
  149. unsigned long end, unsigned long size,
  150. unsigned long align)
  151. {
  152. unsigned long mem = find_e820_area(start, end, size, align);
  153. void *ptr;
  154. if (mem != -1L)
  155. return __va(mem);
  156. ptr = __alloc_bootmem_nopanic(size, align, __pa(MAX_DMA_ADDRESS));
  157. if (ptr == NULL) {
  158. printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
  159. size, nodeid);
  160. return NULL;
  161. }
  162. return ptr;
  163. }
  164. /* Initialize bootmem allocator for a node */
  165. void __init setup_node_bootmem(int nodeid, unsigned long start,
  166. unsigned long end)
  167. {
  168. unsigned long start_pfn, end_pfn, bootmap_pages, bootmap_size;
  169. unsigned long bootmap_start, nodedata_phys;
  170. void *bootmap;
  171. const int pgdat_size = round_up(sizeof(pg_data_t), PAGE_SIZE);
  172. int nid;
  173. start = round_up(start, ZONE_ALIGN);
  174. printk(KERN_INFO "Bootmem setup node %d %016lx-%016lx\n", nodeid,
  175. start, end);
  176. start_pfn = start >> PAGE_SHIFT;
  177. end_pfn = end >> PAGE_SHIFT;
  178. node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size,
  179. SMP_CACHE_BYTES);
  180. if (node_data[nodeid] == NULL)
  181. return;
  182. nodedata_phys = __pa(node_data[nodeid]);
  183. printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
  184. nodedata_phys + pgdat_size - 1);
  185. memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
  186. NODE_DATA(nodeid)->bdata = &plat_node_bdata[nodeid];
  187. NODE_DATA(nodeid)->node_start_pfn = start_pfn;
  188. NODE_DATA(nodeid)->node_spanned_pages = end_pfn - start_pfn;
  189. /*
  190. * Find a place for the bootmem map
  191. * nodedata_phys could be on other nodes by alloc_bootmem,
  192. * so need to sure bootmap_start not to be small, otherwise
  193. * early_node_mem will get that with find_e820_area instead
  194. * of alloc_bootmem, that could clash with reserved range
  195. */
  196. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  197. nid = phys_to_nid(nodedata_phys);
  198. if (nid == nodeid)
  199. bootmap_start = round_up(nodedata_phys + pgdat_size, PAGE_SIZE);
  200. else
  201. bootmap_start = round_up(start, PAGE_SIZE);
  202. /*
  203. * SMP_CAHCE_BYTES could be enough, but init_bootmem_node like
  204. * to use that to align to PAGE_SIZE
  205. */
  206. bootmap = early_node_mem(nodeid, bootmap_start, end,
  207. bootmap_pages<<PAGE_SHIFT, PAGE_SIZE);
  208. if (bootmap == NULL) {
  209. if (nodedata_phys < start || nodedata_phys >= end)
  210. free_bootmem(nodedata_phys, pgdat_size);
  211. node_data[nodeid] = NULL;
  212. return;
  213. }
  214. bootmap_start = __pa(bootmap);
  215. bootmap_size = init_bootmem_node(NODE_DATA(nodeid),
  216. bootmap_start >> PAGE_SHIFT,
  217. start_pfn, end_pfn);
  218. printk(KERN_INFO " bootmap [%016lx - %016lx] pages %lx\n",
  219. bootmap_start, bootmap_start + bootmap_size - 1,
  220. bootmap_pages);
  221. free_bootmem_with_active_regions(nodeid, end);
  222. /*
  223. * convert early reserve to bootmem reserve earlier
  224. * otherwise early_node_mem could use early reserved mem
  225. * on previous node
  226. */
  227. early_res_to_bootmem(start, end);
  228. /*
  229. * in some case early_node_mem could use alloc_bootmem
  230. * to get range on other node, don't reserve that again
  231. */
  232. if (nid != nodeid)
  233. printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nodeid, nid);
  234. else
  235. reserve_bootmem_node(NODE_DATA(nodeid), nodedata_phys,
  236. pgdat_size, BOOTMEM_DEFAULT);
  237. nid = phys_to_nid(bootmap_start);
  238. if (nid != nodeid)
  239. printk(KERN_INFO " bootmap(%d) on node %d\n", nodeid, nid);
  240. else
  241. reserve_bootmem_node(NODE_DATA(nodeid), bootmap_start,
  242. bootmap_pages<<PAGE_SHIFT, BOOTMEM_DEFAULT);
  243. #ifdef CONFIG_ACPI_NUMA
  244. srat_reserve_add_area(nodeid);
  245. #endif
  246. node_set_online(nodeid);
  247. }
  248. /*
  249. * There are unfortunately some poorly designed mainboards around that
  250. * only connect memory to a single CPU. This breaks the 1:1 cpu->node
  251. * mapping. To avoid this fill in the mapping for all possible CPUs,
  252. * as the number of CPUs is not known yet. We round robin the existing
  253. * nodes.
  254. */
  255. void __init numa_init_array(void)
  256. {
  257. int rr, i;
  258. rr = first_node(node_online_map);
  259. for (i = 0; i < NR_CPUS; i++) {
  260. if (early_cpu_to_node(i) != NUMA_NO_NODE)
  261. continue;
  262. numa_set_node(i, rr);
  263. rr = next_node(rr, node_online_map);
  264. if (rr == MAX_NUMNODES)
  265. rr = first_node(node_online_map);
  266. }
  267. }
  268. #ifdef CONFIG_NUMA_EMU
  269. /* Numa emulation */
  270. char *cmdline __initdata;
  271. /*
  272. * Setups up nid to range from addr to addr + size. If the end
  273. * boundary is greater than max_addr, then max_addr is used instead.
  274. * The return value is 0 if there is additional memory left for
  275. * allocation past addr and -1 otherwise. addr is adjusted to be at
  276. * the end of the node.
  277. */
  278. static int __init setup_node_range(int nid, struct bootnode *nodes, u64 *addr,
  279. u64 size, u64 max_addr)
  280. {
  281. int ret = 0;
  282. nodes[nid].start = *addr;
  283. *addr += size;
  284. if (*addr >= max_addr) {
  285. *addr = max_addr;
  286. ret = -1;
  287. }
  288. nodes[nid].end = *addr;
  289. node_set(nid, node_possible_map);
  290. printk(KERN_INFO "Faking node %d at %016Lx-%016Lx (%LuMB)\n", nid,
  291. nodes[nid].start, nodes[nid].end,
  292. (nodes[nid].end - nodes[nid].start) >> 20);
  293. return ret;
  294. }
  295. /*
  296. * Splits num_nodes nodes up equally starting at node_start. The return value
  297. * is the number of nodes split up and addr is adjusted to be at the end of the
  298. * last node allocated.
  299. */
  300. static int __init split_nodes_equally(struct bootnode *nodes, u64 *addr,
  301. u64 max_addr, int node_start,
  302. int num_nodes)
  303. {
  304. unsigned int big;
  305. u64 size;
  306. int i;
  307. if (num_nodes <= 0)
  308. return -1;
  309. if (num_nodes > MAX_NUMNODES)
  310. num_nodes = MAX_NUMNODES;
  311. size = (max_addr - *addr - e820_hole_size(*addr, max_addr)) /
  312. num_nodes;
  313. /*
  314. * Calculate the number of big nodes that can be allocated as a result
  315. * of consolidating the leftovers.
  316. */
  317. big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * num_nodes) /
  318. FAKE_NODE_MIN_SIZE;
  319. /* Round down to nearest FAKE_NODE_MIN_SIZE. */
  320. size &= FAKE_NODE_MIN_HASH_MASK;
  321. if (!size) {
  322. printk(KERN_ERR "Not enough memory for each node. "
  323. "NUMA emulation disabled.\n");
  324. return -1;
  325. }
  326. for (i = node_start; i < num_nodes + node_start; i++) {
  327. u64 end = *addr + size;
  328. if (i < big)
  329. end += FAKE_NODE_MIN_SIZE;
  330. /*
  331. * The final node can have the remaining system RAM. Other
  332. * nodes receive roughly the same amount of available pages.
  333. */
  334. if (i == num_nodes + node_start - 1)
  335. end = max_addr;
  336. else
  337. while (end - *addr - e820_hole_size(*addr, end) <
  338. size) {
  339. end += FAKE_NODE_MIN_SIZE;
  340. if (end > max_addr) {
  341. end = max_addr;
  342. break;
  343. }
  344. }
  345. if (setup_node_range(i, nodes, addr, end - *addr, max_addr) < 0)
  346. break;
  347. }
  348. return i - node_start + 1;
  349. }
  350. /*
  351. * Splits the remaining system RAM into chunks of size. The remaining memory is
  352. * always assigned to a final node and can be asymmetric. Returns the number of
  353. * nodes split.
  354. */
  355. static int __init split_nodes_by_size(struct bootnode *nodes, u64 *addr,
  356. u64 max_addr, int node_start, u64 size)
  357. {
  358. int i = node_start;
  359. size = (size << 20) & FAKE_NODE_MIN_HASH_MASK;
  360. while (!setup_node_range(i++, nodes, addr, size, max_addr))
  361. ;
  362. return i - node_start;
  363. }
  364. /*
  365. * Sets up the system RAM area from start_pfn to end_pfn according to the
  366. * numa=fake command-line option.
  367. */
  368. static struct bootnode nodes[MAX_NUMNODES] __initdata;
  369. static int __init numa_emulation(unsigned long start_pfn, unsigned long end_pfn)
  370. {
  371. u64 size, addr = start_pfn << PAGE_SHIFT;
  372. u64 max_addr = end_pfn << PAGE_SHIFT;
  373. int num_nodes = 0, num = 0, coeff_flag, coeff = -1, i;
  374. memset(&nodes, 0, sizeof(nodes));
  375. /*
  376. * If the numa=fake command-line is just a single number N, split the
  377. * system RAM into N fake nodes.
  378. */
  379. if (!strchr(cmdline, '*') && !strchr(cmdline, ',')) {
  380. long n = simple_strtol(cmdline, NULL, 0);
  381. num_nodes = split_nodes_equally(nodes, &addr, max_addr, 0, n);
  382. if (num_nodes < 0)
  383. return num_nodes;
  384. goto out;
  385. }
  386. /* Parse the command line. */
  387. for (coeff_flag = 0; ; cmdline++) {
  388. if (*cmdline && isdigit(*cmdline)) {
  389. num = num * 10 + *cmdline - '0';
  390. continue;
  391. }
  392. if (*cmdline == '*') {
  393. if (num > 0)
  394. coeff = num;
  395. coeff_flag = 1;
  396. }
  397. if (!*cmdline || *cmdline == ',') {
  398. if (!coeff_flag)
  399. coeff = 1;
  400. /*
  401. * Round down to the nearest FAKE_NODE_MIN_SIZE.
  402. * Command-line coefficients are in megabytes.
  403. */
  404. size = ((u64)num << 20) & FAKE_NODE_MIN_HASH_MASK;
  405. if (size)
  406. for (i = 0; i < coeff; i++, num_nodes++)
  407. if (setup_node_range(num_nodes, nodes,
  408. &addr, size, max_addr) < 0)
  409. goto done;
  410. if (!*cmdline)
  411. break;
  412. coeff_flag = 0;
  413. coeff = -1;
  414. }
  415. num = 0;
  416. }
  417. done:
  418. if (!num_nodes)
  419. return -1;
  420. /* Fill remainder of system RAM, if appropriate. */
  421. if (addr < max_addr) {
  422. if (coeff_flag && coeff < 0) {
  423. /* Split remaining nodes into num-sized chunks */
  424. num_nodes += split_nodes_by_size(nodes, &addr, max_addr,
  425. num_nodes, num);
  426. goto out;
  427. }
  428. switch (*(cmdline - 1)) {
  429. case '*':
  430. /* Split remaining nodes into coeff chunks */
  431. if (coeff <= 0)
  432. break;
  433. num_nodes += split_nodes_equally(nodes, &addr, max_addr,
  434. num_nodes, coeff);
  435. break;
  436. case ',':
  437. /* Do not allocate remaining system RAM */
  438. break;
  439. default:
  440. /* Give one final node */
  441. setup_node_range(num_nodes, nodes, &addr,
  442. max_addr - addr, max_addr);
  443. num_nodes++;
  444. }
  445. }
  446. out:
  447. memnode_shift = compute_hash_shift(nodes, num_nodes, NULL);
  448. if (memnode_shift < 0) {
  449. memnode_shift = 0;
  450. printk(KERN_ERR "No NUMA hash function found. NUMA emulation "
  451. "disabled.\n");
  452. return -1;
  453. }
  454. /*
  455. * We need to vacate all active ranges that may have been registered by
  456. * SRAT and set acpi_numa to -1 so that srat_disabled() always returns
  457. * true. NUMA emulation has succeeded so we will not scan ACPI nodes.
  458. */
  459. remove_all_active_ranges();
  460. #ifdef CONFIG_ACPI_NUMA
  461. acpi_numa = -1;
  462. #endif
  463. for_each_node_mask(i, node_possible_map) {
  464. e820_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
  465. nodes[i].end >> PAGE_SHIFT);
  466. setup_node_bootmem(i, nodes[i].start, nodes[i].end);
  467. }
  468. acpi_fake_nodes(nodes, num_nodes);
  469. numa_init_array();
  470. return 0;
  471. }
  472. #endif /* CONFIG_NUMA_EMU */
  473. void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
  474. {
  475. int i;
  476. nodes_clear(node_possible_map);
  477. nodes_clear(node_online_map);
  478. #ifdef CONFIG_NUMA_EMU
  479. if (cmdline && !numa_emulation(start_pfn, end_pfn))
  480. return;
  481. nodes_clear(node_possible_map);
  482. nodes_clear(node_online_map);
  483. #endif
  484. #ifdef CONFIG_ACPI_NUMA
  485. if (!numa_off && !acpi_scan_nodes(start_pfn << PAGE_SHIFT,
  486. end_pfn << PAGE_SHIFT))
  487. return;
  488. nodes_clear(node_possible_map);
  489. nodes_clear(node_online_map);
  490. #endif
  491. #ifdef CONFIG_K8_NUMA
  492. if (!numa_off && !k8_scan_nodes(start_pfn<<PAGE_SHIFT,
  493. end_pfn<<PAGE_SHIFT))
  494. return;
  495. nodes_clear(node_possible_map);
  496. nodes_clear(node_online_map);
  497. #endif
  498. printk(KERN_INFO "%s\n",
  499. numa_off ? "NUMA turned off" : "No NUMA configuration found");
  500. printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
  501. start_pfn << PAGE_SHIFT,
  502. end_pfn << PAGE_SHIFT);
  503. /* setup dummy node covering all memory */
  504. memnode_shift = 63;
  505. memnodemap = memnode.embedded_map;
  506. memnodemap[0] = 0;
  507. node_set_online(0);
  508. node_set(0, node_possible_map);
  509. for (i = 0; i < NR_CPUS; i++)
  510. numa_set_node(i, 0);
  511. /* cpumask_of_cpu() may not be available during early startup */
  512. memset(&node_to_cpumask_map[0], 0, sizeof(node_to_cpumask_map[0]));
  513. cpu_set(0, node_to_cpumask_map[0]);
  514. e820_register_active_regions(0, start_pfn, end_pfn);
  515. setup_node_bootmem(0, start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT);
  516. }
  517. __cpuinit void numa_add_cpu(int cpu)
  518. {
  519. set_bit(cpu,
  520. (unsigned long *)&node_to_cpumask_map[early_cpu_to_node(cpu)]);
  521. }
  522. void __cpuinit numa_set_node(int cpu, int node)
  523. {
  524. int *cpu_to_node_map = x86_cpu_to_node_map_early_ptr;
  525. if(cpu_to_node_map)
  526. cpu_to_node_map[cpu] = node;
  527. else if(per_cpu_offset(cpu))
  528. per_cpu(x86_cpu_to_node_map, cpu) = node;
  529. else
  530. Dprintk(KERN_INFO "Setting node for non-present cpu %d\n", cpu);
  531. }
  532. unsigned long __init numa_free_all_bootmem(void)
  533. {
  534. unsigned long pages = 0;
  535. int i;
  536. for_each_online_node(i)
  537. pages += free_all_bootmem_node(NODE_DATA(i));
  538. return pages;
  539. }
  540. void __init paging_init(void)
  541. {
  542. unsigned long max_zone_pfns[MAX_NR_ZONES];
  543. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  544. max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
  545. max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
  546. max_zone_pfns[ZONE_NORMAL] = end_pfn;
  547. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  548. sparse_init();
  549. free_area_init_nodes(max_zone_pfns);
  550. }
  551. static __init int numa_setup(char *opt)
  552. {
  553. if (!opt)
  554. return -EINVAL;
  555. if (!strncmp(opt, "off", 3))
  556. numa_off = 1;
  557. #ifdef CONFIG_NUMA_EMU
  558. if (!strncmp(opt, "fake=", 5))
  559. cmdline = opt + 5;
  560. #endif
  561. #ifdef CONFIG_ACPI_NUMA
  562. if (!strncmp(opt, "noacpi", 6))
  563. acpi_numa = -1;
  564. if (!strncmp(opt, "hotadd=", 7))
  565. hotadd_percent = simple_strtoul(opt+7, NULL, 10);
  566. #endif
  567. return 0;
  568. }
  569. early_param("numa", numa_setup);
  570. /*
  571. * Setup early cpu_to_node.
  572. *
  573. * Populate cpu_to_node[] only if x86_cpu_to_apicid[],
  574. * and apicid_to_node[] tables have valid entries for a CPU.
  575. * This means we skip cpu_to_node[] initialisation for NUMA
  576. * emulation and faking node case (when running a kernel compiled
  577. * for NUMA on a non NUMA box), which is OK as cpu_to_node[]
  578. * is already initialized in a round robin manner at numa_init_array,
  579. * prior to this call, and this initialization is good enough
  580. * for the fake NUMA cases.
  581. */
  582. void __init init_cpu_to_node(void)
  583. {
  584. int i;
  585. for (i = 0; i < NR_CPUS; i++) {
  586. int node;
  587. u16 apicid = x86_cpu_to_apicid_init[i];
  588. if (apicid == BAD_APICID)
  589. continue;
  590. node = apicid_to_node[apicid];
  591. if (node == NUMA_NO_NODE)
  592. continue;
  593. if (!node_online(node))
  594. continue;
  595. numa_set_node(i, node);
  596. }
  597. }