4 #include <linux/kernel.h>
5 #include <linux/errno.h>
25 for (i = 0; i < mi->
nr_blks; i++)
26 if (mi->
blk[i].nid == nid)
33 unsigned long start_pfn =
PFN_UP(start);
34 unsigned long end_pfn =
PFN_DOWN(end);
36 if (start_pfn < end_pfn)
37 return PFN_PHYS(absent_pages_in_range(start_pfn, end_pfn));
47 int nid,
int phys_blk,
u64 size)
53 pr_err(
"NUMA: Too many emulated memblks, failing emulation\n");
63 emu_nid_to_phys[
nid] =
nid;
93 pr_info(
"numa=fake=%d too large, reducing to %d\n",
102 size = max_addr - addr - mem_hole_size(addr, max_addr);
109 big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
112 size &= FAKE_NODE_MIN_HASH_MASK;
114 pr_err(
"Not enough memory for each node. "
115 "NUMA emulation disabled.\n");
119 for (i = 0; i < pi->
nr_blks; i++)
132 phys_blk = emu_find_memblk_by_nid(i, pi);
137 start = pi->
blk[phys_blk].start;
138 limit = pi->
blk[phys_blk].end;
142 end += FAKE_NODE_MIN_SIZE;
148 while (end - start - mem_hole_size(start, end) < size) {
149 end += FAKE_NODE_MIN_SIZE;
161 if (end < dma32_end && dma32_end - end -
162 mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
170 if (limit - end - mem_hole_size(end, limit) < size)
173 ret = emu_setup_memblk(ei, pi, nid++ % nr_nodes,
175 min(end, limit) - start);
191 while (end - start - mem_hole_size(start, end) < size) {
192 end += FAKE_NODE_MIN_SIZE;
193 if (end > max_addr) {
222 min_size = (max_addr - addr - mem_hole_size(addr, max_addr)) /
MAX_NUMNODES;
223 min_size =
max(min_size, FAKE_NODE_MIN_SIZE);
224 if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
225 min_size = (min_size + FAKE_NODE_MIN_SIZE) &
226 FAKE_NODE_MIN_HASH_MASK;
227 if (size < min_size) {
228 pr_err(
"Fake node size %LuMB too small, increasing to %LuMB\n",
229 size >> 20, min_size >> 20);
232 size &= FAKE_NODE_MIN_HASH_MASK;
234 for (i = 0; i < pi->
nr_blks; i++)
247 phys_blk = emu_find_memblk_by_nid(i, pi);
252 start = pi->
blk[phys_blk].start;
253 limit = pi->
blk[phys_blk].end;
255 end = find_end_of_node(start, limit, size);
261 if (end < dma32_end && dma32_end - end -
262 mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
270 if (limit - end - mem_hole_size(end, limit) < size)
275 min(end, limit) - start);
312 static struct numa_meminfo ei __initdata;
313 static struct numa_meminfo pi __initdata;
316 size_t phys_size = numa_dist_cnt * numa_dist_cnt *
sizeof(phys_dist[0]);
317 int max_emu_nid, dfl_phys_nid;
323 memset(&ei, 0,
sizeof(ei));
334 if (
strchr(emu_cmdline,
'M') ||
strchr(emu_cmdline,
'G')) {
337 size =
memparse(emu_cmdline, &emu_cmdline);
338 ret = split_nodes_size_interleave(&ei, &pi, 0, max_addr, size);
343 ret = split_nodes_interleave(&ei, &pi, 0, max_addr, n);
345 if (*emu_cmdline ==
':')
352 pr_warning(
"NUMA: Warning: constructed meminfo invalid, disabling emulation\n");
363 pr_warning(
"NUMA: Warning: can't allocate copy of distance table, disabling emulation\n");
367 phys_dist =
__va(phys);
369 for (i = 0; i < numa_dist_cnt; i++)
370 for (j = 0; j < numa_dist_cnt; j++)
371 phys_dist[i * numa_dist_cnt + j] =
381 for (i = 0; i <
ARRAY_SIZE(emu_nid_to_phys); i++) {
385 dfl_phys_nid = emu_nid_to_phys[
i];
389 pr_warning(
"NUMA: Warning: can't determine default physical node, disabling emulation\n");
401 for (i = 0; i <
ARRAY_SIZE(__apicid_to_node); i++) {
404 for (j = 0; j <
ARRAY_SIZE(emu_nid_to_phys); j++)
405 if (__apicid_to_node[i] == emu_nid_to_phys[j])
407 __apicid_to_node[
i] = j <
ARRAY_SIZE(emu_nid_to_phys) ? j : 0;
411 for (i = 0; i <
ARRAY_SIZE(emu_nid_to_phys); i++)
413 emu_nid_to_phys[
i] = dfl_phys_nid;
417 for (i = 0; i < max_emu_nid + 1; i++) {
418 for (j = 0; j < max_emu_nid + 1; j++) {
419 int physi = emu_nid_to_phys[
i];
420 int physj = emu_nid_to_phys[
j];
425 else if (physi >= numa_dist_cnt || physj >= numa_dist_cnt)
426 dist = physi == physj ?
429 dist = phys_dist[physi * numa_dist_cnt + physj];
442 for (i = 0; i <
ARRAY_SIZE(emu_nid_to_phys); i++)
443 emu_nid_to_phys[i] = i;
446 #ifndef CONFIG_DEBUG_PER_CPU_MAPS
451 nid = early_cpu_to_node(cpu);
454 physnid = emu_nid_to_phys[nid];
461 if (emu_nid_to_phys[nid] == physnid)
477 nid = early_cpu_to_node(cpu);
483 physnid = emu_nid_to_phys[nid];
486 if (emu_nid_to_phys[nid] != physnid)
489 debug_cpumask_set_cpu(cpu, nid, enable);
495 numa_set_cpumask(cpu,
true);
500 numa_set_cpumask(cpu,
false);