From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF447606A32A for ; Sun, 29 Nov 2026 15:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=JUy8W/Pt Received: by kanga.kvack.org (Postfix) id BC4A96B05B1; Sun, 29 Nov 2026 10:24:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B75366B05B6; Sun, 29 Nov 2026 10:24:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8B806B05B8; Sun, 29 Nov 2026 10:24:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 706866B05B1 for ; Sun, 29 Nov 2026 10:24:50 -0500 (EST) Received: from smtpin05.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0B8214083A for ; Sun, 29 Nov 2026 15:24:50 +0000 (UTC) X-FDA: 85488529140.05.DA436D3 Received: from mta0.migadu.com (out-51.mta0.migadu.com [91.218.175.51]) by imf23.hostedemail.com (Postfix) with ESMTP id E5935140003 for ; Sun, 29 Nov 2026 15:24:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="JUy8W/Pt"; spf=pass (imf23.hostedemail.com: domain of chen.yu@linux.dev designates 91.218.175.51 as permitted sender) smtp.mailfrom=chen.yu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1795965888; b=Nd/sHX1YdNMOFdN3rgAmQGSnxAC758kkW2zUxlhgXLhgdhw+Of5hf9sImqNLkUwvJ/Dzks w0Di9/1v7PHDc211paDOKUVXEUvWRL81Bg7RisWvxN6gYtPMZraKdoUYt+HuVRdhAqi7MT +l+2YIqkPFBj1lpcUtOFL/HlPjJzZS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1795965888; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eGu7JidkR7Aqpa9A93v7X7zvoRXzuYqxdN1/dDnuUwg=; b=IZwzDBCNMMO1ogqxu5pNKJnnzyRCSatFBYsxe/GY74if5/pLDWyY+sBpyc9LktaMYAKcuX KNBI7OR6QNCFyFpVMprVN/wXOzUnrzDCFIZS3kxijhFENu++yC8J7rGByJrQctfdvMZo5m sow4Su1muCkkdUs+Cag/FnmGrbGrg/w= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="JUy8W/Pt"; spf=pass (imf23.hostedemail.com: domain of chen.yu@linux.dev designates 91.218.175.51 as permitted sender) smtp.mailfrom=chen.yu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=cO54ISLqXigegMnIf5b8jWbNBbm6KLMJBeD1npmguLM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795965886; v=1; x=1796570686; b=JUy8W/PtA8SsPVgWdCT6hUDjajL0ufk5b31vtvop1rGKnWMDP6ko1e3LajZtuDJP+L+9NSCZ szyImkWEC2SlX5Xg7sYW6bEwmMEInSr6JcGfesLT7IVFYAeBqI9w5v1iDH9vNvhQbuPbmzxsZWB 2SYPUdGvEmpt1GGBl908Y10I= X-Envelope-To: linux-mm@kvack.org Received: by smtp.migadu.com with ESMTPS id 1ffea6eff2225565; Sun, 29 Nov 2026 15:24:46 +0000 X-Mizu-Trace-ID: 1ffea6eff2225565 X-Migadu-Flow: FLOW_OUT Date: Sun, 29 Nov 2026 23:26:09 +0800 From: Chen Yu To: Jianyong Wu Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Chen Yu , Tim Chen , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Shrikanth Hegde , Phil Auld , Andrew Morton , David Hildenbrand , maddy@linux.ibm.com, Michael Ellerman , ljs@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, jianyong.wu@outlook.com, zhongyuan@hygon.cn, huangsj@hygon.cn, wangfengyu@hygon.cn, yingzhiwei@hygon.cn Subject: Re: [RFC PATCH v3 01/17] sched/topology: Add llc_to_node() to translate LLC ID to NUMA node Message-ID: References: <20261029022036.4002331-1-wujianyong@hygon.cn> <20261029022036.4002331-2-wujianyong@hygon.cn> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261029022036.4002331-2-wujianyong@hygon.cn> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E5935140003 X-Rspam-User: X-Stat-Signature: 1n4hkco6667m7a6o8t49udeme4eo39hx X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1795965887-35785 X-HE-Meta: U2FsdGVkX1/SQvXJUjkLiv9l6XrkwT8RKSHCqPr/n4fur1I2pv70xZWBQr7OuYidP2kI3TFvvFq6skkCYi+7Wry+GvbHQwYKWizqh0bWRe8hULGD1lvTeYIi2op0kAPWWFxGFTXwXehA2JCv7Qj3TTwnMDYt74ymaPey+qnKiBZWzc+i4bMOfCPCGv4W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SFWNXVnEVXxVXjtjrxvQK1Xe9eOqdnsDfUzPntnTr7zOosTT9k+XJN77lKWvtJf4WJ2KScK5irVmUkcg1+SeLqpM/95lCPWAw/h/I/7Oa0We09d5oLc4qeKFQshyFClP3IZkI6rXWy9PeLlgKoC6P2pg7WuxcDU8knA8k2deFENIAIRo344VbKZbgpALJAgZChzme742U0VsxZl95dPl7QeikeVo2NesypcMxLTWrcN8BxgNK+FgRoK3FvBt7gi44162Zo1nsLfACXwyA6ZQ== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thu, Oct 29, 2026 at 10:20:19AM +0800, Jianyong Wu wrote: > > Building LLC affinity sequences requires knowing which NUMA node each > LLC belongs to. Add a per-LLC-ID NUMA-node map derived from possible > CPUs that currently hold an LLC ID, and expose it to the scheduler > through llc_to_node(). Unassigned IDs return NUMA_NO_NODE. > > Signed-off-by: Jianyong Wu > --- > kernel/sched/sched.h | 1 + > kernel/sched/topology.c | 93 +++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 91 insertions(+), 3 deletions(-) > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 56acf502ba26..4ee223416012 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -4107,6 +4107,7 @@ static inline bool sched_cache_enabled(void) > } > > extern void sched_cache_active_set(void); > +extern int llc_to_node(int llc); > > #endif > > diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c > index 622e2e01974c..18171d2338fe 100644 > --- a/kernel/sched/topology.c > +++ b/kernel/sched/topology.c > @@ -685,6 +685,24 @@ DEFINE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity); > DEFINE_STATIC_KEY_FALSE(sched_asym_cpucapacity); > DEFINE_STATIC_KEY_FALSE(sched_cluster_active); > > +#ifdef CONFIG_SCHED_CACHE > +/* > + * LLC id to NUMA node map. The number of entries lives inside the > + * RCU-protected allocation so that a reader bound-checks against the > + * length of the very map it dereferenced. max_lid is updated by > + * __sched_domains_alloc_llc_id() well before rebuild_llc_node_map() > + * installs the matching map, so it must not be used as the bound. > + */ > +struct llc_node_map { > + int nr_llc; > + int node[]; > +}; > + > +static struct llc_node_map __rcu *llc_to_node_map; > +static void rebuild_llc_node_map(int size); > + > +#endif > + > static void update_top_cache_domain(int cpu) > { > struct sched_domain_shared *sds = NULL; > @@ -856,6 +874,64 @@ DEFINE_STATIC_KEY_FALSE(sched_cache_active); > /* user wants cache aware scheduling [0 or 1] */ > int sysctl_sched_cache_user = 1; > > +int llc_to_node(int llc) > +{ > + struct llc_node_map *map; > + int node = -1; > + > + rcu_read_lock(); > + map = rcu_dereference(llc_to_node_map); > + if (map && llc >= 0 && llc < map->nr_llc) > + node = map->node[llc]; > + rcu_read_unlock(); > + > + return node; > +} > + How about allocate llc_node = kmalloc_array(n, sizeof(*llc_node), GFP_KERNEL); near sched_domains_llc_id_allocmask() in sched_init_domains()? In this way, we don't need to reallocate the map array. We just update the llc_to_node_map[] values (either NUMA_NO_NODE or the new llc_id) of the CPUs when the llc_id changes for that LLC domain, and we don't have to update all the values in llc_to_node_map[]? > +static void rebuild_llc_node_map(int size) > +{ > + struct llc_node_map *new_map, *old_map; > + int cpu, llc, node; > + > + lockdep_assert_held(&sched_domains_mutex); > + if (size <= 0) > + goto fail; > + > + new_map = kzalloc(struct_size(new_map, node, size), GFP_KERNEL); > + if (!new_map) > + goto fail; > + > + new_map->nr_llc = size; > + for (llc = 0; llc < size; llc++) > + new_map->node[llc] = NUMA_NO_NODE; > + > + /* > + * for_each_possible_cpu() revisits the same LLC non-consecutively > + * under SMT (each node's LLCs are walked once per thread), so > + * dedup by populated node entries, not by comparing against the > + * immediately preceding CPU's llc. > + */ > + for_each_possible_cpu(cpu) { > + llc = per_cpu(sd_llc_id, cpu); > + if (llc < 0 || llc >= size || new_map->node[llc] >= 0) new_map->node[llc] != NUMA_NO_NODE ? > + continue; > + node = cpu_to_node(cpu); > + if (node >= 0 && node < nr_node_ids && node_possible(node)) I thought node != NUMA_NO_NODE should be enough, why check node < nr_node_ids and node_possible(node)? > + new_map->node[llc] = node; > + } > + > +publish: > + old_map = rcu_dereference_protected(llc_to_node_map, > + lockdep_is_held(&sched_domains_mutex)); > + rcu_assign_pointer(llc_to_node_map, new_map); > + kfree_rcu_mightsleep(old_map); > + return; > + > +fail: > + new_map = NULL; > + goto publish; If new_map allocation failed, can we still use the old llc_to_node_map? > +} > + > /* > * Get the effective LLC size in bytes that @cpu's bottom sched_domain > * can use. A CPU within a cpuset partition can only use a proportion > @@ -3040,7 +3116,8 @@ static int __sched_domains_alloc_llc_id(void) > return lid; > } > > -static void __sched_domains_free_llc_id(int cpu) > +/* Return true only when the last CPU releases the LLC ID. */ > +static bool __sched_domains_free_llc_id(int cpu) > { > int i, lid, max; > > @@ -3048,14 +3125,14 @@ static void __sched_domains_free_llc_id(int cpu) > > lid = per_cpu(sd_llc_id, cpu); > if (lid == -1 || lid >= nr_cpu_ids) > - return; > + return false; > > per_cpu(sd_llc_id, cpu) = -1; > > for_each_cpu(i, llc_mask(cpu)) { > /* An online CPU owns the llc_id. */ > if (per_cpu(sd_llc_id, i) == lid) > - return; > + return false; > } > > __cpumask_clear_cpu(lid, sched_domains_llc_id_allocmask); > @@ -3064,12 +3141,18 @@ static void __sched_domains_free_llc_id(int cpu) > /* shrink max lid to save memory */ > if (max < max_lid) > max_lid = max; > + return true; > } > > void sched_domains_free_llc_id(int cpu) > { > sched_domains_mutex_lock(); > +#ifdef CONFIG_SCHED_CACHE > + if (__sched_domains_free_llc_id(cpu)) > + rebuild_llc_node_map(max_lid + 1); > +#else May I know why llc_to_node depends on CONFIG_SCHED_CACHE? Since llc_id is already independent of cache-aware scheduling, shouldn't llc_to_node be as well? thanks, Chenyu > __sched_domains_free_llc_id(cpu); > +#endif > sched_domains_mutex_unlock(); > } > > @@ -3139,6 +3222,10 @@ build_sched_domains(const struct cpumask *cpu_map, struct sched_domain_attr *att > } > } > > +#ifdef CONFIG_SCHED_CACHE > + /* The map depends on assigned LLC IDs, not on sd_llc allocations. */ > + rebuild_llc_node_map(max_lid + 1); > +#endif > if (WARN_ON(!topology_span_sane(cpu_map))) > goto error; > > -- > 2.34.1 > >