From: Cheng-Yang Chou <yphbchou0911@gmail.com>
To: sched-ext@lists.linux.dev, Tejun Heo <tj@kernel.org>,
David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Mike Rapoport <rppt@kernel.org>
Cc: Ching-Chun Huang <jserv@ccns.ncku.edu.tw>,
Chia-Ping Tsai <chia7712@gmail.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>, "H . Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Arnd Bergmann <arnd@arndb.de>,
linux-arch@vger.kernel.org, chengyang.chou@mediatek.com,
Cheng-Yang Chou <yphbchou0911@gmail.com>
Subject: [PATCH v2 mm and sched_ext/for-7.5 1/2] mm/fake-numa: map each CPU only to its own node
Date: Tue, 1 Dec 2026 17:18:02 +0800 [thread overview]
Message-ID: <20261201091829.16311-2-yphbchou0911@gmail.com> (raw)
In-Reply-To: <20261201091829.16311-1-yphbchou0911@gmail.com>
With numa=fake, numa_add_cpu() sets a CPU in cpumask_of_node() of every
emulated node on its physical node, while cpu_to_node() returns only
one of them. On a Raspberry Pi 5, whose firmware adds numa=fake=8, all
eight nodes list CPUs 0-3 and have N_CPU set, but cpu_to_node() is 0
for every CPU.
No real topology puts a CPU in more than one node, and code that walks
N_CPU or cpumask_of_node() expects them to agree with cpu_to_node().
For example, sched_ext tracks idle CPUs by cpu_to_node(), so the seven
other nodes can never have an idle CPU even though N_CPU says they
have CPUs.
Set a CPU only in the cpumask of its own node, the same as without
emulation. The other emulated nodes on the same physical node become
memory-only nodes. Also drop the code this leaves unused.
On that rpi5, node 0 now lists CPUs 0-3, nodes 1-7 list none and has_cpu
is 0, while the interleave policy the rpi5 kernel sets still spreads
memory over all eight nodes.
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
arch/x86/mm/numa.c | 4 ---
include/asm-generic/numa.h | 4 ---
mm/arch_numa.c | 26 ---------------
mm/numa_emulation.c | 67 ++------------------------------------
4 files changed, 3 insertions(+), 98 deletions(-)
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index ced66e68a68e..55d0fe9cd0b2 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -323,7 +323,6 @@ void __init init_cpu_to_node(void)
#ifndef CONFIG_DEBUG_PER_CPU_MAPS
-# ifndef CONFIG_NUMA_EMU
void numa_add_cpu(unsigned int cpu)
{
cpumask_set_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
@@ -333,7 +332,6 @@ void numa_remove_cpu(unsigned int cpu)
{
cpumask_clear_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
}
-# endif /* !CONFIG_NUMA_EMU */
#else /* !CONFIG_DEBUG_PER_CPU_MAPS */
@@ -393,7 +391,6 @@ void debug_cpumask_set_cpu(unsigned int cpu, int node, bool enable)
return;
}
-# ifndef CONFIG_NUMA_EMU
static void numa_set_cpumask(int cpu, bool enable)
{
debug_cpumask_set_cpu(cpu, early_cpu_to_node(cpu), enable);
@@ -408,7 +405,6 @@ void numa_remove_cpu(unsigned int cpu)
{
numa_set_cpumask(cpu, false);
}
-# endif /* !CONFIG_NUMA_EMU */
/*
* Returns a pointer to the bitmask of CPUs on Node 'node'.
diff --git a/include/asm-generic/numa.h b/include/asm-generic/numa.h
index e063d6487f66..f7397c158860 100644
--- a/include/asm-generic/numa.h
+++ b/include/asm-generic/numa.h
@@ -49,8 +49,4 @@ static inline int early_cpu_to_node(int cpu) { return 0; }
#endif /* CONFIG_NUMA */
-#ifdef CONFIG_NUMA_EMU
-void debug_cpumask_set_cpu(unsigned int cpu, int node, bool enable);
-#endif
-
#endif /* __ASM_GENERIC_NUMA_H */
diff --git a/mm/arch_numa.c b/mm/arch_numa.c
index a4b1732274fa..c69d301129d7 100644
--- a/mm/arch_numa.c
+++ b/mm/arch_numa.c
@@ -59,7 +59,6 @@ EXPORT_SYMBOL(cpumask_of_node);
#endif
-#ifndef CONFIG_NUMA_EMU
static void numa_update_cpu(unsigned int cpu, bool remove)
{
int nid = cpu_to_node(cpu);
@@ -82,7 +81,6 @@ void numa_remove_cpu(unsigned int cpu)
{
numa_update_cpu(cpu, true);
}
-#endif
void numa_clear_node(unsigned int cpu)
{
@@ -356,28 +354,4 @@ u64 __init numa_emu_dma_end(void)
{
return memblock_start_of_DRAM() + SZ_4G;
}
-
-void debug_cpumask_set_cpu(unsigned int cpu, int node, bool enable)
-{
- struct cpumask *mask;
-
- if (node == NUMA_NO_NODE)
- return;
-
- mask = node_to_cpumask_map[node];
- if (!cpumask_available(mask)) {
- pr_err("node_to_cpumask_map[%i] NULL\n", node);
- dump_stack();
- return;
- }
-
- if (enable)
- cpumask_set_cpu(cpu, mask);
- else
- cpumask_clear_cpu(cpu, mask);
-
- pr_debug("%s cpu %d node %d: mask now %*pbl\n",
- enable ? "numa_add_cpu" : "numa_remove_cpu",
- cpu, node, cpumask_pr_args(mask));
-}
#endif /* CONFIG_NUMA_EMU */
diff --git a/mm/numa_emulation.c b/mm/numa_emulation.c
index 55f26b22bb0b..63f3ce5ef839 100644
--- a/mm/numa_emulation.c
+++ b/mm/numa_emulation.c
@@ -366,10 +366,10 @@ static int __init setup_emu2phys_nid(int *dfl_phys_nid)
* are mapped to physical nodes and match the actual distances.
*
* - emu_nid_to_phys[] reflects how emulated nodes are mapped to physical
- * nodes. This is used by numa_add_cpu() and numa_remove_cpu().
+ * nodes.
*
- * If emulation is not enabled or fails, emu_nid_to_phys[] is filled with
- * identity mapping and no other modification is made.
+ * If emulation is not enabled or fails, the NUMA configuration is left
+ * unchanged.
*/
void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
{
@@ -547,65 +547,4 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
no_emu:
numa_nodes_parsed = physnode_mask;
- /* No emulation. Build identity emu_nid_to_phys[] for numa_add_cpu() */
- for (i = 0; i < ARRAY_SIZE(emu_nid_to_phys); i++)
- emu_nid_to_phys[i] = i;
}
-
-#ifndef CONFIG_DEBUG_PER_CPU_MAPS
-void numa_add_cpu(unsigned int cpu)
-{
- int physnid, nid;
-
- nid = early_cpu_to_node(cpu);
- BUG_ON(nid == NUMA_NO_NODE || !node_online(nid));
-
- physnid = emu_nid_to_phys[nid];
-
- /*
- * Map the cpu to each emulated node that is allocated on the physical
- * node of the cpu's apic id.
- */
- for_each_online_node(nid)
- if (emu_nid_to_phys[nid] == physnid)
- cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
-}
-
-void numa_remove_cpu(unsigned int cpu)
-{
- int i;
-
- for_each_online_node(i)
- cpumask_clear_cpu(cpu, node_to_cpumask_map[i]);
-}
-#else /* !CONFIG_DEBUG_PER_CPU_MAPS */
-static void numa_set_cpumask(unsigned int cpu, bool enable)
-{
- int nid, physnid;
-
- nid = early_cpu_to_node(cpu);
- if (nid == NUMA_NO_NODE) {
- /* early_cpu_to_node() already emits a warning and trace */
- return;
- }
-
- physnid = emu_nid_to_phys[nid];
-
- for_each_online_node(nid) {
- if (emu_nid_to_phys[nid] != physnid)
- continue;
-
- debug_cpumask_set_cpu(cpu, nid, enable);
- }
-}
-
-void numa_add_cpu(unsigned int cpu)
-{
- numa_set_cpumask(cpu, true);
-}
-
-void numa_remove_cpu(unsigned int cpu)
-{
- numa_set_cpumask(cpu, false);
-}
-#endif /* !CONFIG_DEBUG_PER_CPU_MAPS */
base-commit: 95a4df9944cd5d57a92662269114ba99cb972394
--
2.56.0
next prev parent reply other threads:[~2026-12-01 9:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:18 [PATCH v2 mm and sched_ext/for-7.5 0/2] Skip nodes without CPUs in the sched_ext idle walk Cheng-Yang Chou
2026-12-01 9:18 ` Cheng-Yang Chou [this message]
2026-12-01 9:18 ` [PATCH v2 mm and sched_ext/for-7.5 2/2] sched_ext/idle: Skip nodes without CPUs Cheng-Yang Chou
2026-12-01 15:45 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201091829.16311-2-yphbchou0911@gmail.com \
--to=yphbchou0911@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arighi@nvidia.com \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=changwoo@igalia.com \
--cc=chengyang.chou@mediatek.com \
--cc=chia7712@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-arch@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rppt@kernel.org \
--cc=sched-ext@lists.linux.dev \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.