mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib/group_cpus: sequentially bind CPUs within node to groups.
@ 2026-09-07  8:42 brookxu.cn
  0 siblings, 0 replies; only message in thread
From: brookxu.cn @ 2026-09-07  8:42 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel

From: Chunguang Xu <chunguang.xu@shopee.com>

grp_spread_init_one() tends to bind adjacent CPUs to a queue, which may
leads to performance regresstion in some case, such as SPDK, business
often need to  bind SPDK to static CPUs to poll data, such as 3,4,5,6,
this will result in some SPDK instance may only have one queue active.
So I think we should tends to spread the CPUs within node to all queue
sequentially as what we do before.

Signed-off-by: Chunguang Xu <chunguang.xu@shopee.com>
---
 lib/group_cpus.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/lib/group_cpus.c b/lib/group_cpus.c
index 18d43a406114..b40e885f6fbf 100644
--- a/lib/group_cpus.c
+++ b/lib/group_cpus.c
@@ -11,19 +11,28 @@
 
 #ifdef CONFIG_SMP
 
-static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk,
-				unsigned int cpus_per_grp)
+struct node_groups {
+	unsigned id;
+
+	union {
+		unsigned ngroups;
+		unsigned ncpus;
+	};
+};
+
+static void grp_spread_init_one(struct node_groups *nv, struct cpumask *irqmsk,
+				struct cpumask *nmsk, unsigned int cpus_per_grp)
 {
 	const struct cpumask *siblmsk;
 	int cpu, sibl;
 
+	cpu = cpumask_first(nmsk);
+
+	/* Should not happen, but I'm too lazy to think about it */
+	if (cpu >= nr_cpu_ids)
+		return;
+
 	for ( ; cpus_per_grp > 0; ) {
-		cpu = cpumask_first(nmsk);
-
-		/* Should not happen, but I'm too lazy to think about it */
-		if (cpu >= nr_cpu_ids)
-			return;
-
 		cpumask_clear_cpu(cpu, nmsk);
 		cpumask_set_cpu(cpu, irqmsk);
 		cpus_per_grp--;
@@ -39,6 +48,10 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk,
 			cpumask_set_cpu(sibl, irqmsk);
 			cpus_per_grp--;
 		}
+
+		cpu += nv->ngroups;
+		if (!cpumask_test_cpu(cpu, nmsk))
+			return;
 	}
 }
 
@@ -97,15 +110,6 @@ static int get_nodes_in_cpumask(cpumask_var_t *node_to_cpumask,
 	return nodes;
 }
 
-struct node_groups {
-	unsigned id;
-
-	union {
-		unsigned ngroups;
-		unsigned ncpus;
-	};
-};
-
 static int ncpus_cmp_func(const void *l, const void *r)
 {
 	const struct node_groups *ln = l;
@@ -320,8 +324,8 @@ static int __group_cpus_evenly(unsigned int startgrp, unsigned int numgrps,
 			 */
 			if (curgrp >= last_grp)
 				curgrp = 0;
-			grp_spread_init_one(&masks[curgrp], nmsk,
-						cpus_per_grp);
+
+			grp_spread_init_one(nv, &masks[curgrp], nmsk, cpus_per_grp);
 		}
 		done += nv->ngroups;
 	}
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-07  8:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-07  8:42 [PATCH] lib/group_cpus: sequentially bind CPUs within node to groups brookxu.cn

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®