From: Yury Norov <yury.norov@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>,
Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
"Yury Norov [NVIDIA]" <yury.norov@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Thorsten Blum <thorsten.blum@linux.dev>,
Zqiang <qiang.zhang1211@gmail.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/4] smp: Improve locality in smp_call_function_any()
Date: Sun, 22 Jun 2025 20:00:06 -0400 [thread overview]
Message-ID: <20250623000010.10124-2-yury.norov@gmail.com> (raw)
In-Reply-To: <20250623000010.10124-1-yury.norov@gmail.com>
From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>
smp_call_function_any() tries to make a local call as it's the cheapest
option, or switches to a CPU in the same node. If it's not possible, the
algorithm gives up and searches for any CPU, in a numerical order.
Instead, we can search for the best CPU based on NUMA locality, including
2nd nearest hop (a set of equidistant nodes), and higher.
sched_numa_find_nth_cpu() does exactly that, and also helps to drop most
of housekeeping code.
Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
---
kernel/smp.c | 19 +++----------------
1 file changed, 3 insertions(+), 16 deletions(-)
diff --git a/kernel/smp.c b/kernel/smp.c
index 974f3a3962e8..7c8cfab0ce55 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -741,32 +741,19 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async);
*
* Selection preference:
* 1) current cpu if in @mask
- * 2) any cpu of current node if in @mask
- * 3) any other online cpu in @mask
+ * 2) nearest cpu in @mask, based on NUMA topology
*/
int smp_call_function_any(const struct cpumask *mask,
smp_call_func_t func, void *info, int wait)
{
unsigned int cpu;
- const struct cpumask *nodemask;
int ret;
/* Try for same CPU (cheapest) */
cpu = get_cpu();
- if (cpumask_test_cpu(cpu, mask))
- goto call;
-
- /* Try for same node. */
- nodemask = cpumask_of_node(cpu_to_node(cpu));
- for (cpu = cpumask_first_and(nodemask, mask); cpu < nr_cpu_ids;
- cpu = cpumask_next_and(cpu, nodemask, mask)) {
- if (cpu_online(cpu))
- goto call;
- }
+ if (!cpumask_test_cpu(cpu, mask))
+ cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu));
- /* Any online will do: smp_call_function_single handles nr_cpu_ids. */
- cpu = cpumask_any_and(mask, cpu_online_mask);
-call:
ret = smp_call_function_single(cpu, func, info, wait);
put_cpu();
return ret;
--
2.43.0
next prev parent reply other threads:[~2025-06-23 0:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 0:00 [PATCH v2 0/4] smp: Improve on cpumasks handling Yury Norov
2025-06-23 0:00 ` Yury Norov [this message]
2025-06-26 21:55 ` [tip: smp/core] smp: Improve locality in smp_call_function_any() tip-bot2 for Yury Norov [NVIDIA]
2025-06-23 0:00 ` [PATCH v2 2/4] smp: Use cpumask_any_but() in smp_call_function_many_cond() Yury Norov
2025-06-26 21:55 ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
2025-06-23 0:00 ` [PATCH v2 3/4] smp: Don't wait for remote work done if not needed " Yury Norov
2025-06-26 21:55 ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
2025-06-23 0:00 ` [PATCH v2 4/4] smp: Defer check for local execution " Yury Norov
2025-06-26 21:55 ` [tip: smp/core] " tip-bot2 for Yury Norov [NVIDIA]
2025-07-02 17:23 ` tip-bot2 for Yury Norov [NVIDIA]
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=20250623000010.10124-2-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang.zhang1211@gmail.com \
--cc=tglx@linutronix.de \
--cc=thorsten.blum@linux.dev \
/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;
as well as URLs for NNTP newsgroup(s).