numa.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * pSeries NUMA support
  3. *
  4. * Copyright (C) 2002 Anton Blanchard <anton@au.ibm.com>, IBM
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/threads.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/init.h>
  14. #include <linux/mm.h>
  15. #include <linux/mmzone.h>
  16. #include <linux/module.h>
  17. #include <linux/nodemask.h>
  18. #include <linux/cpu.h>
  19. #include <linux/notifier.h>
  20. #include <asm/lmb.h>
  21. #include <asm/machdep.h>
  22. #include <asm/abs_addr.h>
  23. static int numa_enabled = 1;
  24. static int numa_debug;
  25. #define dbg(args...) if (numa_debug) { printk(KERN_INFO args); }
  26. #ifdef DEBUG_NUMA
  27. #define ARRAY_INITIALISER -1
  28. #else
  29. #define ARRAY_INITIALISER 0
  30. #endif
  31. int numa_cpu_lookup_table[NR_CPUS] = { [ 0 ... (NR_CPUS - 1)] =
  32. ARRAY_INITIALISER};
  33. char *numa_memory_lookup_table;
  34. cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES];
  35. int nr_cpus_in_node[MAX_NUMNODES] = { [0 ... (MAX_NUMNODES -1)] = 0};
  36. struct pglist_data *node_data[MAX_NUMNODES];
  37. bootmem_data_t __initdata plat_node_bdata[MAX_NUMNODES];
  38. static int min_common_depth;
  39. /*
  40. * We need somewhere to store start/span for each node until we have
  41. * allocated the real node_data structures.
  42. */
  43. static struct {
  44. unsigned long node_start_pfn;
  45. unsigned long node_end_pfn;
  46. unsigned long node_present_pages;
  47. } init_node_data[MAX_NUMNODES] __initdata;
  48. EXPORT_SYMBOL(node_data);
  49. EXPORT_SYMBOL(numa_cpu_lookup_table);
  50. EXPORT_SYMBOL(numa_memory_lookup_table);
  51. EXPORT_SYMBOL(numa_cpumask_lookup_table);
  52. EXPORT_SYMBOL(nr_cpus_in_node);
  53. static inline void map_cpu_to_node(int cpu, int node)
  54. {
  55. numa_cpu_lookup_table[cpu] = node;
  56. if (!(cpu_isset(cpu, numa_cpumask_lookup_table[node]))) {
  57. cpu_set(cpu, numa_cpumask_lookup_table[node]);
  58. nr_cpus_in_node[node]++;
  59. }
  60. }
  61. #ifdef CONFIG_HOTPLUG_CPU
  62. static void unmap_cpu_from_node(unsigned long cpu)
  63. {
  64. int node = numa_cpu_lookup_table[cpu];
  65. dbg("removing cpu %lu from node %d\n", cpu, node);
  66. if (cpu_isset(cpu, numa_cpumask_lookup_table[node])) {
  67. cpu_clear(cpu, numa_cpumask_lookup_table[node]);
  68. nr_cpus_in_node[node]--;
  69. } else {
  70. printk(KERN_ERR "WARNING: cpu %lu not found in node %d\n",
  71. cpu, node);
  72. }
  73. }
  74. #endif /* CONFIG_HOTPLUG_CPU */
  75. static struct device_node * __devinit find_cpu_node(unsigned int cpu)
  76. {
  77. unsigned int hw_cpuid = get_hard_smp_processor_id(cpu);
  78. struct device_node *cpu_node = NULL;
  79. unsigned int *interrupt_server, *reg;
  80. int len;
  81. while ((cpu_node = of_find_node_by_type(cpu_node, "cpu")) != NULL) {
  82. /* Try interrupt server first */
  83. interrupt_server = (unsigned int *)get_property(cpu_node,
  84. "ibm,ppc-interrupt-server#s", &len);
  85. len = len / sizeof(u32);
  86. if (interrupt_server && (len > 0)) {
  87. while (len--) {
  88. if (interrupt_server[len] == hw_cpuid)
  89. return cpu_node;
  90. }
  91. } else {
  92. reg = (unsigned int *)get_property(cpu_node,
  93. "reg", &len);
  94. if (reg && (len > 0) && (reg[0] == hw_cpuid))
  95. return cpu_node;
  96. }
  97. }
  98. return NULL;
  99. }
  100. /* must hold reference to node during call */
  101. static int *of_get_associativity(struct device_node *dev)
  102. {
  103. return (unsigned int *)get_property(dev, "ibm,associativity", NULL);
  104. }
  105. static int of_node_numa_domain(struct device_node *device)
  106. {
  107. int numa_domain;
  108. unsigned int *tmp;
  109. if (min_common_depth == -1)
  110. return 0;
  111. tmp = of_get_associativity(device);
  112. if (tmp && (tmp[0] >= min_common_depth)) {
  113. numa_domain = tmp[min_common_depth];
  114. } else {
  115. dbg("WARNING: no NUMA information for %s\n",
  116. device->full_name);
  117. numa_domain = 0;
  118. }
  119. return numa_domain;
  120. }
  121. /*
  122. * In theory, the "ibm,associativity" property may contain multiple
  123. * associativity lists because a resource may be multiply connected
  124. * into the machine. This resource then has different associativity
  125. * characteristics relative to its multiple connections. We ignore
  126. * this for now. We also assume that all cpu and memory sets have
  127. * their distances represented at a common level. This won't be
  128. * true for heirarchical NUMA.
  129. *
  130. * In any case the ibm,associativity-reference-points should give
  131. * the correct depth for a normal NUMA system.
  132. *
  133. * - Dave Hansen <haveblue@us.ibm.com>
  134. */
  135. static int __init find_min_common_depth(void)
  136. {
  137. int depth;
  138. unsigned int *ref_points;
  139. struct device_node *rtas_root;
  140. unsigned int len;
  141. rtas_root = of_find_node_by_path("/rtas");
  142. if (!rtas_root)
  143. return -1;
  144. /*
  145. * this property is 2 32-bit integers, each representing a level of
  146. * depth in the associativity nodes. The first is for an SMP
  147. * configuration (should be all 0's) and the second is for a normal
  148. * NUMA configuration.
  149. */
  150. ref_points = (unsigned int *)get_property(rtas_root,
  151. "ibm,associativity-reference-points", &len);
  152. if ((len >= 1) && ref_points) {
  153. depth = ref_points[1];
  154. } else {
  155. dbg("WARNING: could not find NUMA "
  156. "associativity reference point\n");
  157. depth = -1;
  158. }
  159. of_node_put(rtas_root);
  160. return depth;
  161. }
  162. static int __init get_mem_addr_cells(void)
  163. {
  164. struct device_node *memory = NULL;
  165. int rc;
  166. memory = of_find_node_by_type(memory, "memory");
  167. if (!memory)
  168. return 0; /* it won't matter */
  169. rc = prom_n_addr_cells(memory);
  170. return rc;
  171. }
  172. static int __init get_mem_size_cells(void)
  173. {
  174. struct device_node *memory = NULL;
  175. int rc;
  176. memory = of_find_node_by_type(memory, "memory");
  177. if (!memory)
  178. return 0; /* it won't matter */
  179. rc = prom_n_size_cells(memory);
  180. return rc;
  181. }
  182. static unsigned long read_n_cells(int n, unsigned int **buf)
  183. {
  184. unsigned long result = 0;
  185. while (n--) {
  186. result = (result << 32) | **buf;
  187. (*buf)++;
  188. }
  189. return result;
  190. }
  191. /*
  192. * Figure out to which domain a cpu belongs and stick it there.
  193. * Return the id of the domain used.
  194. */
  195. static int numa_setup_cpu(unsigned long lcpu)
  196. {
  197. int numa_domain = 0;
  198. struct device_node *cpu = find_cpu_node(lcpu);
  199. if (!cpu) {
  200. WARN_ON(1);
  201. goto out;
  202. }
  203. numa_domain = of_node_numa_domain(cpu);
  204. if (numa_domain >= num_online_nodes()) {
  205. /*
  206. * POWER4 LPAR uses 0xffff as invalid node,
  207. * dont warn in this case.
  208. */
  209. if (numa_domain != 0xffff)
  210. printk(KERN_ERR "WARNING: cpu %ld "
  211. "maps to invalid NUMA node %d\n",
  212. lcpu, numa_domain);
  213. numa_domain = 0;
  214. }
  215. out:
  216. node_set_online(numa_domain);
  217. map_cpu_to_node(lcpu, numa_domain);
  218. of_node_put(cpu);
  219. return numa_domain;
  220. }
  221. static int cpu_numa_callback(struct notifier_block *nfb,
  222. unsigned long action,
  223. void *hcpu)
  224. {
  225. unsigned long lcpu = (unsigned long)hcpu;
  226. int ret = NOTIFY_DONE;
  227. switch (action) {
  228. case CPU_UP_PREPARE:
  229. if (min_common_depth == -1 || !numa_enabled)
  230. map_cpu_to_node(lcpu, 0);
  231. else
  232. numa_setup_cpu(lcpu);
  233. ret = NOTIFY_OK;
  234. break;
  235. #ifdef CONFIG_HOTPLUG_CPU
  236. case CPU_DEAD:
  237. case CPU_UP_CANCELED:
  238. unmap_cpu_from_node(lcpu);
  239. break;
  240. ret = NOTIFY_OK;
  241. #endif
  242. }
  243. return ret;
  244. }
  245. /*
  246. * Check and possibly modify a memory region to enforce the memory limit.
  247. *
  248. * Returns the size the region should have to enforce the memory limit.
  249. * This will either be the original value of size, a truncated value,
  250. * or zero. If the returned value of size is 0 the region should be
  251. * discarded as it lies wholy above the memory limit.
  252. */
  253. static unsigned long __init numa_enforce_memory_limit(unsigned long start, unsigned long size)
  254. {
  255. /*
  256. * We use lmb_end_of_DRAM() in here instead of memory_limit because
  257. * we've already adjusted it for the limit and it takes care of
  258. * having memory holes below the limit.
  259. */
  260. extern unsigned long memory_limit;
  261. if (! memory_limit)
  262. return size;
  263. if (start + size <= lmb_end_of_DRAM())
  264. return size;
  265. if (start >= lmb_end_of_DRAM())
  266. return 0;
  267. return lmb_end_of_DRAM() - start;
  268. }
  269. static int __init parse_numa_properties(void)
  270. {
  271. struct device_node *cpu = NULL;
  272. struct device_node *memory = NULL;
  273. int addr_cells, size_cells;
  274. int max_domain = 0;
  275. long entries = lmb_end_of_DRAM() >> MEMORY_INCREMENT_SHIFT;
  276. unsigned long i;
  277. if (numa_enabled == 0) {
  278. printk(KERN_WARNING "NUMA disabled by user\n");
  279. return -1;
  280. }
  281. numa_memory_lookup_table =
  282. (char *)abs_to_virt(lmb_alloc(entries * sizeof(char), 1));
  283. memset(numa_memory_lookup_table, 0, entries * sizeof(char));
  284. for (i = 0; i < entries ; i++)
  285. numa_memory_lookup_table[i] = ARRAY_INITIALISER;
  286. min_common_depth = find_min_common_depth();
  287. dbg("NUMA associativity depth for CPU/Memory: %d\n", min_common_depth);
  288. if (min_common_depth < 0)
  289. return min_common_depth;
  290. max_domain = numa_setup_cpu(boot_cpuid);
  291. /*
  292. * Even though we connect cpus to numa domains later in SMP init,
  293. * we need to know the maximum node id now. This is because each
  294. * node id must have NODE_DATA etc backing it.
  295. * As a result of hotplug we could still have cpus appear later on
  296. * with larger node ids. In that case we force the cpu into node 0.
  297. */
  298. for_each_cpu(i) {
  299. int numa_domain;
  300. cpu = find_cpu_node(i);
  301. if (cpu) {
  302. numa_domain = of_node_numa_domain(cpu);
  303. of_node_put(cpu);
  304. if (numa_domain < MAX_NUMNODES &&
  305. max_domain < numa_domain)
  306. max_domain = numa_domain;
  307. }
  308. }
  309. addr_cells = get_mem_addr_cells();
  310. size_cells = get_mem_size_cells();
  311. memory = NULL;
  312. while ((memory = of_find_node_by_type(memory, "memory")) != NULL) {
  313. unsigned long start;
  314. unsigned long size;
  315. int numa_domain;
  316. int ranges;
  317. unsigned int *memcell_buf;
  318. unsigned int len;
  319. memcell_buf = (unsigned int *)get_property(memory, "reg", &len);
  320. if (!memcell_buf || len <= 0)
  321. continue;
  322. ranges = memory->n_addrs;
  323. new_range:
  324. /* these are order-sensitive, and modify the buffer pointer */
  325. start = read_n_cells(addr_cells, &memcell_buf);
  326. size = read_n_cells(size_cells, &memcell_buf);
  327. start = _ALIGN_DOWN(start, MEMORY_INCREMENT);
  328. size = _ALIGN_UP(size, MEMORY_INCREMENT);
  329. numa_domain = of_node_numa_domain(memory);
  330. if (numa_domain >= MAX_NUMNODES) {
  331. if (numa_domain != 0xffff)
  332. printk(KERN_ERR "WARNING: memory at %lx maps "
  333. "to invalid NUMA node %d\n", start,
  334. numa_domain);
  335. numa_domain = 0;
  336. }
  337. if (max_domain < numa_domain)
  338. max_domain = numa_domain;
  339. if (! (size = numa_enforce_memory_limit(start, size))) {
  340. if (--ranges)
  341. goto new_range;
  342. else
  343. continue;
  344. }
  345. /*
  346. * Initialize new node struct, or add to an existing one.
  347. */
  348. if (init_node_data[numa_domain].node_end_pfn) {
  349. if ((start / PAGE_SIZE) <
  350. init_node_data[numa_domain].node_start_pfn)
  351. init_node_data[numa_domain].node_start_pfn =
  352. start / PAGE_SIZE;
  353. if (((start / PAGE_SIZE) + (size / PAGE_SIZE)) >
  354. init_node_data[numa_domain].node_end_pfn)
  355. init_node_data[numa_domain].node_end_pfn =
  356. (start / PAGE_SIZE) +
  357. (size / PAGE_SIZE);
  358. init_node_data[numa_domain].node_present_pages +=
  359. size / PAGE_SIZE;
  360. } else {
  361. node_set_online(numa_domain);
  362. init_node_data[numa_domain].node_start_pfn =
  363. start / PAGE_SIZE;
  364. init_node_data[numa_domain].node_end_pfn =
  365. init_node_data[numa_domain].node_start_pfn +
  366. size / PAGE_SIZE;
  367. init_node_data[numa_domain].node_present_pages =
  368. size / PAGE_SIZE;
  369. }
  370. for (i = start ; i < (start+size); i += MEMORY_INCREMENT)
  371. numa_memory_lookup_table[i >> MEMORY_INCREMENT_SHIFT] =
  372. numa_domain;
  373. memory_present(numa_domain, start >> PAGE_SHIFT,
  374. (start + size) >> PAGE_SHIFT);
  375. if (--ranges)
  376. goto new_range;
  377. }
  378. for (i = 0; i <= max_domain; i++)
  379. node_set_online(i);
  380. return 0;
  381. }
  382. static void __init setup_nonnuma(void)
  383. {
  384. unsigned long top_of_ram = lmb_end_of_DRAM();
  385. unsigned long total_ram = lmb_phys_mem_size();
  386. unsigned long i;
  387. printk(KERN_INFO "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
  388. top_of_ram, total_ram);
  389. printk(KERN_INFO "Memory hole size: %ldMB\n",
  390. (top_of_ram - total_ram) >> 20);
  391. if (!numa_memory_lookup_table) {
  392. long entries = top_of_ram >> MEMORY_INCREMENT_SHIFT;
  393. numa_memory_lookup_table =
  394. (char *)abs_to_virt(lmb_alloc(entries * sizeof(char), 1));
  395. memset(numa_memory_lookup_table, 0, entries * sizeof(char));
  396. for (i = 0; i < entries ; i++)
  397. numa_memory_lookup_table[i] = ARRAY_INITIALISER;
  398. }
  399. map_cpu_to_node(boot_cpuid, 0);
  400. node_set_online(0);
  401. init_node_data[0].node_start_pfn = 0;
  402. init_node_data[0].node_end_pfn = lmb_end_of_DRAM() / PAGE_SIZE;
  403. init_node_data[0].node_present_pages = total_ram / PAGE_SIZE;
  404. for (i = 0 ; i < top_of_ram; i += MEMORY_INCREMENT)
  405. numa_memory_lookup_table[i >> MEMORY_INCREMENT_SHIFT] = 0;
  406. memory_present(0, 0, init_node_data[0].node_end_pfn);
  407. }
  408. static void __init dump_numa_topology(void)
  409. {
  410. unsigned int node;
  411. unsigned int count;
  412. if (min_common_depth == -1 || !numa_enabled)
  413. return;
  414. for_each_online_node(node) {
  415. unsigned long i;
  416. printk(KERN_INFO "Node %d Memory:", node);
  417. count = 0;
  418. for (i = 0; i < lmb_end_of_DRAM(); i += MEMORY_INCREMENT) {
  419. if (numa_memory_lookup_table[i >> MEMORY_INCREMENT_SHIFT] == node) {
  420. if (count == 0)
  421. printk(" 0x%lx", i);
  422. ++count;
  423. } else {
  424. if (count > 0)
  425. printk("-0x%lx", i);
  426. count = 0;
  427. }
  428. }
  429. if (count > 0)
  430. printk("-0x%lx", i);
  431. printk("\n");
  432. }
  433. return;
  434. }
  435. /*
  436. * Allocate some memory, satisfying the lmb or bootmem allocator where
  437. * required. nid is the preferred node and end is the physical address of
  438. * the highest address in the node.
  439. *
  440. * Returns the physical address of the memory.
  441. */
  442. static unsigned long careful_allocation(int nid, unsigned long size,
  443. unsigned long align, unsigned long end)
  444. {
  445. unsigned long ret = lmb_alloc_base(size, align, end);
  446. /* retry over all memory */
  447. if (!ret)
  448. ret = lmb_alloc_base(size, align, lmb_end_of_DRAM());
  449. if (!ret)
  450. panic("numa.c: cannot allocate %lu bytes on node %d",
  451. size, nid);
  452. /*
  453. * If the memory came from a previously allocated node, we must
  454. * retry with the bootmem allocator.
  455. */
  456. if (pa_to_nid(ret) < nid) {
  457. nid = pa_to_nid(ret);
  458. ret = (unsigned long)__alloc_bootmem_node(NODE_DATA(nid),
  459. size, align, 0);
  460. if (!ret)
  461. panic("numa.c: cannot allocate %lu bytes on node %d",
  462. size, nid);
  463. ret = virt_to_abs(ret);
  464. dbg("alloc_bootmem %lx %lx\n", ret, size);
  465. }
  466. return ret;
  467. }
  468. void __init do_init_bootmem(void)
  469. {
  470. int nid;
  471. int addr_cells, size_cells;
  472. struct device_node *memory = NULL;
  473. static struct notifier_block ppc64_numa_nb = {
  474. .notifier_call = cpu_numa_callback,
  475. .priority = 1 /* Must run before sched domains notifier. */
  476. };
  477. min_low_pfn = 0;
  478. max_low_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
  479. max_pfn = max_low_pfn;
  480. if (parse_numa_properties())
  481. setup_nonnuma();
  482. else
  483. dump_numa_topology();
  484. register_cpu_notifier(&ppc64_numa_nb);
  485. for_each_online_node(nid) {
  486. unsigned long start_paddr, end_paddr;
  487. int i;
  488. unsigned long bootmem_paddr;
  489. unsigned long bootmap_pages;
  490. start_paddr = init_node_data[nid].node_start_pfn * PAGE_SIZE;
  491. end_paddr = init_node_data[nid].node_end_pfn * PAGE_SIZE;
  492. /* Allocate the node structure node local if possible */
  493. NODE_DATA(nid) = (struct pglist_data *)careful_allocation(nid,
  494. sizeof(struct pglist_data),
  495. SMP_CACHE_BYTES, end_paddr);
  496. NODE_DATA(nid) = abs_to_virt(NODE_DATA(nid));
  497. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  498. dbg("node %d\n", nid);
  499. dbg("NODE_DATA() = %p\n", NODE_DATA(nid));
  500. NODE_DATA(nid)->bdata = &plat_node_bdata[nid];
  501. NODE_DATA(nid)->node_start_pfn =
  502. init_node_data[nid].node_start_pfn;
  503. NODE_DATA(nid)->node_spanned_pages =
  504. end_paddr - start_paddr;
  505. if (NODE_DATA(nid)->node_spanned_pages == 0)
  506. continue;
  507. dbg("start_paddr = %lx\n", start_paddr);
  508. dbg("end_paddr = %lx\n", end_paddr);
  509. bootmap_pages = bootmem_bootmap_pages((end_paddr - start_paddr) >> PAGE_SHIFT);
  510. bootmem_paddr = careful_allocation(nid,
  511. bootmap_pages << PAGE_SHIFT,
  512. PAGE_SIZE, end_paddr);
  513. memset(abs_to_virt(bootmem_paddr), 0,
  514. bootmap_pages << PAGE_SHIFT);
  515. dbg("bootmap_paddr = %lx\n", bootmem_paddr);
  516. init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
  517. start_paddr >> PAGE_SHIFT,
  518. end_paddr >> PAGE_SHIFT);
  519. /*
  520. * We need to do another scan of all memory sections to
  521. * associate memory with the correct node.
  522. */
  523. addr_cells = get_mem_addr_cells();
  524. size_cells = get_mem_size_cells();
  525. memory = NULL;
  526. while ((memory = of_find_node_by_type(memory, "memory")) != NULL) {
  527. unsigned long mem_start, mem_size;
  528. int numa_domain, ranges;
  529. unsigned int *memcell_buf;
  530. unsigned int len;
  531. memcell_buf = (unsigned int *)get_property(memory, "reg", &len);
  532. if (!memcell_buf || len <= 0)
  533. continue;
  534. ranges = memory->n_addrs; /* ranges in cell */
  535. new_range:
  536. mem_start = read_n_cells(addr_cells, &memcell_buf);
  537. mem_size = read_n_cells(size_cells, &memcell_buf);
  538. numa_domain = numa_enabled ? of_node_numa_domain(memory) : 0;
  539. if (numa_domain != nid)
  540. continue;
  541. mem_size = numa_enforce_memory_limit(mem_start, mem_size);
  542. if (mem_size) {
  543. dbg("free_bootmem %lx %lx\n", mem_start, mem_size);
  544. free_bootmem_node(NODE_DATA(nid), mem_start, mem_size);
  545. }
  546. if (--ranges) /* process all ranges in cell */
  547. goto new_range;
  548. }
  549. /*
  550. * Mark reserved regions on this node
  551. */
  552. for (i = 0; i < lmb.reserved.cnt; i++) {
  553. unsigned long physbase = lmb.reserved.region[i].physbase;
  554. unsigned long size = lmb.reserved.region[i].size;
  555. if (pa_to_nid(physbase) != nid &&
  556. pa_to_nid(physbase+size-1) != nid)
  557. continue;
  558. if (physbase < end_paddr &&
  559. (physbase+size) > start_paddr) {
  560. /* overlaps */
  561. if (physbase < start_paddr) {
  562. size -= start_paddr - physbase;
  563. physbase = start_paddr;
  564. }
  565. if (size > end_paddr - physbase)
  566. size = end_paddr - physbase;
  567. dbg("reserve_bootmem %lx %lx\n", physbase,
  568. size);
  569. reserve_bootmem_node(NODE_DATA(nid), physbase,
  570. size);
  571. }
  572. }
  573. }
  574. }
  575. void __init paging_init(void)
  576. {
  577. unsigned long zones_size[MAX_NR_ZONES];
  578. unsigned long zholes_size[MAX_NR_ZONES];
  579. int nid;
  580. memset(zones_size, 0, sizeof(zones_size));
  581. memset(zholes_size, 0, sizeof(zholes_size));
  582. for_each_online_node(nid) {
  583. unsigned long start_pfn;
  584. unsigned long end_pfn;
  585. start_pfn = init_node_data[nid].node_start_pfn;
  586. end_pfn = init_node_data[nid].node_end_pfn;
  587. zones_size[ZONE_DMA] = end_pfn - start_pfn;
  588. zholes_size[ZONE_DMA] = zones_size[ZONE_DMA] -
  589. init_node_data[nid].node_present_pages;
  590. dbg("free_area_init node %d %lx %lx (hole: %lx)\n", nid,
  591. zones_size[ZONE_DMA], start_pfn, zholes_size[ZONE_DMA]);
  592. free_area_init_node(nid, NODE_DATA(nid), zones_size,
  593. start_pfn, zholes_size);
  594. }
  595. }
  596. static int __init early_numa(char *p)
  597. {
  598. if (!p)
  599. return 0;
  600. if (strstr(p, "off"))
  601. numa_enabled = 0;
  602. if (strstr(p, "debug"))
  603. numa_debug = 1;
  604. return 0;
  605. }
  606. early_param("numa", early_numa);