summaryrefslogtreecommitdiff
path: root/net/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <cel@kernel.org>2026-06-10 21:58:53 -0400
committerChuck Lever <cel@kernel.org>2026-07-27 08:49:57 -0400
commit8968b2bcbc55e8b8f03018fcaf4d4dd7d62c4229 (patch)
tree3044820b1302b3aee76adcdf602e40068f343892 /net/sunrpc
parentd54b94e566d7b2bf39593fd509f999c305150bd0 (diff)
downloadlinux-next-8968b2bcbc55e8b8f03018fcaf4d4dd7d62c4229.tar.gz
linux-next-8968b2bcbc55e8b8f03018fcaf4d4dd7d62c4229.zip
SUNRPC: Add svc_serv_maxthreads() to report the thread ceiling
A pooled RPC service sizes its threads dynamically, growing and shrinking each pool between its minimum and maximum bounds as load varies. The count of running threads therefore reflects recent demand, not the service's capacity. A consumer that sizes a data structure against the concurrency the service can sustain -- NFSD's NFSv4 session slot tables, for one -- needs that stable ceiling, and computing it means summing sp_nrthrmax across every pool. Add svc_serv_maxthreads() so the summation, and its dependence on the layout of struct svc_serv and struct svc_pool, stays within sunrpc. The read is lock-free: pool maxima change only when a service is reconfigured, a path callers already serialize against startup and shutdown, so a racing reader observes at worst a transient value. This is acceptable for the sizing heuristics that will consume it. nfsd_nrthreads() already sums sp_nrthrmax across pools by hand; convert it to svc_serv_maxthreads(), giving the new export an in-tree consumer and removing a copy of the dependence on svc_serv internals. Reviewed-by: NeilBrown <neil@brown.name> Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Benjamin Coddington <bcodding@hammerspace.com> Link: https://patch.msgid.link/20260610-nfsd-slot-growth-clamp-v1-1-7b966700df0b@kernel.org Signed-off-by: Chuck Lever <cel@kernel.org>
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/svc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 009373737ea9..86d39610cf0a 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -988,6 +988,29 @@ svc_set_num_threads(struct svc_serv *serv, unsigned int min_threads,
EXPORT_SYMBOL_GPL(svc_set_num_threads);
/**
+ * svc_serv_maxthreads - report a service's configured thread ceiling
+ * @serv: RPC service to query
+ *
+ * A pooled service sizes its threads dynamically, so the number of
+ * threads running at any moment tracks recent load rather than the
+ * service's capacity. The per-pool maximum is the stable figure a
+ * consumer should size against.
+ *
+ * The caller must keep @serv valid for the duration of the call.
+ *
+ * Return: the sum of every pool's maximum thread count.
+ */
+unsigned int svc_serv_maxthreads(const struct svc_serv *serv)
+{
+ unsigned int i, max = 0;
+
+ for (i = 0; i < serv->sv_nrpools; i++)
+ max += data_race(serv->sv_pools[i].sp_nrthrmax);
+ return max;
+}
+EXPORT_SYMBOL_GPL(svc_serv_maxthreads);
+
+/**
* svc_rqst_replace_page - Replace one page in rq_respages[]
* @rqstp: svc_rqst with pages to replace
* @page: replacement page