mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: Qais Yousef <qyousef@layalina.io>,
	Zhan Xusheng <zhanxusheng1024@gmail.com>,
		peterz@infradead.org, mingo@kernel.org
Cc: yu.c.chen@intel.com, vincent.guittot@linaro.org,
	juri.lelli@redhat.com,  dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
		vschneid@redhat.com, linux-kernel@vger.kernel.org,
	zhanxusheng@xiaomi.com
Subject: Re: [PATCH] sched/cache: Don't use fits_capacity() to compare thread and CPU counts
Date: Tue, 03 Nov 2026 13:07:47 -0800	[thread overview]
Message-ID: <85945b5c0c6c418780c9f5833a5fe6418da4e21a.camel@linux.intel.com> (raw)
In-Reply-To: <bc97743f-5ceb-4ecd-8f3d-1b217eb9020f@layalina.io>

On Tue, 2026-11-03 at 01:31 +0000, Qais Yousef wrote:
> On 11/2/26 02:15, Zhan Xusheng wrote:
> > From: Zhan Xusheng <zhanxusheng@xiaomi.com>
> > 
> > invalid_llc_nr() uses fits_capacity() to compare a thread count with a
> > CPU count, only for its 20% margin.  Qais's series changes
> > fits_capacity() to take a CPU number as its second argument, and this
> > call would then pass the CPU count as a CPU number without a warning.
> > 
> > Give the check its own helper.  x * 5 < y * 4 is the same comparison as
> > x * 1280 < y * 1024, so there is no functional change.
> > 
> > Link: https://lore.kernel.org/all/20260504020003.71306-5-qyousef@layalina.io/
> > Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
> 
> Thanks for the patch. LGTM, although I hope we can do better.
> 
> Reviewed-by: Qais Yousef <qyousef@layalina.io>
> 
> > ---
> > This keeps the 20% margin.  Qais would rather not add hardcoded
> > margins, and llc_aggr_tolerance already scales the LLC size here, so
> > the margin could go, but that changes when a process stops being
> > aggregated.  Tim, Chen Yu, would you drop it?
> 
> Tim, Chen,
> 
> From capacity comparisons, we had issues that we move too slowly or too fast in
> some cases, that's why I was trying to remove this magic number.
> 
> I'd be surprised if this gives a global win.
> 
> Is this the best we can do? What is the problem you're working around here?

Qais,

The 20% margin is a deliberately conservative margin for the default
llc_aggr_tolerance. With no knowledge of whether a process's threads
share data, we only aggregate a process when its threads fit well within
the cores of one LLC, so workloads that don't benefit from aggregation
are not hurt by packing them into a single LLC.

Where aggregation is known to help, the user should raise
llc_aggr_tolerance (or, later, use hints like schedqos or the prctl
interface we proposed) rather than rely on a smaller margin. The
tolerance scales the limit (0.8x cores at the default, 1.6x at 2, and so
on), so the margin only sets how conservative the starting point is.

Thanks.

Tim 

> 
> I see we have other magic like llc_aggr_tolerance and llc_imb_pct etc.
> 
> > 
> >  kernel/sched/fair.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index cfc982205b98..dfd6528d18ee 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -1469,6 +1469,12 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
> >  	return false;
> >  }
> >  
> > +/* Are the running threads (in SMT siblings) below ~80% of the LLC's CPUs? */
> > +static inline bool fits_llc_nr(u64 nr_threads, unsigned int nr_cpus)
> > +{
> > +	return nr_threads * 5 < (u64)nr_cpus * 4;
> > +}
> > +
> >  static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p,
> >  			   int cpu)
> >  {
> > @@ -1485,8 +1491,8 @@ static bool invalid_llc_nr(struct sched_cache_group *grp, struct task_struct *p,
> >  	if (scale == INT_MAX)
> >  		return false;
> >  
> > -	return !fits_capacity((READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads),
> > -			(scale * per_cpu(sd_llc_size, cpu)));
> > +	return !fits_llc_nr(READ_ONCE(grp->nr_running_avg) * cpu_smt_num_threads,
> > +			    scale * per_cpu(sd_llc_size, cpu));
> >  }
> >  
> >  /*
> > 
> > base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
> 

  parent reply	other threads:[~2026-11-03 21:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  2:15 Zhan Xusheng
2026-11-03  1:31 ` Qais Yousef
2026-11-03  2:24   ` Chen Yu
2026-11-03 21:07   ` Tim Chen [this message]
2026-11-03  2:27 ` Chen Yu
2026-11-03 18:30 ` Tim Chen
2026-11-03 18:34 ` Tim Chen

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=85945b5c0c6c418780c9f5833a5fe6418da4e21a.camel@linux.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=yu.c.chen@intel.com \
    --cc=zhanxusheng1024@gmail.com \
    --cc=zhanxusheng@xiaomi.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®