From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796116762; b=Z8q2X6FQWnDxDwVhCdmen5YO4KH19+0aGpfwA/4zFtyQqvOWo9JPlkh89uC+VeKvrIac gyPeTyji6RethyueKKoxWrq71gkOstgrcoPbKmr7ECR6DDMXu5VwC9iUHDANIMMvT4Nc9 cL0L4PPpnIHeSduyUc1rw0N1zTZu934u28u3JhKqb2BO0ffudw2DlqP3/6HEzmzz/rPBY Ezhd8z0pA8XeW0s9ZD8BLBwEn01qcbvyrmvnaeH9RHrfhs21q8ki/rzKT7OMkEM1ptrQ9 o0+X4V45BZFwK8Uda7QGx8bJUuEvB0SFVHJrLSHM+QK7al6zroRh/CKKWZ30wfQgV7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796116762; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=nJwsbYRhzmGu+KsDFyWg4rwJL+Hy9jFtOTWreqPZays=; b=bwWnKlW/gsNYLEByKLX1pZ8n9noR2jGSpR9ODHQ/3mwJdtp4IeOrehufn1uXXqAm3oh+ w7I0UwOLxZtAgQy93+Vwe3NVknyxY3xUcelqUF53VCPMq7BDKYGd2t4znxLdc7e/H9JsM 4FF4TCO2QyQoN1Do5lhOeN1ajRDEdE/nDF/TYKQVo6auJZYkhd1Kis4f/P80BAV+WzoPL 6rYCAXstq8I9m1LDGmLhBhiXHMIdNMEaJRt3cfRYyBDVQOBQR0uATv+TulQtBV1YLNoV6 vCjOfH39+NgX3Ylnj5JhP3+IDptBcSpM3JoJKVjyCWO0zAN9FYvRyA2I6eRNFRrmADA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kr7oiy9V; arc=none smtp.remote-ip=209.85.215.181 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA4D2606A331 for ; Tue, 1 Dec 2026 09:19:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA4D2606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kr7oiy9V Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-cd6acc50b8dso5798434a12.3 for ; Tue, 01 Dec 2026 01:19:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796116761; x=1796721561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nJwsbYRhzmGu+KsDFyWg4rwJL+Hy9jFtOTWreqPZays=; b=kr7oiy9VvukLfnmzTfzwLEvGA6t8XTHnM3SaKw9PD6n07WKuwY1HeJDnj6CajoUQK0 g5/tafxi+gAeFNWa1evXS8Q6vopwdaO0JP/O4eYfrczQUcXs0ly42u2a1T+voEMw83KV CCDuDdXIdmz+4CMTxwt09m2PQCAOwOPdl4ltHZh9h1hKJrDQd4sa04vpX7ssz5GsuBrb 4+3QOVI3qlCxDDYjAAzMUGxa9jCNxpK1YIvwNudTRCfkXgieMmuHTi3QXadT8jGfXhL/ CqYc1WVN4Z08Zbammc7xct4yl9gfY60A4agOKuS850dj3hIjopHuLfOscziU6AoBAX7c 0kFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796116761; x=1796721561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=nJwsbYRhzmGu+KsDFyWg4rwJL+Hy9jFtOTWreqPZays=; b=gzWsiUXDk43J9G/EtNrAQI3Cun6AS09h3RJ7BWXZW+ZHm8r7FtWySUIvMsGZFm+Wh7 jKdb3cFRtlHge1E64AWM2kdkbSt8yKMQIlizu0K5qucIZyenXR1zCv3sybipQcjeZWbT 6QpfNDc+CfV0eEjhcM4LjJF7gCOmvTCK3t5cz1AfwazMce6mpSuHbbrO3RTFCYDtGF3P +49nlljGcsTqxwzKQclfJCXaTYo5JodxQM0BF23NMDwFTHRJzw69e/W5Ct8O3Xsb3GKM S38Yib7w/R7RsvFv3GMGaoMz9T2pFhOqm9rhqTF9z4OQvy+NtDoWcdEn+66enGQHLZoB LbUg== X-Forwarded-Encrypted: i=1; AL+hErEs8LEM5rM9J3C6Ckm2TbyBF41hIuLsOVHNs0zUxXn0YDsgVz8J82SOo9KhEvsaSV9El87Qrps6Q0Dv@vger.kernel.org X-Gm-Message-State: APuU4Z9i0+tuW+mHU3TP3Q3J9BC+iGMypyk3HJj9U7cMw26p7nxN5wtg pFrxBywtjsGWYoO2pLlkp8TpO8uU1HdaoXomIBSW+hk9ZaMIBIYhw/Lw X-Gm-Gg: AZFdTZe3Tp7eGFgw1pLEayhjRiw80XaHmq6DDJvYeJTQz6vph1vpU7Mh6mM9pYgilTZ bsMiqqLBtdKJafixizDfV6r0qL8u/WOWy/0b6yJaMZccFBKLqvEDqC1cFSsND4d5le7BtlVXou8 1iCYNzMPLS2yAVxYpg948Eeaspl2YWSshtwn97xM+VLW6vobFL08DeAI7dmgUrUM9X71hHUndqT kDN2uBTyfu2sa3tkdvHsMPZpiSJ+5zqFkfbzCMlIsOgiNjZfN8K0lgp/ph1I1kq+ml1KqzzCYbP EGfiB+abInXj8ln6k6zCPpW/vkWEhKtnGTnXvvEXf1cTSCs52z+4beoe+880AsCXh3u1E08LYbx sNw2wYb/ZzJPUqg+IRFUdcg2QoQiWMXlrnV7EWBo37xssI5vCI7nrysFXVzoxmqaXoBvZge5ctv KCnLtD9ZdbKWtedA48T56MQF2Z+TAPXH5vZB43GOuWJX4DMhpNxiLeTyBv82OXebT816yZ8/2vo Z+u5S7g7NobCTKTHGHwllPYra+hBemjCgTi0uXNYVOHiHK5OJhQjCk75Vjzg+Ft8MlmTrD8crs4 lteY9TP50lDdVprYu4ptFC9ElVJLp5sE6vJSaAr70GaLPfbIibqxVuMJLMxL1xrKSdneTz1yZQN HM9mc30ZaddbLQBKLJ/1a X-Received: by 2002:a17:90a:d885:b0:3b4:6094:2f9e with SMTP id 98e67ed59e1d1-3b4609433d7mr30492406a91.46.1796116761030; Tue, 01 Dec 2026 01:19:21 -0800 (PST) Received: from eric-hp.. (36-225-94-109.dynamic-ip.hinet.net. [36.225.94.109]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b405d63728sm63580544a91.8.2026.12.01.01.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 01:19:20 -0800 (PST) From: Cheng-Yang Chou To: sched-ext@lists.linux.dev, Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , linux-mm@kvack.org, Andrew Morton , Mike Rapoport Cc: Ching-Chun Huang , Chia-Ping Tsai , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, Arnd Bergmann , linux-arch@vger.kernel.org, chengyang.chou@mediatek.com, Cheng-Yang Chou 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 Message-ID: <20261201091829.16311-2-yphbchou0911@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20261201091829.16311-1-yphbchou0911@gmail.com> References: <20261201091829.16311-1-yphbchou0911@gmail.com> X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Cheng-Yang Chou --- 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