mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 15:43:08 -04:00
sunrpc: route to a populated pool in svc_pool_for_cpu()
svc_set_num_threads() spreads the requested threads evenly across the
service's pools (base = nrservs / sv_nrpools). When a service runs
fewer threads than it has pools -- e.g. an nfsd configured with fewer
threads than the host has NUMA nodes while running in "pernode" or
"percpu" mode -- the trailing pools are left with no threads at all.
svc_xprt_enqueue() selects a pool from the CPU servicing the transport,
queues the transport on that pool's sp_xprts, and only wakes a thread
from the same pool. Each thread services exclusively its own pool, so a
transport that lands on a threadless pool is enqueued on sp_xprts and
never picked up: the connection hangs indefinitely.
Have svc_pool_for_cpu() skip pools that currently have no threads,
falling back to the next populated pool. This trades NUMA locality for
a guarantee that the work is actually serviced. sp_nrthreads is only
updated under the service mutex; the lockless read here is a best-effort
routing hint, so annotate it with data_race().
Fixes: bfd241600a ("[PATCH] knfsd: make rpc threads pools numa aware")
Cc: stable@vger.kernel.org
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://patch.msgid.link/20260706-sunrpc-pool-mode-v5-1-6c4ee7cd89aa@kernel.org
Signed-off-by: Chuck Lever <cel@kernel.org>
This commit is contained in:
@@ -402,6 +402,7 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv)
|
||||
struct svc_pool_map *m = &svc_pool_map;
|
||||
int cpu = raw_smp_processor_id();
|
||||
unsigned int pidx = 0;
|
||||
unsigned int i;
|
||||
|
||||
if (serv->sv_nrpools <= 1)
|
||||
return serv->sv_pools;
|
||||
@@ -414,8 +415,34 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv)
|
||||
pidx = m->to_pool[cpu_to_node(cpu)];
|
||||
break;
|
||||
}
|
||||
pidx %= serv->sv_nrpools;
|
||||
|
||||
return &serv->sv_pools[pidx % serv->sv_nrpools];
|
||||
/*
|
||||
* It's possible to have a pool with no threads. Userland can just set
|
||||
* things up this way directly. Also, when threads are autodistributed
|
||||
* they are spread evenly across the pools, but when there are fewer
|
||||
* threads than pools some pools can end up with none.
|
||||
*
|
||||
* A transport enqueued on a threadless pool would never be picked up,
|
||||
* since each thread only services its own pool. Fall back to the next
|
||||
* populated pool, trading NUMA locality for a guarantee that the
|
||||
* transport is serviced.
|
||||
*/
|
||||
for (i = 0; i < serv->sv_nrpools; i++) {
|
||||
struct svc_pool *pool = &serv->sv_pools[pidx];
|
||||
|
||||
/* This is set under the service mutex and rarely ever
|
||||
* changes. A data race here is harmless.
|
||||
*/
|
||||
if (data_race(pool->sp_nrthreads))
|
||||
return pool;
|
||||
|
||||
if (++pidx >= serv->sv_nrpools)
|
||||
pidx = 0;
|
||||
}
|
||||
|
||||
/* No pool has any threads; nothing can service the transport. */
|
||||
return &serv->sv_pools[pidx];
|
||||
}
|
||||
|
||||
static int svc_rpcb_setup(struct svc_serv *serv, struct net *net)
|
||||
|
||||
Reference in New Issue
Block a user