From: Eric Dumazet <edumazet@google.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
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>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Eric Dumazet <eric.dumazet@gmail.com>,
Eric Dumazet <edumazet@google.com>,
Yafang Shao <laoar.shao@gmail.com>,
Sean Christopherson <seanjc@google.com>,
Josh Don <joshdon@google.com>
Subject: [PATCH] sched/fair: reduce false sharing on sched_balance_running
Date: Wed, 23 Apr 2025 17:46:34 +0000 [thread overview]
Message-ID: <20250423174634.3009657-1-edumazet@google.com> (raw)
rebalance_domains() can attempt to change sched_balance_running
more than 350,000 times per second on our servers.
If sched_clock_irqtime and sched_balance_running share the
same cache line, we see a very high cost on hosts with 480 threads
dealing with many interrupts.
This patch only acquires sched_balance_running when sd->last_balance
is old enough.
It also moves sched_balance_running into a dedicated cache line on SMP.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Yafang Shao <laoar.shao@gmail.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Josh Don <joshdon@google.com>
---
kernel/sched/fair.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index e43993a4e5807eaffcacaf761c289e8adb354cfd..460008d0dc459b3ca60209565e89c419ea32a4e2 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -12144,7 +12144,7 @@ static int active_load_balance_cpu_stop(void *data)
* execution, as non-SD_SERIALIZE domains will still be
* load-balanced in parallel.
*/
-static atomic_t sched_balance_running = ATOMIC_INIT(0);
+static __cacheline_aligned_in_smp atomic_t sched_balance_running = ATOMIC_INIT(0);
/*
* Scale the max sched_balance_rq interval with the number of CPUs in the system.
@@ -12220,25 +12220,25 @@ static void sched_balance_domains(struct rq *rq, enum cpu_idle_type idle)
interval = get_sd_balance_interval(sd, busy);
+ if (!time_after_eq(jiffies, sd->last_balance + interval))
+ goto out;
+
need_serialize = sd->flags & SD_SERIALIZE;
if (need_serialize) {
if (atomic_cmpxchg_acquire(&sched_balance_running, 0, 1))
goto out;
}
-
- if (time_after_eq(jiffies, sd->last_balance + interval)) {
- if (sched_balance_rq(cpu, rq, sd, idle, &continue_balancing)) {
- /*
- * The LBF_DST_PINNED logic could have changed
- * env->dst_cpu, so we can't know our idle
- * state even if we migrated tasks. Update it.
- */
- idle = idle_cpu(cpu);
- busy = !idle && !sched_idle_cpu(cpu);
- }
- sd->last_balance = jiffies;
- interval = get_sd_balance_interval(sd, busy);
+ if (sched_balance_rq(cpu, rq, sd, idle, &continue_balancing)) {
+ /*
+ * The LBF_DST_PINNED logic could have changed
+ * env->dst_cpu, so we can't know our idle
+ * state even if we migrated tasks. Update it.
+ */
+ idle = idle_cpu(cpu);
+ busy = !idle && !sched_idle_cpu(cpu);
}
+ sd->last_balance = jiffies;
+ interval = get_sd_balance_interval(sd, busy);
if (need_serialize)
atomic_set_release(&sched_balance_running, 0);
out:
--
2.49.0.805.g082f7c87e0-goog
next reply other threads:[~2025-04-23 17:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 17:46 Eric Dumazet [this message]
2025-04-24 14:45 ` Yafang Shao
2025-04-24 15:49 ` Eric Dumazet
2025-04-25 2:29 ` Yafang Shao
2025-04-25 16:22 ` Eric Dumazet
2025-04-26 10:43 ` Yafang Shao
2025-04-24 20:06 ` Josh Don
2025-04-25 16:05 ` Shrikanth Hegde
2025-04-25 16:14 ` Eric Dumazet
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=20250423174634.3009657-1-edumazet@google.com \
--to=edumazet@google.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=eric.dumazet@gmail.com \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=seanjc@google.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®