From: Jemmy Wong <jemmywong512@gmail.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Tim Chen <tim.c.chen@linux.intel.com>
Cc: Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
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>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org, Jemmy Wong <jemmywong512@gmail.com>
Subject: [PATCH] sched/cache: Avoid publishing partial LLC utilization
Date: Sat, 10 Oct 2026 19:34:25 +0800 [thread overview]
Message-ID: <20261010113425.34829-1-jemmywong512@gmail.com> (raw)
update_sg_lb_stats() sums utilization over the CPUs in both
sched_group_span(group) and env->cpus, but takes capacity from
group->sgc->capacity for the whole group. record_sg_llc_stats()
publishes both.
Rejecting an all-affinity-pinned source runqueue removes that CPU from
env->cpus and retries group selection. The retry can publish the
partial utilization with the full capacity. On a two-CPU LLC this
replaces 1800/2048 with 900/2048.
can_migrate_llc() then treats a busy preferred LLC as having spare
capacity. More tasks can aggregate into it, migrations out can be
blocked, and two busy LLCs may not fall back to generic balancing.
This increases CPU contention and task latency. Found by inspection.
Publish either shared LLC statistic only when env->cpus covers the
whole group. A partial scan keeps the previous complete snapshot;
other groups still refresh. Load balancing still uses the
affinity-filtered statistics.
The same window exists during CPU hotplug. env->cpus drops a CPU at
set_cpu_active(false), but the group span and sgc->capacity still
include it until cpuset_cpu_inactive() rebuilds the domains. Keeping
the previous snapshot avoids the mismatched publish. After the rebuild,
the next periodic balance records both statistics again.
Signed-off-by: Jemmy Wong <jemmywong512@gmail.com>
---
kernel/sched/fair.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index aa4a7d22d1df..a98a62f729d4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -12121,6 +12121,13 @@ static void record_sg_llc_stats(struct lb_env *env,
if (env->sd->child != rcu_dereference_all(per_cpu(sd_llc, env->dst_cpu)))
return;
+ /*
+ * Affinity retries can remove CPUs from env->cpus. Do not publish
+ * partial utilization against the capacity of the whole group.
+ */
+ if (!cpumask_subset(sched_group_span(group), env->cpus))
+ return;
+
/*
* At this point we know this group spans a LLC domain.
* Record the statistic of this group in its corresponding
--
2.25.1
next reply other threads:[~2026-10-10 11:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 11:34 Jemmy Wong [this message]
2026-10-12 3:34 ` K Prateek Nayak
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=20261010113425.34829-1-jemmywong512@gmail.com \
--to=jemmywong512@gmail.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tim.c.chen@linux.intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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®