[PATCH v4 4/4] sunrpc: eliminate a modulus operation from the enqueueing codepath
From: Jeff Layton
Date: Wed Jul 01 2026 - 16:10:55 EST
Currently we do this to determine the pool to enqueue on:
pidx = m->to_pool[cpu_to_node(raw_smp_processor_id())] % serv->sv_nrpools;
...but a modulus is rather expensive. Replace this instead with an
explicit check for running off the end of the array.
This situation should never occur, but if it does, just fall back to
pool 0.
This trades a ~20-30 cycle operation that isn't pipelined and
monopolizes the divider for a ~1 cycle well-predicted branch.
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
net/sunrpc/svc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index ae93a6f51087..ed841ea09079 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -252,7 +252,9 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv)
if (serv->sv_nrpools <= 1)
return serv->sv_pools;
- pidx = m->to_pool[cpu_to_node(raw_smp_processor_id())] % serv->sv_nrpools;
+ pidx = m->to_pool[cpu_to_node(raw_smp_processor_id())];
+ if (pidx >= serv->sv_nrpools)
+ pidx = 0;
/*
* Threads are spread evenly across the pools, but when there are
--
2.54.0