* [PATCH v4 0/4] sunrpc: hardcode pool_mode to pernode, remove other modes
@ 2026-07-01 19:56 Jeff Layton
2026-07-01 19:56 ` [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() Jeff Layton
` (3 more replies)
0 siblings, 4 replies; 16+ messages in thread
From: Jeff Layton @ 2026-07-01 19:56 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Chuck Lever
Cc: linux-nfs, linux-kernel, Jeff Layton
This version drops the 5/4 follow-on patch that I had sent after the
original series, and changes the second patch to not allow unpooled
services to consult the map.
Patches #1 and #3 address what is a shortcoming of the existing code --
namely that the server can be configured to schedule RPCs to pools with
no threads in them.
The first patch addresses this problem: if the chosen pool has no
threads, then choose another that does.
The third patch tries to prevent this situation in the
auto-thread-placement case by ensuring that each populated node has at
least one thread.
The last patch is a performance micro-optimization. The old code used a
modulus (actually two) to determine the pool (and prevent potentially
overrunning the array). This trades that for a less cpu-intensive method
of finding the pool to use.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
Changes in v4:
- Drop 5/4 RCU patch
- Only let pooled services consult the map
- Comment and commit log fixes
- Link to v3: https://lore.kernel.org/r/20260629-sunrpc-pool-mode-v3-0-d92676606dfd@kernel.org
Changes in v3:
- Add patch to ensure that we don't route requests to empty pools
- When auto-distributing threads, always create at least one thread per populated pool
- Use sysfs_match_string for the module parameter
- Reword deprecation printk to be more vague about removal
- Explicitly set m_count == 0 in svc_pool_map_get()
- Optimize svc_pool_for_cpu() by eliminating modulus ops
- Link to v2: https://lore.kernel.org/r/20260625-sunrpc-pool-mode-v2-1-4f512b6e1ee8@kernel.org
Changes in v2:
- Accept any previously-accepted setting for pool_mode
- Link to v1: https://lore.kernel.org/r/20260423-sunrpc-pool-mode-v1-1-b7f20e35749b@kernel.org
---
Jeff Layton (4):
sunrpc: route to a populated pool in svc_pool_for_cpu()
sunrpc: hardcode pool_mode to pernode, remove other modes
sunrpc: guarantee a thread per CPU-bearing node when auto-distributing
sunrpc: eliminate a modulus operation from the enqueueing codepath
Documentation/admin-guide/kernel-parameters.txt | 20 +-
net/sunrpc/svc.c | 302 ++++++++----------------
2 files changed, 104 insertions(+), 218 deletions(-)
---
base-commit: f8eb95335cc219493427f976460cf4b7e9641e92
change-id: 20260423-sunrpc-pool-mode-3e6b56320dc4
Best regards,
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() 2026-07-01 19:56 [PATCH v4 0/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton @ 2026-07-01 19:56 ` Jeff Layton 2026-07-01 22:13 ` NeilBrown 2026-07-01 19:56 ` [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton ` (2 subsequent siblings) 3 siblings, 1 reply; 16+ messages in thread From: Jeff Layton @ 2026-07-01 19:56 UTC (permalink / raw) To: Trond Myklebust, Anna Schumaker, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever Cc: linux-nfs, linux-kernel, Jeff Layton 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: 0f0257eaa5d2 ("svc: Move the xprt independent code to the svc_xprt.c file") Signed-off-by: Jeff Layton <jlayton@kernel.org> --- net/sunrpc/svc.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index dd80a2eaaa74..82fb7faf563f 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -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,31 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv) pidx = m->to_pool[cpu_to_node(cpu)]; break; } + pidx %= serv->sv_nrpools; + + /* + * Threads 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 sp_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; + } - return &serv->sv_pools[pidx % serv->sv_nrpools]; + /* 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) -- 2.54.0 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() 2026-07-01 19:56 ` [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() Jeff Layton @ 2026-07-01 22:13 ` NeilBrown 2026-07-02 12:17 ` Jeff Layton 0 siblings, 1 reply; 16+ messages in thread From: NeilBrown @ 2026-07-01 22:13 UTC (permalink / raw) To: Jeff Layton Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel, Jeff Layton On Thu, 02 Jul 2026, Jeff Layton wrote: > 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: 0f0257eaa5d2 ("svc: Move the xprt independent code to the svc_xprt.c file") Why that commit? Did this ever work correctly? It seems more likely that Fixes: 3262c816a3d7 ("[PATCH] knfsd: split svc_serv into pools") is appropriate. > Signed-off-by: Jeff Layton <jlayton@kernel.org> > --- > net/sunrpc/svc.c | 26 +++++++++++++++++++++++++- > 1 file changed, 25 insertions(+), 1 deletion(-) > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > index dd80a2eaaa74..82fb7faf563f 100644 > --- a/net/sunrpc/svc.c > +++ b/net/sunrpc/svc.c > @@ -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,31 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv) > pidx = m->to_pool[cpu_to_node(cpu)]; > break; > } > + pidx %= serv->sv_nrpools; > + > + /* > + * Threads 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 sp_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; > + } > > - return &serv->sv_pools[pidx % serv->sv_nrpools]; > + /* No pool has any threads; nothing can service the transport. */ Would a WARN_ON_ONCE() be appropriate here? I think this is a sensible defensive-programming approach. Reviewed-by: NeilBrown <neil@brown.name> Thnaks, NeilBrown > + return &serv->sv_pools[pidx]; > } > > static int svc_rpcb_setup(struct svc_serv *serv, struct net *net) > > -- > 2.54.0 > > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() 2026-07-01 22:13 ` NeilBrown @ 2026-07-02 12:17 ` Jeff Layton 2026-07-02 12:31 ` Jeff Layton 0 siblings, 1 reply; 16+ messages in thread From: Jeff Layton @ 2026-07-02 12:17 UTC (permalink / raw) To: NeilBrown Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel On Thu, 2026-07-02 at 08:13 +1000, NeilBrown wrote: > On Thu, 02 Jul 2026, Jeff Layton wrote: > > 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: 0f0257eaa5d2 ("svc: Move the xprt independent code to the svc_xprt.c file") > > Why that commit? Did this ever work correctly? > It seems more likely that > Fixes: 3262c816a3d7 ("[PATCH] knfsd: split svc_serv into pools") > is appropriate. > Indeed. Good catch. > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > > --- > > net/sunrpc/svc.c | 26 +++++++++++++++++++++++++- > > 1 file changed, 25 insertions(+), 1 deletion(-) > > > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > index dd80a2eaaa74..82fb7faf563f 100644 > > --- a/net/sunrpc/svc.c > > +++ b/net/sunrpc/svc.c > > @@ -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,31 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv) > > pidx = m->to_pool[cpu_to_node(cpu)]; > > break; > > } > > + pidx %= serv->sv_nrpools; > > + > > + /* > > + * Threads 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 sp_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; > > + } > > > > - return &serv->sv_pools[pidx % serv->sv_nrpools]; > > + /* No pool has any threads; nothing can service the transport. */ > > Would a WARN_ON_ONCE() be appropriate here? > Maybe a pr_notice_once()? A stack trace isn't particularly helpful here, but it would be good to let someone know that this isn't optimally configured. I'll add one for v5. > I think this is a sensible defensive-programming approach. > > Reviewed-by: NeilBrown <neil@brown.name> > Thanks! > > + return &serv->sv_pools[pidx]; > > } > > > > static int svc_rpcb_setup(struct svc_serv *serv, struct net *net) > > > > -- > > 2.54.0 > > > > -- Jeff Layton <jlayton@kernel.org> ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() 2026-07-02 12:17 ` Jeff Layton @ 2026-07-02 12:31 ` Jeff Layton 2026-07-03 3:42 ` NeilBrown 0 siblings, 1 reply; 16+ messages in thread From: Jeff Layton @ 2026-07-02 12:31 UTC (permalink / raw) To: NeilBrown Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel On Thu, 2026-07-02 at 08:17 -0400, Jeff Layton wrote: > On Thu, 2026-07-02 at 08:13 +1000, NeilBrown wrote: > > On Thu, 02 Jul 2026, Jeff Layton wrote: > > > 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: 0f0257eaa5d2 ("svc: Move the xprt independent code to the svc_xprt.c file") > > > > Why that commit? Did this ever work correctly? > > It seems more likely that > > Fixes: 3262c816a3d7 ("[PATCH] knfsd: split svc_serv into pools") > > is appropriate. > > > > Indeed. Good catch. > I had the LLM run this down. We're both wrong. It briefly worked properly after 3262c816a3d7 ("split svc_serv into pools"), but then was broken in the same series in commit bfd241600a3b ("knfsd: make rpc threads pools numa aware"). So I think we want: Fixes: bfd241600a3b ("knfsd: make rpc threads pools numa aware") > > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > > > --- > > > net/sunrpc/svc.c | 26 +++++++++++++++++++++++++- > > > 1 file changed, 25 insertions(+), 1 deletion(-) > > > > > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > > index dd80a2eaaa74..82fb7faf563f 100644 > > > --- a/net/sunrpc/svc.c > > > +++ b/net/sunrpc/svc.c > > > @@ -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,31 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv) > > > pidx = m->to_pool[cpu_to_node(cpu)]; > > > break; > > > } > > > + pidx %= serv->sv_nrpools; > > > + > > > + /* > > > + * Threads 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 sp_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; > > > + } > > > > > > - return &serv->sv_pools[pidx % serv->sv_nrpools]; > > > + /* No pool has any threads; nothing can service the transport. */ > > > > Would a WARN_ON_ONCE() be appropriate here? > > > > Maybe a pr_notice_once()? A stack trace isn't particularly helpful > here, but it would be good to let someone know that this isn't > optimally configured. I'll add one for v5. > > This is probably not feasible, as there are cases where we legitimately queue the call to a pool with no threads. At startup, we create listeners and then threads only get spun up later. If we get a RPC on the listener port during that window, the message would fire. There's a similar window on shutdown. It might not hurt to add a tracepoint there though. > > I think this is a sensible defensive-programming approach. > > > > Reviewed-by: NeilBrown <neil@brown.name> > > > > Thanks! > > > > + return &serv->sv_pools[pidx]; > > > } > > > > > > static int svc_rpcb_setup(struct svc_serv *serv, struct net *net) > > > > > > -- > > > 2.54.0 > > > > > > -- Jeff Layton <jlayton@kernel.org> ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() 2026-07-02 12:31 ` Jeff Layton @ 2026-07-03 3:42 ` NeilBrown 2026-07-06 11:49 ` Jeff Layton 0 siblings, 1 reply; 16+ messages in thread From: NeilBrown @ 2026-07-03 3:42 UTC (permalink / raw) To: Jeff Layton Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel On Thu, 02 Jul 2026, Jeff Layton wrote: > On Thu, 2026-07-02 at 08:17 -0400, Jeff Layton wrote: > > On Thu, 2026-07-02 at 08:13 +1000, NeilBrown wrote: > > > On Thu, 02 Jul 2026, Jeff Layton wrote: > > > > 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: 0f0257eaa5d2 ("svc: Move the xprt independent code to the svc_xprt.c file") > > > > > > Why that commit? Did this ever work correctly? > > > It seems more likely that > > > Fixes: 3262c816a3d7 ("[PATCH] knfsd: split svc_serv into pools") > > > is appropriate. > > > > > > > Indeed. Good catch. > > > > I had the LLM run this down. We're both wrong. > > It briefly worked properly after 3262c816a3d7 ("split svc_serv into > pools"), but then was broken in the same series in commit bfd241600a3b > ("knfsd: make rpc threads pools numa aware"). So I think we want: > > Fixes: bfd241600a3b ("knfsd: make rpc threads pools numa aware") That is certainly credible - thanks. > > > > > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > > > > --- > > > > net/sunrpc/svc.c | 26 +++++++++++++++++++++++++- > > > > 1 file changed, 25 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > > > index dd80a2eaaa74..82fb7faf563f 100644 > > > > --- a/net/sunrpc/svc.c > > > > +++ b/net/sunrpc/svc.c > > > > @@ -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,31 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv) > > > > pidx = m->to_pool[cpu_to_node(cpu)]; > > > > break; > > > > } > > > > + pidx %= serv->sv_nrpools; > > > > + > > > > + /* > > > > + * Threads 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 sp_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; > > > > + } > > > > > > > > - return &serv->sv_pools[pidx % serv->sv_nrpools]; > > > > + /* No pool has any threads; nothing can service the transport. */ > > > > > > Would a WARN_ON_ONCE() be appropriate here? > > > > > > > Maybe a pr_notice_once()? A stack trace isn't particularly helpful > > here, but it would be good to let someone know that this isn't > > optimally configured. I'll add one for v5. > > > > > > This is probably not feasible, as there are cases where we legitimately > queue the call to a pool with no threads. > > At startup, we create listeners and then threads only get spun up > later. If we get a RPC on the listener port during that window, the > message would fire. There's a similar window on shutdown. > > It might not hurt to add a tracepoint there though. and a comment explaining when this might happen? The start-up window makes sense - as long as we start a thread on each pool it should be safe. But if we don't (if the admin request zero on some pools) we can still get stuck. Is there something simple we can do about that, or does the admin get to keep both halves? And on shutdown the threads stop before the sockets are cleaned up - but they do get cleaned up, so all good. Thanks, NeilBrown > > > > I think this is a sensible defensive-programming approach. > > > > > > Reviewed-by: NeilBrown <neil@brown.name> > > > > > > > Thanks! > > > > > > + return &serv->sv_pools[pidx]; > > > > } > > > > > > > > static int svc_rpcb_setup(struct svc_serv *serv, struct net *net) > > > > > > > > -- > > > > 2.54.0 > > > > > > > > > > -- > Jeff Layton <jlayton@kernel.org> > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() 2026-07-03 3:42 ` NeilBrown @ 2026-07-06 11:49 ` Jeff Layton 0 siblings, 0 replies; 16+ messages in thread From: Jeff Layton @ 2026-07-06 11:49 UTC (permalink / raw) To: NeilBrown Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel On Fri, 2026-07-03 at 13:42 +1000, NeilBrown wrote: > On Thu, 02 Jul 2026, Jeff Layton wrote: > > On Thu, 2026-07-02 at 08:17 -0400, Jeff Layton wrote: > > > On Thu, 2026-07-02 at 08:13 +1000, NeilBrown wrote: > > > > On Thu, 02 Jul 2026, Jeff Layton wrote: > > > > > 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: 0f0257eaa5d2 ("svc: Move the xprt independent code to the svc_xprt.c file") > > > > > > > > Why that commit? Did this ever work correctly? > > > > It seems more likely that > > > > Fixes: 3262c816a3d7 ("[PATCH] knfsd: split svc_serv into pools") > > > > is appropriate. > > > > > > > > > > Indeed. Good catch. > > > > > > > I had the LLM run this down. We're both wrong. > > > > It briefly worked properly after 3262c816a3d7 ("split svc_serv into > > pools"), but then was broken in the same series in commit bfd241600a3b > > ("knfsd: make rpc threads pools numa aware"). So I think we want: > > > > Fixes: bfd241600a3b ("knfsd: make rpc threads pools numa aware") > > That is certainly credible - thanks. > > > > > > > > > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > > > > > --- > > > > > net/sunrpc/svc.c | 26 +++++++++++++++++++++++++- > > > > > 1 file changed, 25 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > > > > index dd80a2eaaa74..82fb7faf563f 100644 > > > > > --- a/net/sunrpc/svc.c > > > > > +++ b/net/sunrpc/svc.c > > > > > @@ -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,31 @@ struct svc_pool *svc_pool_for_cpu(struct svc_serv *serv) > > > > > pidx = m->to_pool[cpu_to_node(cpu)]; > > > > > break; > > > > > } > > > > > + pidx %= serv->sv_nrpools; > > > > > + > > > > > + /* > > > > > + * Threads 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 sp_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; > > > > > + } > > > > > > > > > > - return &serv->sv_pools[pidx % serv->sv_nrpools]; > > > > > + /* No pool has any threads; nothing can service the transport. */ > > > > > > > > Would a WARN_ON_ONCE() be appropriate here? > > > > > > > > > > Maybe a pr_notice_once()? A stack trace isn't particularly helpful > > > here, but it would be good to let someone know that this isn't > > > optimally configured. I'll add one for v5. > > > > > > > > > > This is probably not feasible, as there are cases where we legitimately > > queue the call to a pool with no threads. > > > > At startup, we create listeners and then threads only get spun up > > later. If we get a RPC on the listener port during that window, the > > message would fire. There's a similar window on shutdown. > > > > It might not hurt to add a tracepoint there though. > > and a comment explaining when this might happen? > Sure, I'll add one. > The start-up window makes sense - as long as we start a thread on each > pool it should be safe. But if we don't (if the admin request zero on > some pools) we can still get stuck. Is there something simple we can do > about that, or does the admin get to keep both halves? > Well, no. This patch makes sure that RPCs are always routed to a pool with CPUs. They might end up doing cross-NUMA calls and performance might suck, but it shouldn't get stuck. > And on shutdown the threads stop before the sockets are cleaned up - but > they do get cleaned up, so all good. > > Correct. > > > > > > > I think this is a sensible defensive-programming approach. > > > > > > > > Reviewed-by: NeilBrown <neil@brown.name> > > > > > > > > > > Thanks! > > > > > > > > + return &serv->sv_pools[pidx]; > > > > > } > > > > > > > > > > static int svc_rpcb_setup(struct svc_serv *serv, struct net *net) > > > > > > > > > > -- > > > > > 2.54.0 > > > > > > > > > > > > > > -- > > Jeff Layton <jlayton@kernel.org> > > Thanks again for the review. -- Jeff Layton <jlayton@kernel.org> ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes 2026-07-01 19:56 [PATCH v4 0/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton 2026-07-01 19:56 ` [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() Jeff Layton @ 2026-07-01 19:56 ` Jeff Layton 2026-07-01 22:31 ` NeilBrown 2026-07-01 19:56 ` [PATCH v4 3/4] sunrpc: guarantee a thread per CPU-bearing node when auto-distributing Jeff Layton 2026-07-01 19:56 ` [PATCH v4 4/4] sunrpc: eliminate a modulus operation from the enqueueing codepath Jeff Layton 3 siblings, 1 reply; 16+ messages in thread From: Jeff Layton @ 2026-07-01 19:56 UTC (permalink / raw) To: Trond Myklebust, Anna Schumaker, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever Cc: linux-nfs, linux-kernel, Jeff Layton The SVC_POOL_AUTO/GLOBAL/PERCPU/PERNODE pool mode selection machinery was added when NUMA was new and the right default was unclear. The default has always been "global" (a single pool for the whole service); the other modes were only used when an admin explicitly set the pool_mode parameter or asked for "auto", which then picked a mode from the host topology. Today, pernode is the right choice everywhere: - On multi-NUMA hosts, it gives one pool per node with proper thread affinity and NUMA-local memory allocation. - On single-node hosts, pernode degenerates to exactly one pool, identical to the old "global" mode -- svc_pool_for_cpu() short- circuits when sv_nrpools <= 1, no CPU affinity is set, and memory is allocated from the single node. The percpu mode (one pool per CPU) created excessive pools relative to the number of threads most deployments run, and was only auto-selected in a narrow case (single node, >2 CPUs). Note that this changes the default behaviour on multi-NUMA hosts: a service that previously ran with a single global pool now gets one pool per NUMA node by default. This in turn means a host running fewer threads than it has NUMA nodes can end up with pools that have no threads. svc_pool_for_cpu() already falls back to a populated pool in that case, so transports are still serviced. Remove the SVC_POOL_* enum, mode selection heuristic, svc_pool_map_init_percpu(), and all mode-based switch statements. Simplify pool map functions to always use the pernode path. If pool map allocation fails, svc_pool_map_get() now returns 0 and service creation fails, rather than silently falling back to a single global pool. With the mode check gone, svc_pool_map_get_node() would dereference the shared pool_to[] for every service that starts a thread. Only services created via svc_create_pooled() hold a map reference that keeps that array allocated, so gate the lookup in svc_new_thread() on sv_is_pooled: unpooled services (e.g. lockd, the NFS callback) use NUMA_NO_NODE and never consult the map. The kmalloc_node() callers in svc_prepare_thread() already accept NUMA_NO_NODE, but __folio_alloc_node() requires a valid node id, so resolve NUMA_NO_NODE to numa_mem_id() for the scratch folio allocation. The module parameter and netlink interfaces are preserved for backward compatibility: - Writing any of the four documented mode names still succeeds silently - Reading always returns "pernode" - Writing to the module parameter emits a deprecation notice Update Documentation/admin-guide/kernel-parameters.txt to mark the pool_mode parameter deprecated and describe the new behaviour. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jeff Layton <jlayton@kernel.org> --- Documentation/admin-guide/kernel-parameters.txt | 20 +- net/sunrpc/svc.c | 265 ++++++------------------ 2 files changed, 65 insertions(+), 220 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index b5493a7f8f22..441b78867478 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -7441,19 +7441,13 @@ Kernel parameters sunrpc.pool_mode= [NFS] - Control how the NFS server code allocates CPUs to - service thread pools. Depending on how many NICs - you have and where their interrupts are bound, this - option will affect which CPUs will do NFS serving. - Note: this parameter cannot be changed while the - NFS server is running. - - auto the server chooses an appropriate mode - automatically using heuristics - global a single global pool contains all CPUs - percpu one pool for each CPU - pernode one pool for each NUMA node (equivalent - to global on non-NUMA machines) + Deprecated. The NFS server now always uses one + service thread pool per NUMA node (equivalent to a + single global pool on non-NUMA machines). All of + the previously accepted values (auto, global, + percpu, pernode) are still accepted for backward + compatibility but are ignored: the mode is always + pernode, and reads always return "pernode". sunrpc.tcp_slot_table_entries= sunrpc.udp_slot_table_entries= diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 82fb7faf563f..c9fba7edaace 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -38,82 +38,36 @@ static void svc_unregister(const struct svc_serv *serv, struct net *net); -#define SVC_POOL_DEFAULT SVC_POOL_GLOBAL - /* - * Mode for mapping cpus to pools. - */ -enum { - SVC_POOL_AUTO = -1, /* choose one of the others */ - SVC_POOL_GLOBAL, /* no mapping, just a single global pool - * (legacy & UP mode) */ - SVC_POOL_PERCPU, /* one pool per cpu */ - SVC_POOL_PERNODE /* one pool per numa node */ -}; - -/* - * Structure for mapping cpus to pools and vice versa. + * Structure for mapping nodes to pools and vice versa. * Setup once during sunrpc initialisation. */ struct svc_pool_map { int count; /* How many svc_servs use us */ - int mode; /* Note: int not enum to avoid - * warnings about "enumeration value - * not handled in switch" */ unsigned int npools; - unsigned int *pool_to; /* maps pool id to cpu or node */ - unsigned int *to_pool; /* maps cpu or node to pool id */ + unsigned int *pool_to; /* maps pool id to node */ + unsigned int *to_pool; /* maps node to pool id */ }; -static struct svc_pool_map svc_pool_map = { - .mode = SVC_POOL_DEFAULT -}; +static struct svc_pool_map svc_pool_map; static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */ -static int -__param_set_pool_mode(const char *val, struct svc_pool_map *m) -{ - int err, mode; - - mutex_lock(&svc_pool_map_mutex); - - err = 0; - if (!strncmp(val, "auto", 4)) - mode = SVC_POOL_AUTO; - else if (!strncmp(val, "global", 6)) - mode = SVC_POOL_GLOBAL; - else if (!strncmp(val, "percpu", 6)) - mode = SVC_POOL_PERCPU; - else if (!strncmp(val, "pernode", 7)) - mode = SVC_POOL_PERNODE; - else - err = -EINVAL; - - if (err) - goto out; - - if (m->count == 0) - m->mode = mode; - else if (mode != m->mode) - err = -EBUSY; -out: - mutex_unlock(&svc_pool_map_mutex); - return err; -} - -static int -param_set_pool_mode(const char *val, const struct kernel_param *kp) -{ - struct svc_pool_map *m = kp->arg; - - return __param_set_pool_mode(val, m); -} +/* + * Pool modes that were historically accepted. They no longer select + * anything: the pool mode is always pernode. The names are retained + * only so that writing a previously-valid value still succeeds. + */ +static const char * const pool_mode_names[] = { + "auto", "global", "percpu", "pernode", +}; int sunrpc_set_pool_mode(const char *val) { - return __param_set_pool_mode(val, &svc_pool_map); + int idx = sysfs_match_string(pool_mode_names, val); + + return idx < 0 ? idx : 0; } EXPORT_SYMBOL(sunrpc_set_pool_mode); @@ -122,84 +76,32 @@ EXPORT_SYMBOL(sunrpc_set_pool_mode); * @buf: where to write the current pool_mode * @size: size of @buf * - * Grab the current pool_mode from the svc_pool_map and write - * the resulting string to @buf. Returns the number of characters + * Write the pool_mode string to @buf. Returns the number of characters * written to @buf (a'la snprintf()). */ int sunrpc_get_pool_mode(char *buf, size_t size) { - struct svc_pool_map *m = &svc_pool_map; - - switch (m->mode) - { - case SVC_POOL_AUTO: - return snprintf(buf, size, "auto"); - case SVC_POOL_GLOBAL: - return snprintf(buf, size, "global"); - case SVC_POOL_PERCPU: - return snprintf(buf, size, "percpu"); - case SVC_POOL_PERNODE: - return snprintf(buf, size, "pernode"); - default: - return snprintf(buf, size, "%d", m->mode); - } + return snprintf(buf, size, "pernode"); } EXPORT_SYMBOL(sunrpc_get_pool_mode); static int -param_get_pool_mode(char *buf, const struct kernel_param *kp) +param_set_pool_mode(const char *val, const struct kernel_param *kp) { - char str[16]; - int len; - - len = sunrpc_get_pool_mode(str, ARRAY_SIZE(str)); - - /* Ensure we have room for newline and NUL */ - len = min_t(int, len, ARRAY_SIZE(str) - 2); - - /* tack on the newline */ - str[len] = '\n'; - str[len + 1] = '\0'; - - return sysfs_emit(buf, "%s", str); + pr_notice_once("sunrpc: the pool_mode module parameter is deprecated and no longer has any effect; the pool mode is always 'pernode'\n"); + return sunrpc_set_pool_mode(val); } -module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, - &svc_pool_map, 0644); - -/* - * Detect best pool mapping mode heuristically, - * according to the machine's topology. - */ static int -svc_pool_map_choose_mode(void) +param_get_pool_mode(char *buf, const struct kernel_param *kp) { - unsigned int node; - - if (nr_online_nodes > 1) { - /* - * Actually have multiple NUMA nodes, - * so split pools on NUMA node boundaries - */ - return SVC_POOL_PERNODE; - } - - node = first_online_node; - if (nr_cpus_node(node) > 2) { - /* - * Non-trivial SMP, or CONFIG_NUMA on - * non-NUMA hardware, e.g. with a generic - * x86_64 kernel on Xeons. In this case we - * want to divide the pools on cpu boundaries. - */ - return SVC_POOL_PERCPU; - } - - /* default: one global pool */ - return SVC_POOL_GLOBAL; + return sysfs_emit(buf, "pernode\n"); } +module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, + NULL, 0644); + /* * Allocate the to_pool[] and pool_to[] arrays. * Returns 0 on success or an errno. @@ -224,35 +126,7 @@ svc_pool_map_alloc_arrays(struct svc_pool_map *m, unsigned int maxpools) } /* - * Initialise the pool map for SVC_POOL_PERCPU mode. - * Returns number of pools or <0 on error. - */ -static int -svc_pool_map_init_percpu(struct svc_pool_map *m) -{ - unsigned int maxpools = nr_cpu_ids; - unsigned int pidx = 0; - unsigned int cpu; - int err; - - err = svc_pool_map_alloc_arrays(m, maxpools); - if (err) - return err; - - for_each_online_cpu(cpu) { - BUG_ON(pidx >= maxpools); - m->to_pool[cpu] = pidx; - m->pool_to[pidx] = cpu; - pidx++; - } - /* cpus brought online later all get mapped to pool0, sorry */ - - return pidx; -}; - - -/* - * Initialise the pool map for SVC_POOL_PERNODE mode. + * Initialise the pool map for one pool per NUMA node. * Returns number of pools or <0 on error. */ static int @@ -281,17 +155,16 @@ svc_pool_map_init_pernode(struct svc_pool_map *m) /* - * Add a reference to the global map of cpus to pools (and + * Add a reference to the global map of nodes to pools (and * vice versa) if pools are in use. * Initialise the map if we're the first user. - * Returns the number of pools. If this is '1', no reference - * was taken. + * Returns the number of pools, or 0 on failure. */ static unsigned int svc_pool_map_get(void) { struct svc_pool_map *m = &svc_pool_map; - int npools = -1; + int npools; mutex_lock(&svc_pool_map_mutex); if (m->count++) { @@ -299,22 +172,11 @@ svc_pool_map_get(void) return m->npools; } - if (m->mode == SVC_POOL_AUTO) - m->mode = svc_pool_map_choose_mode(); - - switch (m->mode) { - case SVC_POOL_PERCPU: - npools = svc_pool_map_init_percpu(m); - break; - case SVC_POOL_PERNODE: - npools = svc_pool_map_init_pernode(m); - break; - } - + npools = svc_pool_map_init_pernode(m); if (npools <= 0) { - /* default, or memory allocation failure */ - npools = 1; - m->mode = SVC_POOL_GLOBAL; + m->count = 0; + mutex_unlock(&svc_pool_map_mutex); + return 0; } m->npools = npools; mutex_unlock(&svc_pool_map_mutex); @@ -322,7 +184,7 @@ svc_pool_map_get(void) } /* - * Drop a reference to the global map of cpus to pools. + * Drop a reference to the global map of nodes to pools. * When the last reference is dropped, the map data is * freed; this allows the sysadmin to change the pool. */ @@ -346,14 +208,11 @@ static int svc_pool_map_get_node(unsigned int pidx) { const struct svc_pool_map *m = &svc_pool_map; - if (m->count) { - if (m->mode == SVC_POOL_PERCPU) - return cpu_to_node(m->pool_to[pidx]); - if (m->mode == SVC_POOL_PERNODE) - return m->pool_to[pidx]; - } + if (m->count) + return m->pool_to[pidx]; return numa_mem_id(); } + /* * Set the given thread's cpus_allowed mask so that it * will only run on cpus in the given pool. @@ -372,27 +231,15 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) if (m->count == 0) return; - switch (m->mode) { - case SVC_POOL_PERCPU: - { - set_cpus_allowed_ptr(task, cpumask_of(node)); - break; - } - case SVC_POOL_PERNODE: - { - set_cpus_allowed_ptr(task, cpumask_of_node(node)); - break; - } - } + set_cpus_allowed_ptr(task, cpumask_of_node(node)); } /** * svc_pool_for_cpu - Select pool to run a thread on this cpu * @serv: An RPC service * - * Use the active CPU and the svc_pool_map's mode setting to - * select the svc thread pool to use. Once initialized, the - * svc_pool_map does not change. + * Use the active CPU and the svc_pool_map to select the svc thread + * pool to use. Once initialized, the svc_pool_map does not change. * * Return value: * A pointer to an svc_pool @@ -400,22 +247,12 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) 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; + unsigned int pidx, i; if (serv->sv_nrpools <= 1) return serv->sv_pools; - switch (m->mode) { - case SVC_POOL_PERCPU: - pidx = m->to_pool[cpu]; - break; - case SVC_POOL_PERNODE: - pidx = m->to_pool[cpu_to_node(cpu)]; - break; - } - pidx %= serv->sv_nrpools; + pidx = m->to_pool[cpu_to_node(raw_smp_processor_id())] % serv->sv_nrpools; /* * Threads are spread evenly across the pools, but when there are @@ -641,6 +478,9 @@ struct svc_serv *svc_create_pooled(struct svc_program *prog, struct svc_serv *serv; unsigned int npools = svc_pool_map_get(); + if (!npools) + return NULL; + serv = __svc_create(prog, nprogs, stats, bufsize, npools, threadfn); if (!serv) goto out_err; @@ -775,7 +615,10 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node) rqstp->rq_server = serv; rqstp->rq_pool = pool; - rqstp->rq_scratch_folio = __folio_alloc_node(GFP_KERNEL, 0, node); + /* __folio_alloc_node() rejects NUMA_NO_NODE; let it pick for us */ + rqstp->rq_scratch_folio = + __folio_alloc_node(GFP_KERNEL, 0, + node == NUMA_NO_NODE ? numa_mem_id() : node); if (!rqstp->rq_scratch_folio) goto out_enomem; @@ -864,7 +707,15 @@ int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool) int node; int err = 0; - node = svc_pool_map_get_node(pool->sp_id); + /* + * Only pooled services hold a reference to the pool map, so only they + * may consult it. Unpooled services (e.g. lockd, the NFS callback) + * leave placement to the allocator. + */ + if (serv->sv_is_pooled) + node = svc_pool_map_get_node(pool->sp_id); + else + node = NUMA_NO_NODE; rqstp = svc_prepare_thread(serv, pool, node); if (!rqstp) -- 2.54.0 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes 2026-07-01 19:56 ` [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton @ 2026-07-01 22:31 ` NeilBrown 2026-07-02 12:46 ` Jeff Layton 0 siblings, 1 reply; 16+ messages in thread From: NeilBrown @ 2026-07-01 22:31 UTC (permalink / raw) To: Jeff Layton Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel, Jeff Layton On Thu, 02 Jul 2026, Jeff Layton wrote: > The SVC_POOL_AUTO/GLOBAL/PERCPU/PERNODE pool mode selection machinery > was added when NUMA was new and the right default was unclear. The > default has always been "global" (a single pool for the whole service); > the other modes were only used when an admin explicitly set the > pool_mode parameter or asked for "auto", which then picked a mode from > the host topology. Today, pernode is the right choice everywhere: > > - On multi-NUMA hosts, it gives one pool per node with proper thread > affinity and NUMA-local memory allocation. > - On single-node hosts, pernode degenerates to exactly one pool, > identical to the old "global" mode -- svc_pool_for_cpu() short- > circuits when sv_nrpools <= 1, no CPU affinity is set, and memory > is allocated from the single node. > > The percpu mode (one pool per CPU) created excessive pools relative to > the number of threads most deployments run, and was only auto-selected > in a narrow case (single node, >2 CPUs). > > Note that this changes the default behaviour on multi-NUMA hosts: a > service that previously ran with a single global pool now gets one pool > per NUMA node by default. This in turn means a host running fewer > threads than it has NUMA nodes can end up with pools that have no > threads. svc_pool_for_cpu() already falls back to a populated pool in > that case, so transports are still serviced. > > Remove the SVC_POOL_* enum, mode selection heuristic, > svc_pool_map_init_percpu(), and all mode-based switch statements. > Simplify pool map functions to always use the pernode path. If pool > map allocation fails, svc_pool_map_get() now returns 0 and service > creation fails, rather than silently falling back to a single global > pool. > > With the mode check gone, svc_pool_map_get_node() would dereference the > shared pool_to[] for every service that starts a thread. Only services > created via svc_create_pooled() hold a map reference that keeps that > array allocated, so gate the lookup in svc_new_thread() on sv_is_pooled: > unpooled services (e.g. lockd, the NFS callback) use NUMA_NO_NODE and > never consult the map. The kmalloc_node() callers in > svc_prepare_thread() already accept NUMA_NO_NODE, but __folio_alloc_node() > requires a valid node id, so resolve NUMA_NO_NODE to numa_mem_id() for > the scratch folio allocation. > > The module parameter and netlink interfaces are preserved for backward > compatibility: > - Writing any of the four documented mode names still succeeds silently > - Reading always returns "pernode" > - Writing to the module parameter emits a deprecation notice > > Update Documentation/admin-guide/kernel-parameters.txt to mark the > pool_mode parameter deprecated and describe the new behaviour. > > Assisted-by: Claude:claude-opus-4-8 > Signed-off-by: Jeff Layton <jlayton@kernel.org> > --- > Documentation/admin-guide/kernel-parameters.txt | 20 +- > net/sunrpc/svc.c | 265 ++++++------------------ > 2 files changed, 65 insertions(+), 220 deletions(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index b5493a7f8f22..441b78867478 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -7441,19 +7441,13 @@ Kernel parameters > > sunrpc.pool_mode= > [NFS] > - Control how the NFS server code allocates CPUs to > - service thread pools. Depending on how many NICs > - you have and where their interrupts are bound, this > - option will affect which CPUs will do NFS serving. > - Note: this parameter cannot be changed while the > - NFS server is running. > - > - auto the server chooses an appropriate mode > - automatically using heuristics > - global a single global pool contains all CPUs > - percpu one pool for each CPU > - pernode one pool for each NUMA node (equivalent > - to global on non-NUMA machines) > + Deprecated. The NFS server now always uses one > + service thread pool per NUMA node (equivalent to a > + single global pool on non-NUMA machines). All of > + the previously accepted values (auto, global, > + percpu, pernode) are still accepted for backward > + compatibility but are ignored: the mode is always > + pernode, and reads always return "pernode". > > sunrpc.tcp_slot_table_entries= > sunrpc.udp_slot_table_entries= > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > index 82fb7faf563f..c9fba7edaace 100644 > --- a/net/sunrpc/svc.c > +++ b/net/sunrpc/svc.c > @@ -38,82 +38,36 @@ > > static void svc_unregister(const struct svc_serv *serv, struct net *net); > > -#define SVC_POOL_DEFAULT SVC_POOL_GLOBAL > - > /* > - * Mode for mapping cpus to pools. > - */ > -enum { > - SVC_POOL_AUTO = -1, /* choose one of the others */ > - SVC_POOL_GLOBAL, /* no mapping, just a single global pool > - * (legacy & UP mode) */ > - SVC_POOL_PERCPU, /* one pool per cpu */ > - SVC_POOL_PERNODE /* one pool per numa node */ > -}; > - > -/* > - * Structure for mapping cpus to pools and vice versa. > + * Structure for mapping nodes to pools and vice versa. > * Setup once during sunrpc initialisation. > */ > > struct svc_pool_map { > int count; /* How many svc_servs use us */ > - int mode; /* Note: int not enum to avoid > - * warnings about "enumeration value > - * not handled in switch" */ > unsigned int npools; > - unsigned int *pool_to; /* maps pool id to cpu or node */ > - unsigned int *to_pool; /* maps cpu or node to pool id */ > + unsigned int *pool_to; /* maps pool id to node */ > + unsigned int *to_pool; /* maps node to pool id */ > }; > > -static struct svc_pool_map svc_pool_map = { > - .mode = SVC_POOL_DEFAULT > -}; > +static struct svc_pool_map svc_pool_map; > > static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */ > > -static int > -__param_set_pool_mode(const char *val, struct svc_pool_map *m) > -{ > - int err, mode; > - > - mutex_lock(&svc_pool_map_mutex); > - > - err = 0; > - if (!strncmp(val, "auto", 4)) > - mode = SVC_POOL_AUTO; > - else if (!strncmp(val, "global", 6)) > - mode = SVC_POOL_GLOBAL; > - else if (!strncmp(val, "percpu", 6)) > - mode = SVC_POOL_PERCPU; > - else if (!strncmp(val, "pernode", 7)) > - mode = SVC_POOL_PERNODE; > - else > - err = -EINVAL; > - > - if (err) > - goto out; > - > - if (m->count == 0) > - m->mode = mode; > - else if (mode != m->mode) > - err = -EBUSY; > -out: > - mutex_unlock(&svc_pool_map_mutex); > - return err; > -} > - > -static int > -param_set_pool_mode(const char *val, const struct kernel_param *kp) > -{ > - struct svc_pool_map *m = kp->arg; > - > - return __param_set_pool_mode(val, m); > -} > +/* > + * Pool modes that were historically accepted. They no longer select > + * anything: the pool mode is always pernode. The names are retained > + * only so that writing a previously-valid value still succeeds. > + */ > +static const char * const pool_mode_names[] = { > + "auto", "global", "percpu", "pernode", > +}; > > int sunrpc_set_pool_mode(const char *val) > { > - return __param_set_pool_mode(val, &svc_pool_map); > + int idx = sysfs_match_string(pool_mode_names, val); > + > + return idx < 0 ? idx : 0; > } > EXPORT_SYMBOL(sunrpc_set_pool_mode); > > @@ -122,84 +76,32 @@ EXPORT_SYMBOL(sunrpc_set_pool_mode); > * @buf: where to write the current pool_mode > * @size: size of @buf > * > - * Grab the current pool_mode from the svc_pool_map and write > - * the resulting string to @buf. Returns the number of characters > + * Write the pool_mode string to @buf. Returns the number of characters > * written to @buf (a'la snprintf()). > */ > int > sunrpc_get_pool_mode(char *buf, size_t size) > { > - struct svc_pool_map *m = &svc_pool_map; > - > - switch (m->mode) > - { > - case SVC_POOL_AUTO: > - return snprintf(buf, size, "auto"); > - case SVC_POOL_GLOBAL: > - return snprintf(buf, size, "global"); > - case SVC_POOL_PERCPU: > - return snprintf(buf, size, "percpu"); > - case SVC_POOL_PERNODE: > - return snprintf(buf, size, "pernode"); > - default: > - return snprintf(buf, size, "%d", m->mode); > - } > + return snprintf(buf, size, "pernode"); > } > EXPORT_SYMBOL(sunrpc_get_pool_mode); > > static int > -param_get_pool_mode(char *buf, const struct kernel_param *kp) > +param_set_pool_mode(const char *val, const struct kernel_param *kp) > { > - char str[16]; > - int len; > - > - len = sunrpc_get_pool_mode(str, ARRAY_SIZE(str)); > - > - /* Ensure we have room for newline and NUL */ > - len = min_t(int, len, ARRAY_SIZE(str) - 2); > - > - /* tack on the newline */ > - str[len] = '\n'; > - str[len + 1] = '\0'; > - > - return sysfs_emit(buf, "%s", str); > + pr_notice_once("sunrpc: the pool_mode module parameter is deprecated and no longer has any effect; the pool mode is always 'pernode'\n"); > + return sunrpc_set_pool_mode(val); > } > > -module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, > - &svc_pool_map, 0644); > - > -/* > - * Detect best pool mapping mode heuristically, > - * according to the machine's topology. > - */ > static int > -svc_pool_map_choose_mode(void) > +param_get_pool_mode(char *buf, const struct kernel_param *kp) > { > - unsigned int node; > - > - if (nr_online_nodes > 1) { > - /* > - * Actually have multiple NUMA nodes, > - * so split pools on NUMA node boundaries > - */ > - return SVC_POOL_PERNODE; > - } > - > - node = first_online_node; > - if (nr_cpus_node(node) > 2) { > - /* > - * Non-trivial SMP, or CONFIG_NUMA on > - * non-NUMA hardware, e.g. with a generic > - * x86_64 kernel on Xeons. In this case we > - * want to divide the pools on cpu boundaries. > - */ > - return SVC_POOL_PERCPU; > - } > - > - /* default: one global pool */ > - return SVC_POOL_GLOBAL; > + return sysfs_emit(buf, "pernode\n"); > } > > +module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, > + NULL, 0644); > + > /* > * Allocate the to_pool[] and pool_to[] arrays. > * Returns 0 on success or an errno. > @@ -224,35 +126,7 @@ svc_pool_map_alloc_arrays(struct svc_pool_map *m, unsigned int maxpools) > } > > /* > - * Initialise the pool map for SVC_POOL_PERCPU mode. > - * Returns number of pools or <0 on error. > - */ > -static int > -svc_pool_map_init_percpu(struct svc_pool_map *m) > -{ > - unsigned int maxpools = nr_cpu_ids; > - unsigned int pidx = 0; > - unsigned int cpu; > - int err; > - > - err = svc_pool_map_alloc_arrays(m, maxpools); > - if (err) > - return err; > - > - for_each_online_cpu(cpu) { > - BUG_ON(pidx >= maxpools); > - m->to_pool[cpu] = pidx; > - m->pool_to[pidx] = cpu; > - pidx++; > - } > - /* cpus brought online later all get mapped to pool0, sorry */ > - > - return pidx; > -}; > - > - > -/* > - * Initialise the pool map for SVC_POOL_PERNODE mode. > + * Initialise the pool map for one pool per NUMA node. > * Returns number of pools or <0 on error. > */ > static int > @@ -281,17 +155,16 @@ svc_pool_map_init_pernode(struct svc_pool_map *m) > > > /* > - * Add a reference to the global map of cpus to pools (and > + * Add a reference to the global map of nodes to pools (and > * vice versa) if pools are in use. > * Initialise the map if we're the first user. > - * Returns the number of pools. If this is '1', no reference > - * was taken. > + * Returns the number of pools, or 0 on failure. > */ > static unsigned int > svc_pool_map_get(void) > { > struct svc_pool_map *m = &svc_pool_map; > - int npools = -1; > + int npools; > > mutex_lock(&svc_pool_map_mutex); > if (m->count++) { > @@ -299,22 +172,11 @@ svc_pool_map_get(void) > return m->npools; > } > > - if (m->mode == SVC_POOL_AUTO) > - m->mode = svc_pool_map_choose_mode(); > - > - switch (m->mode) { > - case SVC_POOL_PERCPU: > - npools = svc_pool_map_init_percpu(m); > - break; > - case SVC_POOL_PERNODE: > - npools = svc_pool_map_init_pernode(m); > - break; > - } > - > + npools = svc_pool_map_init_pernode(m); > if (npools <= 0) { > - /* default, or memory allocation failure */ > - npools = 1; > - m->mode = SVC_POOL_GLOBAL; > + m->count = 0; > + mutex_unlock(&svc_pool_map_mutex); > + return 0; > } > m->npools = npools; > mutex_unlock(&svc_pool_map_mutex); > @@ -322,7 +184,7 @@ svc_pool_map_get(void) > } > > /* > - * Drop a reference to the global map of cpus to pools. > + * Drop a reference to the global map of nodes to pools. > * When the last reference is dropped, the map data is > * freed; this allows the sysadmin to change the pool. > */ > @@ -346,14 +208,11 @@ static int svc_pool_map_get_node(unsigned int pidx) > { > const struct svc_pool_map *m = &svc_pool_map; > > - if (m->count) { > - if (m->mode == SVC_POOL_PERCPU) > - return cpu_to_node(m->pool_to[pidx]); > - if (m->mode == SVC_POOL_PERNODE) > - return m->pool_to[pidx]; > - } > + if (m->count) > + return m->pool_to[pidx]; > return numa_mem_id(); > } > + > /* > * Set the given thread's cpus_allowed mask so that it > * will only run on cpus in the given pool. > @@ -372,27 +231,15 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) > if (m->count == 0) > return; > > - switch (m->mode) { > - case SVC_POOL_PERCPU: > - { > - set_cpus_allowed_ptr(task, cpumask_of(node)); > - break; > - } > - case SVC_POOL_PERNODE: > - { > - set_cpus_allowed_ptr(task, cpumask_of_node(node)); > - break; > - } > - } > + set_cpus_allowed_ptr(task, cpumask_of_node(node)); > } > > /** > * svc_pool_for_cpu - Select pool to run a thread on this cpu > * @serv: An RPC service > * > - * Use the active CPU and the svc_pool_map's mode setting to > - * select the svc thread pool to use. Once initialized, the > - * svc_pool_map does not change. > + * Use the active CPU and the svc_pool_map to select the svc thread > + * pool to use. Once initialized, the svc_pool_map does not change. > * > * Return value: > * A pointer to an svc_pool > @@ -400,22 +247,12 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) > 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; > + unsigned int pidx, i; > > if (serv->sv_nrpools <= 1) > return serv->sv_pools; > > - switch (m->mode) { > - case SVC_POOL_PERCPU: > - pidx = m->to_pool[cpu]; > - break; > - case SVC_POOL_PERNODE: > - pidx = m->to_pool[cpu_to_node(cpu)]; > - break; > - } > - pidx %= serv->sv_nrpools; > + pidx = m->to_pool[cpu_to_node(raw_smp_processor_id())] % serv->sv_nrpools; > > /* > * Threads are spread evenly across the pools, but when there are > @@ -641,6 +478,9 @@ struct svc_serv *svc_create_pooled(struct svc_program *prog, > struct svc_serv *serv; > unsigned int npools = svc_pool_map_get(); > > + if (!npools) > + return NULL; > + > serv = __svc_create(prog, nprogs, stats, bufsize, npools, threadfn); > if (!serv) > goto out_err; > @@ -775,7 +615,10 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node) > rqstp->rq_server = serv; > rqstp->rq_pool = pool; > > - rqstp->rq_scratch_folio = __folio_alloc_node(GFP_KERNEL, 0, node); > + /* __folio_alloc_node() rejects NUMA_NO_NODE; let it pick for us */ > + rqstp->rq_scratch_folio = > + __folio_alloc_node(GFP_KERNEL, 0, > + node == NUMA_NO_NODE ? numa_mem_id() : node); > if (!rqstp->rq_scratch_folio) > goto out_enomem; > > @@ -864,7 +707,15 @@ int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool) > int node; > int err = 0; > > - node = svc_pool_map_get_node(pool->sp_id); > + /* > + * Only pooled services hold a reference to the pool map, so only they > + * may consult it. Unpooled services (e.g. lockd, the NFS callback) > + * leave placement to the allocator. > + */ > + if (serv->sv_is_pooled) > + node = svc_pool_map_get_node(pool->sp_id); > + else > + node = NUMA_NO_NODE; > > rqstp = svc_prepare_thread(serv, pool, node); > if (!rqstp) > I think this patch is good, but there is probably room for further simplification which is probably best left to a later patch. In particular, ->sv_nrpools is now either '1' or svc_pool_map.count, and these possibilities match ->sv_is_pooled. So we only need one of those. I think removing ->sv_nrpools and only using ->sv_is_pooled would simplify/clarify some of the code. Reviewed-by: NeilBrown <neil@brown.name> Thanks, NeilBrown ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes 2026-07-01 22:31 ` NeilBrown @ 2026-07-02 12:46 ` Jeff Layton 2026-07-03 4:02 ` NeilBrown 0 siblings, 1 reply; 16+ messages in thread From: Jeff Layton @ 2026-07-02 12:46 UTC (permalink / raw) To: NeilBrown Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel On Thu, 2026-07-02 at 08:31 +1000, NeilBrown wrote: > On Thu, 02 Jul 2026, Jeff Layton wrote: > > The SVC_POOL_AUTO/GLOBAL/PERCPU/PERNODE pool mode selection machinery > > was added when NUMA was new and the right default was unclear. The > > default has always been "global" (a single pool for the whole service); > > the other modes were only used when an admin explicitly set the > > pool_mode parameter or asked for "auto", which then picked a mode from > > the host topology. Today, pernode is the right choice everywhere: > > > > - On multi-NUMA hosts, it gives one pool per node with proper thread > > affinity and NUMA-local memory allocation. > > - On single-node hosts, pernode degenerates to exactly one pool, > > identical to the old "global" mode -- svc_pool_for_cpu() short- > > circuits when sv_nrpools <= 1, no CPU affinity is set, and memory > > is allocated from the single node. > > > > The percpu mode (one pool per CPU) created excessive pools relative to > > the number of threads most deployments run, and was only auto-selected > > in a narrow case (single node, >2 CPUs). > > > > Note that this changes the default behaviour on multi-NUMA hosts: a > > service that previously ran with a single global pool now gets one pool > > per NUMA node by default. This in turn means a host running fewer > > threads than it has NUMA nodes can end up with pools that have no > > threads. svc_pool_for_cpu() already falls back to a populated pool in > > that case, so transports are still serviced. > > > > Remove the SVC_POOL_* enum, mode selection heuristic, > > svc_pool_map_init_percpu(), and all mode-based switch statements. > > Simplify pool map functions to always use the pernode path. If pool > > map allocation fails, svc_pool_map_get() now returns 0 and service > > creation fails, rather than silently falling back to a single global > > pool. > > > > With the mode check gone, svc_pool_map_get_node() would dereference the > > shared pool_to[] for every service that starts a thread. Only services > > created via svc_create_pooled() hold a map reference that keeps that > > array allocated, so gate the lookup in svc_new_thread() on sv_is_pooled: > > unpooled services (e.g. lockd, the NFS callback) use NUMA_NO_NODE and > > never consult the map. The kmalloc_node() callers in > > svc_prepare_thread() already accept NUMA_NO_NODE, but __folio_alloc_node() > > requires a valid node id, so resolve NUMA_NO_NODE to numa_mem_id() for > > the scratch folio allocation. > > > > The module parameter and netlink interfaces are preserved for backward > > compatibility: > > - Writing any of the four documented mode names still succeeds silently > > - Reading always returns "pernode" > > - Writing to the module parameter emits a deprecation notice > > > > Update Documentation/admin-guide/kernel-parameters.txt to mark the > > pool_mode parameter deprecated and describe the new behaviour. > > > > Assisted-by: Claude:claude-opus-4-8 > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > > --- > > Documentation/admin-guide/kernel-parameters.txt | 20 +- > > net/sunrpc/svc.c | 265 ++++++------------------ > > 2 files changed, 65 insertions(+), 220 deletions(-) > > > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > > index b5493a7f8f22..441b78867478 100644 > > --- a/Documentation/admin-guide/kernel-parameters.txt > > +++ b/Documentation/admin-guide/kernel-parameters.txt > > @@ -7441,19 +7441,13 @@ Kernel parameters > > > > sunrpc.pool_mode= > > [NFS] > > - Control how the NFS server code allocates CPUs to > > - service thread pools. Depending on how many NICs > > - you have and where their interrupts are bound, this > > - option will affect which CPUs will do NFS serving. > > - Note: this parameter cannot be changed while the > > - NFS server is running. > > - > > - auto the server chooses an appropriate mode > > - automatically using heuristics > > - global a single global pool contains all CPUs > > - percpu one pool for each CPU > > - pernode one pool for each NUMA node (equivalent > > - to global on non-NUMA machines) > > + Deprecated. The NFS server now always uses one > > + service thread pool per NUMA node (equivalent to a > > + single global pool on non-NUMA machines). All of > > + the previously accepted values (auto, global, > > + percpu, pernode) are still accepted for backward > > + compatibility but are ignored: the mode is always > > + pernode, and reads always return "pernode". > > > > sunrpc.tcp_slot_table_entries= > > sunrpc.udp_slot_table_entries= > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > index 82fb7faf563f..c9fba7edaace 100644 > > --- a/net/sunrpc/svc.c > > +++ b/net/sunrpc/svc.c > > @@ -38,82 +38,36 @@ > > > > static void svc_unregister(const struct svc_serv *serv, struct net *net); > > > > -#define SVC_POOL_DEFAULT SVC_POOL_GLOBAL > > - > > /* > > - * Mode for mapping cpus to pools. > > - */ > > -enum { > > - SVC_POOL_AUTO = -1, /* choose one of the others */ > > - SVC_POOL_GLOBAL, /* no mapping, just a single global pool > > - * (legacy & UP mode) */ > > - SVC_POOL_PERCPU, /* one pool per cpu */ > > - SVC_POOL_PERNODE /* one pool per numa node */ > > -}; > > - > > -/* > > - * Structure for mapping cpus to pools and vice versa. > > + * Structure for mapping nodes to pools and vice versa. > > * Setup once during sunrpc initialisation. > > */ > > > > struct svc_pool_map { > > int count; /* How many svc_servs use us */ > > - int mode; /* Note: int not enum to avoid > > - * warnings about "enumeration value > > - * not handled in switch" */ > > unsigned int npools; > > - unsigned int *pool_to; /* maps pool id to cpu or node */ > > - unsigned int *to_pool; /* maps cpu or node to pool id */ > > + unsigned int *pool_to; /* maps pool id to node */ > > + unsigned int *to_pool; /* maps node to pool id */ > > }; > > > > -static struct svc_pool_map svc_pool_map = { > > - .mode = SVC_POOL_DEFAULT > > -}; > > +static struct svc_pool_map svc_pool_map; > > > > static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */ > > > > -static int > > -__param_set_pool_mode(const char *val, struct svc_pool_map *m) > > -{ > > - int err, mode; > > - > > - mutex_lock(&svc_pool_map_mutex); > > - > > - err = 0; > > - if (!strncmp(val, "auto", 4)) > > - mode = SVC_POOL_AUTO; > > - else if (!strncmp(val, "global", 6)) > > - mode = SVC_POOL_GLOBAL; > > - else if (!strncmp(val, "percpu", 6)) > > - mode = SVC_POOL_PERCPU; > > - else if (!strncmp(val, "pernode", 7)) > > - mode = SVC_POOL_PERNODE; > > - else > > - err = -EINVAL; > > - > > - if (err) > > - goto out; > > - > > - if (m->count == 0) > > - m->mode = mode; > > - else if (mode != m->mode) > > - err = -EBUSY; > > -out: > > - mutex_unlock(&svc_pool_map_mutex); > > - return err; > > -} > > - > > -static int > > -param_set_pool_mode(const char *val, const struct kernel_param *kp) > > -{ > > - struct svc_pool_map *m = kp->arg; > > - > > - return __param_set_pool_mode(val, m); > > -} > > +/* > > + * Pool modes that were historically accepted. They no longer select > > + * anything: the pool mode is always pernode. The names are retained > > + * only so that writing a previously-valid value still succeeds. > > + */ > > +static const char * const pool_mode_names[] = { > > + "auto", "global", "percpu", "pernode", > > +}; > > > > int sunrpc_set_pool_mode(const char *val) > > { > > - return __param_set_pool_mode(val, &svc_pool_map); > > + int idx = sysfs_match_string(pool_mode_names, val); > > + > > + return idx < 0 ? idx : 0; > > } > > EXPORT_SYMBOL(sunrpc_set_pool_mode); > > > > @@ -122,84 +76,32 @@ EXPORT_SYMBOL(sunrpc_set_pool_mode); > > * @buf: where to write the current pool_mode > > * @size: size of @buf > > * > > - * Grab the current pool_mode from the svc_pool_map and write > > - * the resulting string to @buf. Returns the number of characters > > + * Write the pool_mode string to @buf. Returns the number of characters > > * written to @buf (a'la snprintf()). > > */ > > int > > sunrpc_get_pool_mode(char *buf, size_t size) > > { > > - struct svc_pool_map *m = &svc_pool_map; > > - > > - switch (m->mode) > > - { > > - case SVC_POOL_AUTO: > > - return snprintf(buf, size, "auto"); > > - case SVC_POOL_GLOBAL: > > - return snprintf(buf, size, "global"); > > - case SVC_POOL_PERCPU: > > - return snprintf(buf, size, "percpu"); > > - case SVC_POOL_PERNODE: > > - return snprintf(buf, size, "pernode"); > > - default: > > - return snprintf(buf, size, "%d", m->mode); > > - } > > + return snprintf(buf, size, "pernode"); > > } > > EXPORT_SYMBOL(sunrpc_get_pool_mode); > > > > static int > > -param_get_pool_mode(char *buf, const struct kernel_param *kp) > > +param_set_pool_mode(const char *val, const struct kernel_param *kp) > > { > > - char str[16]; > > - int len; > > - > > - len = sunrpc_get_pool_mode(str, ARRAY_SIZE(str)); > > - > > - /* Ensure we have room for newline and NUL */ > > - len = min_t(int, len, ARRAY_SIZE(str) - 2); > > - > > - /* tack on the newline */ > > - str[len] = '\n'; > > - str[len + 1] = '\0'; > > - > > - return sysfs_emit(buf, "%s", str); > > + pr_notice_once("sunrpc: the pool_mode module parameter is deprecated and no longer has any effect; the pool mode is always 'pernode'\n"); > > + return sunrpc_set_pool_mode(val); > > } > > > > -module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, > > - &svc_pool_map, 0644); > > - > > -/* > > - * Detect best pool mapping mode heuristically, > > - * according to the machine's topology. > > - */ > > static int > > -svc_pool_map_choose_mode(void) > > +param_get_pool_mode(char *buf, const struct kernel_param *kp) > > { > > - unsigned int node; > > - > > - if (nr_online_nodes > 1) { > > - /* > > - * Actually have multiple NUMA nodes, > > - * so split pools on NUMA node boundaries > > - */ > > - return SVC_POOL_PERNODE; > > - } > > - > > - node = first_online_node; > > - if (nr_cpus_node(node) > 2) { > > - /* > > - * Non-trivial SMP, or CONFIG_NUMA on > > - * non-NUMA hardware, e.g. with a generic > > - * x86_64 kernel on Xeons. In this case we > > - * want to divide the pools on cpu boundaries. > > - */ > > - return SVC_POOL_PERCPU; > > - } > > - > > - /* default: one global pool */ > > - return SVC_POOL_GLOBAL; > > + return sysfs_emit(buf, "pernode\n"); > > } > > > > +module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, > > + NULL, 0644); > > + > > /* > > * Allocate the to_pool[] and pool_to[] arrays. > > * Returns 0 on success or an errno. > > @@ -224,35 +126,7 @@ svc_pool_map_alloc_arrays(struct svc_pool_map *m, unsigned int maxpools) > > } > > > > /* > > - * Initialise the pool map for SVC_POOL_PERCPU mode. > > - * Returns number of pools or <0 on error. > > - */ > > -static int > > -svc_pool_map_init_percpu(struct svc_pool_map *m) > > -{ > > - unsigned int maxpools = nr_cpu_ids; > > - unsigned int pidx = 0; > > - unsigned int cpu; > > - int err; > > - > > - err = svc_pool_map_alloc_arrays(m, maxpools); > > - if (err) > > - return err; > > - > > - for_each_online_cpu(cpu) { > > - BUG_ON(pidx >= maxpools); > > - m->to_pool[cpu] = pidx; > > - m->pool_to[pidx] = cpu; > > - pidx++; > > - } > > - /* cpus brought online later all get mapped to pool0, sorry */ > > - > > - return pidx; > > -}; > > - > > - > > -/* > > - * Initialise the pool map for SVC_POOL_PERNODE mode. > > + * Initialise the pool map for one pool per NUMA node. > > * Returns number of pools or <0 on error. > > */ > > static int > > @@ -281,17 +155,16 @@ svc_pool_map_init_pernode(struct svc_pool_map *m) > > > > > > /* > > - * Add a reference to the global map of cpus to pools (and > > + * Add a reference to the global map of nodes to pools (and > > * vice versa) if pools are in use. > > * Initialise the map if we're the first user. > > - * Returns the number of pools. If this is '1', no reference > > - * was taken. > > + * Returns the number of pools, or 0 on failure. > > */ > > static unsigned int > > svc_pool_map_get(void) > > { > > struct svc_pool_map *m = &svc_pool_map; > > - int npools = -1; > > + int npools; > > > > mutex_lock(&svc_pool_map_mutex); > > if (m->count++) { > > @@ -299,22 +172,11 @@ svc_pool_map_get(void) > > return m->npools; > > } > > > > - if (m->mode == SVC_POOL_AUTO) > > - m->mode = svc_pool_map_choose_mode(); > > - > > - switch (m->mode) { > > - case SVC_POOL_PERCPU: > > - npools = svc_pool_map_init_percpu(m); > > - break; > > - case SVC_POOL_PERNODE: > > - npools = svc_pool_map_init_pernode(m); > > - break; > > - } > > - > > + npools = svc_pool_map_init_pernode(m); > > if (npools <= 0) { > > - /* default, or memory allocation failure */ > > - npools = 1; > > - m->mode = SVC_POOL_GLOBAL; > > + m->count = 0; > > + mutex_unlock(&svc_pool_map_mutex); > > + return 0; > > } > > m->npools = npools; > > mutex_unlock(&svc_pool_map_mutex); > > @@ -322,7 +184,7 @@ svc_pool_map_get(void) > > } > > > > /* > > - * Drop a reference to the global map of cpus to pools. > > + * Drop a reference to the global map of nodes to pools. > > * When the last reference is dropped, the map data is > > * freed; this allows the sysadmin to change the pool. > > */ > > @@ -346,14 +208,11 @@ static int svc_pool_map_get_node(unsigned int pidx) > > { > > const struct svc_pool_map *m = &svc_pool_map; > > > > - if (m->count) { > > - if (m->mode == SVC_POOL_PERCPU) > > - return cpu_to_node(m->pool_to[pidx]); > > - if (m->mode == SVC_POOL_PERNODE) > > - return m->pool_to[pidx]; > > - } > > + if (m->count) > > + return m->pool_to[pidx]; > > return numa_mem_id(); > > } > > + > > /* > > * Set the given thread's cpus_allowed mask so that it > > * will only run on cpus in the given pool. > > @@ -372,27 +231,15 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) > > if (m->count == 0) > > return; > > > > - switch (m->mode) { > > - case SVC_POOL_PERCPU: > > - { > > - set_cpus_allowed_ptr(task, cpumask_of(node)); > > - break; > > - } > > - case SVC_POOL_PERNODE: > > - { > > - set_cpus_allowed_ptr(task, cpumask_of_node(node)); > > - break; > > - } > > - } > > + set_cpus_allowed_ptr(task, cpumask_of_node(node)); > > } > > > > /** > > * svc_pool_for_cpu - Select pool to run a thread on this cpu > > * @serv: An RPC service > > * > > - * Use the active CPU and the svc_pool_map's mode setting to > > - * select the svc thread pool to use. Once initialized, the > > - * svc_pool_map does not change. > > + * Use the active CPU and the svc_pool_map to select the svc thread > > + * pool to use. Once initialized, the svc_pool_map does not change. > > * > > * Return value: > > * A pointer to an svc_pool > > @@ -400,22 +247,12 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) > > 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; > > + unsigned int pidx, i; > > > > if (serv->sv_nrpools <= 1) > > return serv->sv_pools; > > > > - switch (m->mode) { > > - case SVC_POOL_PERCPU: > > - pidx = m->to_pool[cpu]; > > - break; > > - case SVC_POOL_PERNODE: > > - pidx = m->to_pool[cpu_to_node(cpu)]; > > - break; > > - } > > - pidx %= serv->sv_nrpools; > > + pidx = m->to_pool[cpu_to_node(raw_smp_processor_id())] % serv->sv_nrpools; > > > > /* > > * Threads are spread evenly across the pools, but when there are > > @@ -641,6 +478,9 @@ struct svc_serv *svc_create_pooled(struct svc_program *prog, > > struct svc_serv *serv; > > unsigned int npools = svc_pool_map_get(); > > > > + if (!npools) > > + return NULL; > > + > > serv = __svc_create(prog, nprogs, stats, bufsize, npools, threadfn); > > if (!serv) > > goto out_err; > > @@ -775,7 +615,10 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node) > > rqstp->rq_server = serv; > > rqstp->rq_pool = pool; > > > > - rqstp->rq_scratch_folio = __folio_alloc_node(GFP_KERNEL, 0, node); > > + /* __folio_alloc_node() rejects NUMA_NO_NODE; let it pick for us */ > > + rqstp->rq_scratch_folio = > > + __folio_alloc_node(GFP_KERNEL, 0, > > + node == NUMA_NO_NODE ? numa_mem_id() : node); > > if (!rqstp->rq_scratch_folio) > > goto out_enomem; > > > > @@ -864,7 +707,15 @@ int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool) > > int node; > > int err = 0; > > > > - node = svc_pool_map_get_node(pool->sp_id); > > + /* > > + * Only pooled services hold a reference to the pool map, so only they > > + * may consult it. Unpooled services (e.g. lockd, the NFS callback) > > + * leave placement to the allocator. > > + */ > > + if (serv->sv_is_pooled) > > + node = svc_pool_map_get_node(pool->sp_id); > > + else > > + node = NUMA_NO_NODE; > > > > rqstp = svc_prepare_thread(serv, pool, node); > > if (!rqstp) > > > > I think this patch is good, but there is probably room for further > simplification which is probably best left to a later patch. > In particular, ->sv_nrpools is now either '1' or svc_pool_map.count, > and these possibilities match ->sv_is_pooled. So we only need one of > those. > I think removing ->sv_nrpools and only using ->sv_is_pooled would > simplify/clarify some of the code. > > Reviewed-by: NeilBrown <neil@brown.name> Thanks. I took a look at that cleanup, but it's not quite the same. - unpooled service (lockd, NFS callback): sv_is_pooled=false, sv_nrpools=1 - pooled service on a single-node host: sv_is_pooled=true, sv_nrpools=1 (pernode degenerates to one pool) - pooled service on multi-node: sv_is_pooled=true, sv_nrpools=N>1 So you can't derive sv_is_pooled from sv_nrpools because of the single-node case. Worse, it also means that we'd have to create more accessors for the svc_pool_map. There are several places that access sv_nrpools that would have to be converted to get it from the map. That may have performance implications too since the map is accessed during receives. So this kind of cleanup is doable, but it's a bit messier than it sounds at first. -- Jeff Layton <jlayton@kernel.org> ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes 2026-07-02 12:46 ` Jeff Layton @ 2026-07-03 4:02 ` NeilBrown 0 siblings, 0 replies; 16+ messages in thread From: NeilBrown @ 2026-07-03 4:02 UTC (permalink / raw) To: Jeff Layton Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel On Thu, 02 Jul 2026, Jeff Layton wrote: > On Thu, 2026-07-02 at 08:31 +1000, NeilBrown wrote: > > On Thu, 02 Jul 2026, Jeff Layton wrote: > > > The SVC_POOL_AUTO/GLOBAL/PERCPU/PERNODE pool mode selection machinery > > > was added when NUMA was new and the right default was unclear. The > > > default has always been "global" (a single pool for the whole service); > > > the other modes were only used when an admin explicitly set the > > > pool_mode parameter or asked for "auto", which then picked a mode from > > > the host topology. Today, pernode is the right choice everywhere: > > > > > > - On multi-NUMA hosts, it gives one pool per node with proper thread > > > affinity and NUMA-local memory allocation. > > > - On single-node hosts, pernode degenerates to exactly one pool, > > > identical to the old "global" mode -- svc_pool_for_cpu() short- > > > circuits when sv_nrpools <= 1, no CPU affinity is set, and memory > > > is allocated from the single node. > > > > > > The percpu mode (one pool per CPU) created excessive pools relative to > > > the number of threads most deployments run, and was only auto-selected > > > in a narrow case (single node, >2 CPUs). > > > > > > Note that this changes the default behaviour on multi-NUMA hosts: a > > > service that previously ran with a single global pool now gets one pool > > > per NUMA node by default. This in turn means a host running fewer > > > threads than it has NUMA nodes can end up with pools that have no > > > threads. svc_pool_for_cpu() already falls back to a populated pool in > > > that case, so transports are still serviced. > > > > > > Remove the SVC_POOL_* enum, mode selection heuristic, > > > svc_pool_map_init_percpu(), and all mode-based switch statements. > > > Simplify pool map functions to always use the pernode path. If pool > > > map allocation fails, svc_pool_map_get() now returns 0 and service > > > creation fails, rather than silently falling back to a single global > > > pool. > > > > > > With the mode check gone, svc_pool_map_get_node() would dereference the > > > shared pool_to[] for every service that starts a thread. Only services > > > created via svc_create_pooled() hold a map reference that keeps that > > > array allocated, so gate the lookup in svc_new_thread() on sv_is_pooled: > > > unpooled services (e.g. lockd, the NFS callback) use NUMA_NO_NODE and > > > never consult the map. The kmalloc_node() callers in > > > svc_prepare_thread() already accept NUMA_NO_NODE, but __folio_alloc_node() > > > requires a valid node id, so resolve NUMA_NO_NODE to numa_mem_id() for > > > the scratch folio allocation. > > > > > > The module parameter and netlink interfaces are preserved for backward > > > compatibility: > > > - Writing any of the four documented mode names still succeeds silently > > > - Reading always returns "pernode" > > > - Writing to the module parameter emits a deprecation notice > > > > > > Update Documentation/admin-guide/kernel-parameters.txt to mark the > > > pool_mode parameter deprecated and describe the new behaviour. > > > > > > Assisted-by: Claude:claude-opus-4-8 > > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > > > --- > > > Documentation/admin-guide/kernel-parameters.txt | 20 +- > > > net/sunrpc/svc.c | 265 ++++++------------------ > > > 2 files changed, 65 insertions(+), 220 deletions(-) > > > > > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > > > index b5493a7f8f22..441b78867478 100644 > > > --- a/Documentation/admin-guide/kernel-parameters.txt > > > +++ b/Documentation/admin-guide/kernel-parameters.txt > > > @@ -7441,19 +7441,13 @@ Kernel parameters > > > > > > sunrpc.pool_mode= > > > [NFS] > > > - Control how the NFS server code allocates CPUs to > > > - service thread pools. Depending on how many NICs > > > - you have and where their interrupts are bound, this > > > - option will affect which CPUs will do NFS serving. > > > - Note: this parameter cannot be changed while the > > > - NFS server is running. > > > - > > > - auto the server chooses an appropriate mode > > > - automatically using heuristics > > > - global a single global pool contains all CPUs > > > - percpu one pool for each CPU > > > - pernode one pool for each NUMA node (equivalent > > > - to global on non-NUMA machines) > > > + Deprecated. The NFS server now always uses one > > > + service thread pool per NUMA node (equivalent to a > > > + single global pool on non-NUMA machines). All of > > > + the previously accepted values (auto, global, > > > + percpu, pernode) are still accepted for backward > > > + compatibility but are ignored: the mode is always > > > + pernode, and reads always return "pernode". > > > > > > sunrpc.tcp_slot_table_entries= > > > sunrpc.udp_slot_table_entries= > > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > > index 82fb7faf563f..c9fba7edaace 100644 > > > --- a/net/sunrpc/svc.c > > > +++ b/net/sunrpc/svc.c > > > @@ -38,82 +38,36 @@ > > > > > > static void svc_unregister(const struct svc_serv *serv, struct net *net); > > > > > > -#define SVC_POOL_DEFAULT SVC_POOL_GLOBAL > > > - > > > /* > > > - * Mode for mapping cpus to pools. > > > - */ > > > -enum { > > > - SVC_POOL_AUTO = -1, /* choose one of the others */ > > > - SVC_POOL_GLOBAL, /* no mapping, just a single global pool > > > - * (legacy & UP mode) */ > > > - SVC_POOL_PERCPU, /* one pool per cpu */ > > > - SVC_POOL_PERNODE /* one pool per numa node */ > > > -}; > > > - > > > -/* > > > - * Structure for mapping cpus to pools and vice versa. > > > + * Structure for mapping nodes to pools and vice versa. > > > * Setup once during sunrpc initialisation. > > > */ > > > > > > struct svc_pool_map { > > > int count; /* How many svc_servs use us */ > > > - int mode; /* Note: int not enum to avoid > > > - * warnings about "enumeration value > > > - * not handled in switch" */ > > > unsigned int npools; > > > - unsigned int *pool_to; /* maps pool id to cpu or node */ > > > - unsigned int *to_pool; /* maps cpu or node to pool id */ > > > + unsigned int *pool_to; /* maps pool id to node */ > > > + unsigned int *to_pool; /* maps node to pool id */ > > > }; > > > > > > -static struct svc_pool_map svc_pool_map = { > > > - .mode = SVC_POOL_DEFAULT > > > -}; > > > +static struct svc_pool_map svc_pool_map; > > > > > > static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */ > > > > > > -static int > > > -__param_set_pool_mode(const char *val, struct svc_pool_map *m) > > > -{ > > > - int err, mode; > > > - > > > - mutex_lock(&svc_pool_map_mutex); > > > - > > > - err = 0; > > > - if (!strncmp(val, "auto", 4)) > > > - mode = SVC_POOL_AUTO; > > > - else if (!strncmp(val, "global", 6)) > > > - mode = SVC_POOL_GLOBAL; > > > - else if (!strncmp(val, "percpu", 6)) > > > - mode = SVC_POOL_PERCPU; > > > - else if (!strncmp(val, "pernode", 7)) > > > - mode = SVC_POOL_PERNODE; > > > - else > > > - err = -EINVAL; > > > - > > > - if (err) > > > - goto out; > > > - > > > - if (m->count == 0) > > > - m->mode = mode; > > > - else if (mode != m->mode) > > > - err = -EBUSY; > > > -out: > > > - mutex_unlock(&svc_pool_map_mutex); > > > - return err; > > > -} > > > - > > > -static int > > > -param_set_pool_mode(const char *val, const struct kernel_param *kp) > > > -{ > > > - struct svc_pool_map *m = kp->arg; > > > - > > > - return __param_set_pool_mode(val, m); > > > -} > > > +/* > > > + * Pool modes that were historically accepted. They no longer select > > > + * anything: the pool mode is always pernode. The names are retained > > > + * only so that writing a previously-valid value still succeeds. > > > + */ > > > +static const char * const pool_mode_names[] = { > > > + "auto", "global", "percpu", "pernode", > > > +}; > > > > > > int sunrpc_set_pool_mode(const char *val) > > > { > > > - return __param_set_pool_mode(val, &svc_pool_map); > > > + int idx = sysfs_match_string(pool_mode_names, val); > > > + > > > + return idx < 0 ? idx : 0; > > > } > > > EXPORT_SYMBOL(sunrpc_set_pool_mode); > > > > > > @@ -122,84 +76,32 @@ EXPORT_SYMBOL(sunrpc_set_pool_mode); > > > * @buf: where to write the current pool_mode > > > * @size: size of @buf > > > * > > > - * Grab the current pool_mode from the svc_pool_map and write > > > - * the resulting string to @buf. Returns the number of characters > > > + * Write the pool_mode string to @buf. Returns the number of characters > > > * written to @buf (a'la snprintf()). > > > */ > > > int > > > sunrpc_get_pool_mode(char *buf, size_t size) > > > { > > > - struct svc_pool_map *m = &svc_pool_map; > > > - > > > - switch (m->mode) > > > - { > > > - case SVC_POOL_AUTO: > > > - return snprintf(buf, size, "auto"); > > > - case SVC_POOL_GLOBAL: > > > - return snprintf(buf, size, "global"); > > > - case SVC_POOL_PERCPU: > > > - return snprintf(buf, size, "percpu"); > > > - case SVC_POOL_PERNODE: > > > - return snprintf(buf, size, "pernode"); > > > - default: > > > - return snprintf(buf, size, "%d", m->mode); > > > - } > > > + return snprintf(buf, size, "pernode"); > > > } > > > EXPORT_SYMBOL(sunrpc_get_pool_mode); > > > > > > static int > > > -param_get_pool_mode(char *buf, const struct kernel_param *kp) > > > +param_set_pool_mode(const char *val, const struct kernel_param *kp) > > > { > > > - char str[16]; > > > - int len; > > > - > > > - len = sunrpc_get_pool_mode(str, ARRAY_SIZE(str)); > > > - > > > - /* Ensure we have room for newline and NUL */ > > > - len = min_t(int, len, ARRAY_SIZE(str) - 2); > > > - > > > - /* tack on the newline */ > > > - str[len] = '\n'; > > > - str[len + 1] = '\0'; > > > - > > > - return sysfs_emit(buf, "%s", str); > > > + pr_notice_once("sunrpc: the pool_mode module parameter is deprecated and no longer has any effect; the pool mode is always 'pernode'\n"); > > > + return sunrpc_set_pool_mode(val); > > > } > > > > > > -module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, > > > - &svc_pool_map, 0644); > > > - > > > -/* > > > - * Detect best pool mapping mode heuristically, > > > - * according to the machine's topology. > > > - */ > > > static int > > > -svc_pool_map_choose_mode(void) > > > +param_get_pool_mode(char *buf, const struct kernel_param *kp) > > > { > > > - unsigned int node; > > > - > > > - if (nr_online_nodes > 1) { > > > - /* > > > - * Actually have multiple NUMA nodes, > > > - * so split pools on NUMA node boundaries > > > - */ > > > - return SVC_POOL_PERNODE; > > > - } > > > - > > > - node = first_online_node; > > > - if (nr_cpus_node(node) > 2) { > > > - /* > > > - * Non-trivial SMP, or CONFIG_NUMA on > > > - * non-NUMA hardware, e.g. with a generic > > > - * x86_64 kernel on Xeons. In this case we > > > - * want to divide the pools on cpu boundaries. > > > - */ > > > - return SVC_POOL_PERCPU; > > > - } > > > - > > > - /* default: one global pool */ > > > - return SVC_POOL_GLOBAL; > > > + return sysfs_emit(buf, "pernode\n"); > > > } > > > > > > +module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode, > > > + NULL, 0644); > > > + > > > /* > > > * Allocate the to_pool[] and pool_to[] arrays. > > > * Returns 0 on success or an errno. > > > @@ -224,35 +126,7 @@ svc_pool_map_alloc_arrays(struct svc_pool_map *m, unsigned int maxpools) > > > } > > > > > > /* > > > - * Initialise the pool map for SVC_POOL_PERCPU mode. > > > - * Returns number of pools or <0 on error. > > > - */ > > > -static int > > > -svc_pool_map_init_percpu(struct svc_pool_map *m) > > > -{ > > > - unsigned int maxpools = nr_cpu_ids; > > > - unsigned int pidx = 0; > > > - unsigned int cpu; > > > - int err; > > > - > > > - err = svc_pool_map_alloc_arrays(m, maxpools); > > > - if (err) > > > - return err; > > > - > > > - for_each_online_cpu(cpu) { > > > - BUG_ON(pidx >= maxpools); > > > - m->to_pool[cpu] = pidx; > > > - m->pool_to[pidx] = cpu; > > > - pidx++; > > > - } > > > - /* cpus brought online later all get mapped to pool0, sorry */ > > > - > > > - return pidx; > > > -}; > > > - > > > - > > > -/* > > > - * Initialise the pool map for SVC_POOL_PERNODE mode. > > > + * Initialise the pool map for one pool per NUMA node. > > > * Returns number of pools or <0 on error. > > > */ > > > static int > > > @@ -281,17 +155,16 @@ svc_pool_map_init_pernode(struct svc_pool_map *m) > > > > > > > > > /* > > > - * Add a reference to the global map of cpus to pools (and > > > + * Add a reference to the global map of nodes to pools (and > > > * vice versa) if pools are in use. > > > * Initialise the map if we're the first user. > > > - * Returns the number of pools. If this is '1', no reference > > > - * was taken. > > > + * Returns the number of pools, or 0 on failure. > > > */ > > > static unsigned int > > > svc_pool_map_get(void) > > > { > > > struct svc_pool_map *m = &svc_pool_map; > > > - int npools = -1; > > > + int npools; > > > > > > mutex_lock(&svc_pool_map_mutex); > > > if (m->count++) { > > > @@ -299,22 +172,11 @@ svc_pool_map_get(void) > > > return m->npools; > > > } > > > > > > - if (m->mode == SVC_POOL_AUTO) > > > - m->mode = svc_pool_map_choose_mode(); > > > - > > > - switch (m->mode) { > > > - case SVC_POOL_PERCPU: > > > - npools = svc_pool_map_init_percpu(m); > > > - break; > > > - case SVC_POOL_PERNODE: > > > - npools = svc_pool_map_init_pernode(m); > > > - break; > > > - } > > > - > > > + npools = svc_pool_map_init_pernode(m); > > > if (npools <= 0) { > > > - /* default, or memory allocation failure */ > > > - npools = 1; > > > - m->mode = SVC_POOL_GLOBAL; > > > + m->count = 0; > > > + mutex_unlock(&svc_pool_map_mutex); > > > + return 0; > > > } > > > m->npools = npools; > > > mutex_unlock(&svc_pool_map_mutex); > > > @@ -322,7 +184,7 @@ svc_pool_map_get(void) > > > } > > > > > > /* > > > - * Drop a reference to the global map of cpus to pools. > > > + * Drop a reference to the global map of nodes to pools. > > > * When the last reference is dropped, the map data is > > > * freed; this allows the sysadmin to change the pool. > > > */ > > > @@ -346,14 +208,11 @@ static int svc_pool_map_get_node(unsigned int pidx) > > > { > > > const struct svc_pool_map *m = &svc_pool_map; > > > > > > - if (m->count) { > > > - if (m->mode == SVC_POOL_PERCPU) > > > - return cpu_to_node(m->pool_to[pidx]); > > > - if (m->mode == SVC_POOL_PERNODE) > > > - return m->pool_to[pidx]; > > > - } > > > + if (m->count) > > > + return m->pool_to[pidx]; > > > return numa_mem_id(); > > > } > > > + > > > /* > > > * Set the given thread's cpus_allowed mask so that it > > > * will only run on cpus in the given pool. > > > @@ -372,27 +231,15 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) > > > if (m->count == 0) > > > return; > > > > > > - switch (m->mode) { > > > - case SVC_POOL_PERCPU: > > > - { > > > - set_cpus_allowed_ptr(task, cpumask_of(node)); > > > - break; > > > - } > > > - case SVC_POOL_PERNODE: > > > - { > > > - set_cpus_allowed_ptr(task, cpumask_of_node(node)); > > > - break; > > > - } > > > - } > > > + set_cpus_allowed_ptr(task, cpumask_of_node(node)); > > > } > > > > > > /** > > > * svc_pool_for_cpu - Select pool to run a thread on this cpu > > > * @serv: An RPC service > > > * > > > - * Use the active CPU and the svc_pool_map's mode setting to > > > - * select the svc thread pool to use. Once initialized, the > > > - * svc_pool_map does not change. > > > + * Use the active CPU and the svc_pool_map to select the svc thread > > > + * pool to use. Once initialized, the svc_pool_map does not change. > > > * > > > * Return value: > > > * A pointer to an svc_pool > > > @@ -400,22 +247,12 @@ svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx) > > > 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; > > > + unsigned int pidx, i; > > > > > > if (serv->sv_nrpools <= 1) > > > return serv->sv_pools; > > > > > > - switch (m->mode) { > > > - case SVC_POOL_PERCPU: > > > - pidx = m->to_pool[cpu]; > > > - break; > > > - case SVC_POOL_PERNODE: > > > - pidx = m->to_pool[cpu_to_node(cpu)]; > > > - break; > > > - } > > > - pidx %= serv->sv_nrpools; > > > + pidx = m->to_pool[cpu_to_node(raw_smp_processor_id())] % serv->sv_nrpools; > > > > > > /* > > > * Threads are spread evenly across the pools, but when there are > > > @@ -641,6 +478,9 @@ struct svc_serv *svc_create_pooled(struct svc_program *prog, > > > struct svc_serv *serv; > > > unsigned int npools = svc_pool_map_get(); > > > > > > + if (!npools) > > > + return NULL; > > > + > > > serv = __svc_create(prog, nprogs, stats, bufsize, npools, threadfn); > > > if (!serv) > > > goto out_err; > > > @@ -775,7 +615,10 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node) > > > rqstp->rq_server = serv; > > > rqstp->rq_pool = pool; > > > > > > - rqstp->rq_scratch_folio = __folio_alloc_node(GFP_KERNEL, 0, node); > > > + /* __folio_alloc_node() rejects NUMA_NO_NODE; let it pick for us */ > > > + rqstp->rq_scratch_folio = > > > + __folio_alloc_node(GFP_KERNEL, 0, > > > + node == NUMA_NO_NODE ? numa_mem_id() : node); > > > if (!rqstp->rq_scratch_folio) > > > goto out_enomem; > > > > > > @@ -864,7 +707,15 @@ int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool) > > > int node; > > > int err = 0; > > > > > > - node = svc_pool_map_get_node(pool->sp_id); > > > + /* > > > + * Only pooled services hold a reference to the pool map, so only they > > > + * may consult it. Unpooled services (e.g. lockd, the NFS callback) > > > + * leave placement to the allocator. > > > + */ > > > + if (serv->sv_is_pooled) > > > + node = svc_pool_map_get_node(pool->sp_id); > > > + else > > > + node = NUMA_NO_NODE; > > > > > > rqstp = svc_prepare_thread(serv, pool, node); > > > if (!rqstp) > > > > > > > I think this patch is good, but there is probably room for further > > simplification which is probably best left to a later patch. > > In particular, ->sv_nrpools is now either '1' or svc_pool_map.count, > > and these possibilities match ->sv_is_pooled. So we only need one of > > those. > > I think removing ->sv_nrpools and only using ->sv_is_pooled would > > simplify/clarify some of the code. > > > > Reviewed-by: NeilBrown <neil@brown.name> > > Thanks. I took a look at that cleanup, but it's not quite the same. > > - unpooled service (lockd, NFS callback): sv_is_pooled=false, sv_nrpools=1 > - pooled service on a single-node host: sv_is_pooled=true, sv_nrpools=1 (pernode degenerates to one pool) > - pooled service on multi-node: sv_is_pooled=true, sv_nrpools=N>1 > > So you can't derive sv_is_pooled from sv_nrpools because of the > single-node case. Agree. We have to keep sv_is_pooled (it implies a reference to svc_pool_map). I'm not convinced that we need sv_nrpools. > > Worse, it also means that we'd have to create more accessors for the > svc_pool_map. There are several places that access sv_nrpools that > would have to be converted to get it from the map. That may have > performance implications too since the map is accessed during receives. svc_pool_map is a single global that is read-mostly, so no dereference, easy to predict. During receive we need to access svc_pool_map anyway to map CPU to POOL. So the svc_pool_map.npools will have to be pulled into cache anyway. But if you don't like it, I won't push it on you. Thanks, NeilBrown > > So this kind of cleanup is doable, but it's a bit messier than it > sounds at first. > -- > Jeff Layton <jlayton@kernel.org> > ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v4 3/4] sunrpc: guarantee a thread per CPU-bearing node when auto-distributing 2026-07-01 19:56 [PATCH v4 0/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton 2026-07-01 19:56 ` [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() Jeff Layton 2026-07-01 19:56 ` [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton @ 2026-07-01 19:56 ` Jeff Layton 2026-07-01 22:37 ` NeilBrown 2026-07-01 19:56 ` [PATCH v4 4/4] sunrpc: eliminate a modulus operation from the enqueueing codepath Jeff Layton 3 siblings, 1 reply; 16+ messages in thread From: Jeff Layton @ 2026-07-01 19:56 UTC (permalink / raw) To: Trond Myklebust, Anna Schumaker, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever Cc: linux-nfs, linux-kernel, Jeff Layton svc_set_num_threads() spreads the requested thread count evenly across the service's pools. In pernode mode each pool maps to a NUMA node, and svc_pool_for_cpu() steers an incoming transport to the pool for the node it arrived on. When fewer threads than pools are requested, even distribution leaves some nodes' pools empty, and a transport steered to an empty pool has no thread to service it. Floor each CPU-bearing node's pool at one thread when auto-distributing a non-zero count, so no such pool is left empty. The resulting total may exceed the requested count. This only affects the auto-distribute path (a single-value array, i.e. svc_set_num_threads()); callers that set per-pool counts explicitly via svc_set_pool_threads() are unchanged and may still set a pool to zero. Nodes without CPUs (e.g. memory-only nodes) get no thread, as nothing is steered to them. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jeff Layton <jlayton@kernel.org> --- net/sunrpc/svc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index c9fba7edaace..ae93a6f51087 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -837,6 +837,12 @@ EXPORT_SYMBOL_GPL(svc_set_pool_threads); * are multiple pools then the new threads or victims will be distributed * evenly among them. * + * When @nrservs is non-zero but smaller than the number of pools, even + * distribution would leave some pools empty. Since each pool maps to a + * NUMA node and only services transports steered to that node, every + * pool whose node has CPUs is instead guaranteed at least one thread. + * The resulting total may therefore exceed @nrservs. + * * Caller must ensure mutual exclusion between this and server startup or * shutdown. * @@ -861,6 +867,15 @@ svc_set_num_threads(struct svc_serv *serv, unsigned int min_threads, --remain; } + /* + * Don't let a node's pool sit empty while threads are + * being auto-distributed: a transport steered there would + * have nothing to service it. + */ + if (threads == 0 && nrservs && + nr_cpus_node(svc_pool_map_get_node(pool->sp_id))) + threads = 1; + err = svc_set_pool_threads(serv, pool, min_threads, threads); if (err) break; -- 2.54.0 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v4 3/4] sunrpc: guarantee a thread per CPU-bearing node when auto-distributing 2026-07-01 19:56 ` [PATCH v4 3/4] sunrpc: guarantee a thread per CPU-bearing node when auto-distributing Jeff Layton @ 2026-07-01 22:37 ` NeilBrown 2026-07-02 13:05 ` Jeff Layton 0 siblings, 1 reply; 16+ messages in thread From: NeilBrown @ 2026-07-01 22:37 UTC (permalink / raw) To: Jeff Layton Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel, Jeff Layton On Thu, 02 Jul 2026, Jeff Layton wrote: > svc_set_num_threads() spreads the requested thread count evenly across > the service's pools. In pernode mode each pool maps to a NUMA node, and > svc_pool_for_cpu() steers an incoming transport to the pool for the node > it arrived on. When fewer threads than pools are requested, even > distribution leaves some nodes' pools empty, and a transport steered to > an empty pool has no thread to service it. > > Floor each CPU-bearing node's pool at one thread when auto-distributing a > non-zero count, so no such pool is left empty. The resulting total may > exceed the requested count. This only affects the auto-distribute path > (a single-value array, i.e. svc_set_num_threads()); callers that set > per-pool counts explicitly via svc_set_pool_threads() are unchanged and > may still set a pool to zero. Nodes without CPUs (e.g. memory-only nodes) > get no thread, as nothing is steered to them. > > Assisted-by: Claude:claude-opus-4-8 > Signed-off-by: Jeff Layton <jlayton@kernel.org> > --- > net/sunrpc/svc.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > index c9fba7edaace..ae93a6f51087 100644 > --- a/net/sunrpc/svc.c > +++ b/net/sunrpc/svc.c > @@ -837,6 +837,12 @@ EXPORT_SYMBOL_GPL(svc_set_pool_threads); > * are multiple pools then the new threads or victims will be distributed > * evenly among them. > * > + * When @nrservs is non-zero but smaller than the number of pools, even > + * distribution would leave some pools empty. Since each pool maps to a > + * NUMA node and only services transports steered to that node, every > + * pool whose node has CPUs is instead guaranteed at least one thread. > + * The resulting total may therefore exceed @nrservs. > + * > * Caller must ensure mutual exclusion between this and server startup or > * shutdown. > * > @@ -861,6 +867,15 @@ svc_set_num_threads(struct svc_serv *serv, unsigned int min_threads, > --remain; > } > > + /* > + * Don't let a node's pool sit empty while threads are > + * being auto-distributed: a transport steered there would > + * have nothing to service it. > + */ > + if (threads == 0 && nrservs && > + nr_cpus_node(svc_pool_map_get_node(pool->sp_id))) svc_pool_map_init_pernode() uses for_each_node_with_cpus() so we can be certain that each node which has been allocated a pool will have at least 1 cpu. Thus that last condition isn't needed. I would probably address the problem outside the loop with if (base == 0 && nrservs != 0) /* We need at least one thread per pool for correct functionality */ remain = serv->sv_nrpools; or similar. But your version works too and this isn't performance-critical code. Reviewed-by: NeilBrown <neil@brown.name> Thanks, NeilBrown ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 3/4] sunrpc: guarantee a thread per CPU-bearing node when auto-distributing 2026-07-01 22:37 ` NeilBrown @ 2026-07-02 13:05 ` Jeff Layton 0 siblings, 0 replies; 16+ messages in thread From: Jeff Layton @ 2026-07-02 13:05 UTC (permalink / raw) To: NeilBrown Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel On Thu, 2026-07-02 at 08:37 +1000, NeilBrown wrote: > On Thu, 02 Jul 2026, Jeff Layton wrote: > > svc_set_num_threads() spreads the requested thread count evenly across > > the service's pools. In pernode mode each pool maps to a NUMA node, and > > svc_pool_for_cpu() steers an incoming transport to the pool for the node > > it arrived on. When fewer threads than pools are requested, even > > distribution leaves some nodes' pools empty, and a transport steered to > > an empty pool has no thread to service it. > > > > Floor each CPU-bearing node's pool at one thread when auto-distributing a > > non-zero count, so no such pool is left empty. The resulting total may > > exceed the requested count. This only affects the auto-distribute path > > (a single-value array, i.e. svc_set_num_threads()); callers that set > > per-pool counts explicitly via svc_set_pool_threads() are unchanged and > > may still set a pool to zero. Nodes without CPUs (e.g. memory-only nodes) > > get no thread, as nothing is steered to them. > > > > Assisted-by: Claude:claude-opus-4-8 > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > > --- > > net/sunrpc/svc.c | 15 +++++++++++++++ > > 1 file changed, 15 insertions(+) > > > > diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c > > index c9fba7edaace..ae93a6f51087 100644 > > --- a/net/sunrpc/svc.c > > +++ b/net/sunrpc/svc.c > > @@ -837,6 +837,12 @@ EXPORT_SYMBOL_GPL(svc_set_pool_threads); > > * are multiple pools then the new threads or victims will be distributed > > * evenly among them. > > * > > + * When @nrservs is non-zero but smaller than the number of pools, even > > + * distribution would leave some pools empty. Since each pool maps to a > > + * NUMA node and only services transports steered to that node, every > > + * pool whose node has CPUs is instead guaranteed at least one thread. > > + * The resulting total may therefore exceed @nrservs. > > + * > > * Caller must ensure mutual exclusion between this and server startup or > > * shutdown. > > * > > @@ -861,6 +867,15 @@ svc_set_num_threads(struct svc_serv *serv, unsigned int min_threads, > > --remain; > > } > > > > + /* > > + * Don't let a node's pool sit empty while threads are > > + * being auto-distributed: a transport steered there would > > + * have nothing to service it. > > + */ > > + if (threads == 0 && nrservs && > > + nr_cpus_node(svc_pool_map_get_node(pool->sp_id))) > > svc_pool_map_init_pernode() uses for_each_node_with_cpus() so we can be > certain that each node which has been allocated a pool will have at > least 1 cpu. Thus that last condition isn't needed. > > I would probably address the problem outside the loop with > > if (base == 0 && nrservs != 0) > /* We need at least one thread per pool for correct functionality */ > remain = serv->sv_nrpools; > > or similar. But your version works too and this isn't > performance-critical code. > > Reviewed-by: NeilBrown <neil@brown.name> > > I like your version better. I'll adopt it. Thanks! -- Jeff Layton <jlayton@kernel.org> ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v4 4/4] sunrpc: eliminate a modulus operation from the enqueueing codepath 2026-07-01 19:56 [PATCH v4 0/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton ` (2 preceding siblings ...) 2026-07-01 19:56 ` [PATCH v4 3/4] sunrpc: guarantee a thread per CPU-bearing node when auto-distributing Jeff Layton @ 2026-07-01 19:56 ` Jeff Layton 2026-07-01 22:38 ` NeilBrown 3 siblings, 1 reply; 16+ messages in thread From: Jeff Layton @ 2026-07-01 19:56 UTC (permalink / raw) To: Trond Myklebust, Anna Schumaker, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever Cc: linux-nfs, linux-kernel, Jeff Layton 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@kernel.org> --- 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 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v4 4/4] sunrpc: eliminate a modulus operation from the enqueueing codepath 2026-07-01 19:56 ` [PATCH v4 4/4] sunrpc: eliminate a modulus operation from the enqueueing codepath Jeff Layton @ 2026-07-01 22:38 ` NeilBrown 0 siblings, 0 replies; 16+ messages in thread From: NeilBrown @ 2026-07-01 22:38 UTC (permalink / raw) To: Jeff Layton Cc: Trond Myklebust, Anna Schumaker, Olga Kornievskaia, Dai Ngo, Tom Talpey, Chuck Lever, linux-nfs, linux-kernel, Jeff Layton On Thu, 02 Jul 2026, Jeff Layton wrote: > 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. I would rather discard ->sv_nrpools as described in previous reply, then this modulus would disappear as it isn't needed. Thanks, NeilBrown > > Signed-off-by: Jeff Layton <jlayton@kernel.org> > --- > 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 > > ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-07-06 11:49 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-01 19:56 [PATCH v4 0/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton 2026-07-01 19:56 ` [PATCH v4 1/4] sunrpc: route to a populated pool in svc_pool_for_cpu() Jeff Layton 2026-07-01 22:13 ` NeilBrown 2026-07-02 12:17 ` Jeff Layton 2026-07-02 12:31 ` Jeff Layton 2026-07-03 3:42 ` NeilBrown 2026-07-06 11:49 ` Jeff Layton 2026-07-01 19:56 ` [PATCH v4 2/4] sunrpc: hardcode pool_mode to pernode, remove other modes Jeff Layton 2026-07-01 22:31 ` NeilBrown 2026-07-02 12:46 ` Jeff Layton 2026-07-03 4:02 ` NeilBrown 2026-07-01 19:56 ` [PATCH v4 3/4] sunrpc: guarantee a thread per CPU-bearing node when auto-distributing Jeff Layton 2026-07-01 22:37 ` NeilBrown 2026-07-02 13:05 ` Jeff Layton 2026-07-01 19:56 ` [PATCH v4 4/4] sunrpc: eliminate a modulus operation from the enqueueing codepath Jeff Layton 2026-07-01 22:38 ` NeilBrown
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox