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 76C5F606A33E for ; Tue, 1 Dec 2026 13:41:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 559016B05B1; Tue, 1 Dec 2026 08:41:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 50A006B05B2; Tue, 1 Dec 2026 08:41:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41FE06B05B4; Tue, 1 Dec 2026 08:41:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CF16F6B05B1 for ; Tue, 1 Dec 2026 08:41:33 -0500 (EST) Received: from smtpin20.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 67324120E98 for ; Tue, 1 Dec 2026 13:41:33 +0000 (UTC) X-FDA: 85495526466.20.F976553 Received: from spam01.hygon.cn (unknown [101.204.27.37]) by imf15.hostedemail.com (Postfix) with ESMTP id 61D7AA0012 for ; Tue, 1 Dec 2026 13:41:28 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=hygon.cn; spf=pass (imf15.hostedemail.com: domain of wujianyong@hygon.cn designates 101.204.27.37 as permitted sender) smtp.mailfrom=wujianyong@hygon.cn ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796132491; b=WFChaofnmhm0HiF71emp+/adWQgGhlas46DRCaZYVXMELhktUZ8TnWdQlW9ECEUFw7SKEG REoQk54nWdUhgj+qn1YJ2Sec0AiKBLh7gLdsfzGfxvbxSHKQBUC+8aCAOmoKuO+wiaY5tH d2mEZacFBXPQxY4qJlQLWzMWT7FrHWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796132491; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h9I0SGLtgjC5CvMeVF+jV9xmlUzZXzEfFOp5keVUbQk=; b=zAvGQYGpxa+SGl6d5GXE3AALCbap+t36Bf81b+voMj9mS9CNY7ETtxQx66cnxy6w9HRJLz f8nOdhTabV3d2v9m+orVrlIkdgdqSMBfjWBgsMaavA59IKR3kM0UwU1MsgKrXx8vv7Za87 Vdn8c9n9DTk64LGSj/oIGZCaK6o7wqY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=hygon.cn; spf=pass (imf15.hostedemail.com: domain of wujianyong@hygon.cn designates 101.204.27.37 as permitted sender) smtp.mailfrom=wujianyong@hygon.cn Received: from maildlp1.hygon.cn (unknown [127.0.0.1]) by spam01.hygon.cn (Postfix) with ESMTP id 4jf29F1cKgzVhfS; Tue, 1 Dec 2026 21:41:21 +0800 (CST) Received: from maildlp1.hygon.cn (unknown [172.23.18.60]) by spam01.hygon.cn (Postfix) with ESMTP id 4jf29B6MqgzVhfS; Tue, 1 Dec 2026 21:41:18 +0800 (CST) Received: from cncheex06.Hygon.cn (unknown [172.23.18.116]) by maildlp1.hygon.cn (Postfix) with ESMTPS id 55CD11663; Tue, 1 Dec 2026 21:41:13 +0800 (CST) Received: from cncheex04.Hygon.cn (172.23.18.114) by cncheex06.Hygon.cn (172.23.18.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Tue, 1 Dec 2026 21:41:18 +0800 Received: from cncheex04.Hygon.cn ([fe80::1b6f:6c58:58a4:430d]) by cncheex04.Hygon.cn ([fe80::1b6f:6c58:58a4:430d%10]) with mapi id 15.02.1544.036; Tue, 1 Dec 2026 21:41:18 +0800 From: Jianyong Wu To: Chen Yu 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" , Yuan Zhong , Huangsj , Fengyu Wang , Zhiwei Ying Subject: RE: [RFC PATCH v3 01/17] sched/topology: Add llc_to_node() to translate LLC ID to NUMA node Thread-Topic: [RFC PATCH v3 01/17] sched/topology: Add llc_to_node() to translate LLC ID to NUMA node Thread-Index: AQHdZ0z3MZcbWGq90k6DQlvNOuR0ybdE1zSAgAODEFA= Date: Tue, 1 Dec 2026 13:41:18 +0000 Message-ID: <0a4881a717524940bdabcadb95c05924@hygon.cn> References: <20261029022036.4002331-1-wujianyong@hygon.cn> <20261029022036.4002331-2-wujianyong@hygon.cn> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Archived-By: MIME-Version: 1.0 X-Stat-Signature: 7dshuuchh1rip6mix5jbcmxcapeiz1by X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 61D7AA0012 X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, 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: 1796132488-632936 X-HE-Meta: U2FsdGVkX18jVJtVl2dbxfBNR++gcQxb8ZrCbsQJEcgTR/FR+WeW5GKxhh8ZBuuF80R7BbQNWSNBgJQTGK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ld6Gxhr+Nov70b+wXfS+8m5Pod0cG+HtCePIkoLK0qBSFmV6YatLqAxV2dJIvuW9/csG00J4+ZQUKjE8ii60ySnFoDIDg/kLFSHhcilsH42SngdlSbXfoBRAJZKtMTOfKCzQiqrq9M4ro1GVjEwP8taHnsRwr75jRQ9V4B9CxkLswK52RFPnvYNAyD3HL0v8mougg3OzuBsw/06zUFQgH5XHH9+ZBvYs2g6kF5TTNFAArTgwltt4/6ZYQYtXKJD/SM15rxirphSnvkSbkARjwSD1qK3SNioqSXrD2IWGCCoHojcNdin2ZqiQULue8DhQMFpEyW3RbsUfm8pYj7RZMDOK6R2grd/DiE2tRFm/0QBO0kQFhmNovzYKVzOLZYwHJuomTbU99U2aWCvGiGV0g869G0V5q8eQO73b1JCjPtzu3pcSFGg5GDXRvgJei07zV+5sMGdvpOojMAnyB3xowV9fu9uB96nJD3XY1ZOWoxy21Qa1k7bqz99GbrKh48sPDeFf9gMCeWd+1wf+iuLx8Kddikyg8+8pwF3qVF7KBlhpjvSUKRNltNCyoNITIgS+/vzT7ZplfJBbgTxIJ6frsjTaP2n3V87ajL5lo2rUcgweS8oNFZpxNjBCtytcMJnXjxuaKlvbTxC0Gl1StLu6/kHpizTFaj9HhJcQovl5M5fi5oLycHQg4PkIpiGmGFTJxujS4G6dmwhmWq3tThoNzPaqkbe2lCJaptgrBA3nHm4nO 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 Hi Chenyu, Thanks for the review. > -----Original Message----- > From: Chen Yu > Sent: Sunday, November 29, 2026 11:26 PM > To: Jianyong Wu > Cc: Ingo Molnar ; Peter Zijlstra > ; Juri Lelli ; Vincent Guitt= ot > ; 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; Yuan Zhong ; Huangsj > ; Fengyu Wang ; Zhiwei Ying > > Subject: Re: [RFC PATCH v3 01/17] sched/topology: Add llc_to_node() to > translate LLC ID to NUMA node >=20 > 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 =3D 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 =3D 1; > > > > +int llc_to_node(int llc) > > +{ > > + struct llc_node_map *map; > > + int node =3D -1; > > + > > + rcu_read_lock(); > > + map =3D rcu_dereference(llc_to_node_map); > > + if (map && llc >=3D 0 && llc < map->nr_llc) > > + node =3D map->node[llc]; > > + rcu_read_unlock(); > > + > > + return node; > > +} > > + >=20 > How about allocate llc_node =3D 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 domai= n, > and we don't have > to update all the values in llc_to_node_map[]? > Agreed. Preallocating the map is better. Since later patches extend this rebuild helper to maintain other information, I'll separate the LLC-to-node mapping from that logic. =20 > > +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 <=3D 0) > > + goto fail; > > + > > + new_map =3D kzalloc(struct_size(new_map, node, size), GFP_KERNEL); > > + if (!new_map) > > + goto fail; > > + > > + new_map->nr_llc =3D size; > > + for (llc =3D 0; llc < size; llc++) > > + new_map->node[llc] =3D 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 =3D per_cpu(sd_llc_id, cpu); > > + if (llc < 0 || llc >=3D size || new_map->node[llc] >=3D 0) >=20 > new_map->node[llc] !=3D NUMA_NO_NODE ? >=20 Agreed, though this check will no longer be needed with the preallocation approach. > > + continue; > > + node =3D cpu_to_node(cpu); > > + if (node >=3D 0 && node < nr_node_ids && node_possible(node)) >=20 > I thought node !=3D NUMA_NO_NODE should be enough, why check node < > nr_node_ids and > node_possible(node)? > Agreed. The additional checks are unnecessary here. I'll simplify this to node !=3D NUMA_NO_NODE. =20 > > + new_map->node[llc] =3D node; > > + } > > + > > +publish: > > + old_map =3D 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 =3D NULL; > > + goto publish; >=20 > If new_map allocation failed, can we still use the old llc_to_node_map? >=20 With the preallocation approach, this runtime allocation failure path will go away. > > +} > > + > > /* > > * 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 =3D per_cpu(sd_llc_id, cpu); > > if (lid =3D=3D -1 || lid >=3D nr_cpu_ids) > > - return; > > + return false; > > > > per_cpu(sd_llc_id, cpu) =3D -1; > > > > for_each_cpu(i, llc_mask(cpu)) { > > /* An online CPU owns the llc_id. */ > > if (per_cpu(sd_llc_id, i) =3D=3D 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 =3D 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 >=20 > 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? > I put it under CONFIG_SCHED_CACHE because its current users are part of cache-aware scheduling. But I agree that the mapping belongs with the LLC ID infrastructure. I'll remove this dependency in the next version. Thanks Jianyong =20 > thanks, > Chenyu >=20 > > __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 > > > >