mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: "vernhao(郝信)" <vernhao@tencent.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>,
	"Gautham R . Shenoy" <gautham.shenoy@amd.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>,
	Juri Lelli	 <juri.lelli@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	 Valentin Schneider	 <vschneid@redhat.com>,
	Madadi Vineeth Reddy <vineethr@linux.ibm.com>,
	Hillf Danton <hdanton@sina.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Jianyong Wu	 <jianyong.wu@outlook.com>,
	Yangyu Chen <cyy@cyyself.name>,
	Tingyin Duan	 <tingyin.duan@gmail.com>,
	Len Brown <len.brown@intel.com>, Aubrey Li	 <aubrey.li@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>, Chen Yu	 <yu.chen.surf@gmail.com>,
	Chen Yu <yu.c.chen@intel.com>, Libo Chen	 <libo.chen@oracle.com>,
	Adam Li <adamli@os.amperecomputing.com>,
	Tim Chen	 <tim.c.chen@intel.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: 回复:[Internet][PATCH 06/19] sched/fair: Assign preferred LLC ID to processes
Date: Mon, 13 Oct 2025 11:09:41 -0700	[thread overview]
Message-ID: <eed85200babfcfd43669270912176d38b8cc8f69.camel@linux.intel.com> (raw)
In-Reply-To: <tencent_660411F01236A0D747E5BF2B@qq.com>

On Mon, 2025-10-13 at 17:10 +0800, vernhao(郝信) wrote:
> 
> Tim Chen<tim.c.chen@linux.intel.com> 在 2025年10月12日 周日 2:18 写道:
> With cache-aware scheduling enabled, each task is assigned a
> preferred LLC ID. This allows quick identification of the LLC domain
> where the task prefers to run, similar to numa_preferred_nid in
> NUMA balancing.
> 
> Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
> ---
>  include/linux/sched.h | 1 +
>  init/init_task.c      | 3 +++
>  kernel/sched/fair.c   | 7 +++++++
>  3 files changed, 11 insertions(+)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index d7ddb7ce6c4b..8a5e4038cd5c 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1402,6 +1402,7 @@ struct task_struct {
>  
>  #ifdef CONFIG_SCHED_CACHE
>   struct callback_head cache_work;
> + int preferred_llc;
>  #endif
>  
>  #ifdef CONFIG_RSEQ
> diff --git a/init/init_task.c b/init/init_task.c
> index e557f622bd90..5fffbe766f57 100644
> --- a/init/init_task.c
> +++ b/init/init_task.c
> @@ -188,6 +188,9 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = {
>   .numa_group = NULL,
>   .numa_faults = NULL,
>  #endif
> +#ifdef CONFIG_SCHED_CACHE
> + .preferred_llc  = -1,
> +#endif
>  #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
>   .kasan_depth = 1,
>  #endif
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 61c129bde8b6..d6167a029c47 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1312,6 +1312,7 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
>   struct mm_struct *mm = p->mm;
>   struct mm_sched *pcpu_sched;
>   unsigned long epoch;
> + int mm_sched_llc = -1;
>  
>   if (!sched_cache_enabled())
>   return;
> @@ -1342,6 +1343,12 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
>   if (mm->mm_sched_cpu != -1)
>   mm->mm_sched_cpu = -1;
>   }
> +
> + if (mm->mm_sched_cpu != -1)
> + mm_sched_llc = per_cpu(sd_llc_id, mm->mm_sched_cpu);
> 
> In high-concurrency multi-threaded scenarios, not all threads handle same events, so their hot data in the LLC is not completely shared. 
> Therefore, if every thread's preferred LLC is migrated to the LLC pointed to by mm->mm_sched_cpu, this would lead to the incorrect 
> assumption that all threads prefer the same LLC, thereby intensifying competition between LLCs.

Yes, that's the reason why we stop aggregating to the preferred LLC once the the utilization of the
LLC becomes too high relative to the other LLCs.

If you know your threads characteristics before hand on which of them
share data together, you probably can use cgroup/cpuset
from user space to separate out the threads.  

There's not enough info from occupancy data for OS to group
the threads by data sharing. Perhaps an alternative if NUMA balancing
is on is to group tasks by their task numa group instead of by mm.  

That would incur the page scanning overhead etc and make
cache aware scheduling be dependent on NUMA balancing.
 

> 
> So I'm wondering, why not move ‘mm->mm_sched_cpu’ to ‘task_struct’, so that each thread can individually track its preferred LLC? What are the losses in doing so?

You would need a way to group related tasks together and put them
on the same LLC.  Either group them by mm or some other means.

Tim

> 
> +
> + if (p->preferred_llc != mm_sched_llc)
> + p->preferred_llc = mm_sched_llc;
>  }
>  
>  static void task_tick_cache(struct rq *rq, struct task_struct *p)

           reply	other threads:[~2025-10-13 18:09 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <tencent_660411F01236A0D747E5BF2B@qq.com>]

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=eed85200babfcfd43669270912176d38b8cc8f69.camel@linux.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=adamli@os.amperecomputing.com \
    --cc=aubrey.li@intel.com \
    --cc=bsegall@google.com \
    --cc=cyy@cyyself.name \
    --cc=dietmar.eggemann@arm.com \
    --cc=gautham.shenoy@amd.com \
    --cc=hdanton@sina.com \
    --cc=jianyong.wu@outlook.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=len.brown@intel.com \
    --cc=libo.chen@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sshegde@linux.ibm.com \
    --cc=tim.c.chen@intel.com \
    --cc=tingyin.duan@gmail.com \
    --cc=vernhao@tencent.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vineethr@linux.ibm.com \
    --cc=vschneid@redhat.com \
    --cc=yu.c.chen@intel.com \
    --cc=yu.chen.surf@gmail.com \
    --cc=zhao1.liu@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®