From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <chuck.lever@oracle.com>, NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH v2 5/8] sunrpc: split new thread creation into a separate function
Date: Tue, 06 Jan 2026 13:59:47 -0500 [thread overview]
Message-ID: <20260106-nfsd-dynathread-v2-5-416e5f27b2b6@kernel.org> (raw)
In-Reply-To: <20260106-nfsd-dynathread-v2-0-416e5f27b2b6@kernel.org>
Break out the part of svc_start_kthreads() that creates a thread into
svc_new_thread(), as a new exported helper function.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
include/linux/sunrpc/svc.h | 1 +
net/sunrpc/svc.c | 72 +++++++++++++++++++++++++++-------------------
2 files changed, 44 insertions(+), 29 deletions(-)
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index 8fd511d02f3b36a614db5595c3b88afe9fce92a2..b55ed8404a9e9863cecfe1f29d79fcc426d6f31c 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -442,6 +442,7 @@ struct svc_serv *svc_create(struct svc_program *, unsigned int,
bool svc_rqst_replace_page(struct svc_rqst *rqstp,
struct page *page);
void svc_rqst_release_pages(struct svc_rqst *rqstp);
+int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool);
void svc_exit_thread(struct svc_rqst *);
struct svc_serv * svc_create_pooled(struct svc_program *prog,
unsigned int nprog,
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 54b32981a8bcf0538684123f73a81c5fa949b55c..bb1b5db42bcce51747a12b901b15d4cd4f5fcdd3 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -763,44 +763,58 @@ void svc_pool_wake_idle_thread(struct svc_pool *pool)
}
EXPORT_SYMBOL_GPL(svc_pool_wake_idle_thread);
-static int
-svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
+/**
+ * svc_new_thread - spawn a new thread in the given pool
+ * @serv: the serv to which the pool belongs
+ * @pool: pool in which thread should be spawned
+ *
+ * Create a new thread inside @pool, which is a part of @serv.
+ * Returns 0 on success, or -errno on failure.
+ */
+int svc_new_thread(struct svc_serv *serv, struct svc_pool *pool)
{
struct svc_rqst *rqstp;
struct task_struct *task;
int node;
- int err;
+ int err = 0;
- do {
- nrservs--;
- node = svc_pool_map_get_node(pool->sp_id);
-
- rqstp = svc_prepare_thread(serv, pool, node);
- if (!rqstp)
- return -ENOMEM;
- task = kthread_create_on_node(serv->sv_threadfn, rqstp,
- node, "%s", serv->sv_name);
- if (IS_ERR(task)) {
- svc_exit_thread(rqstp);
- return PTR_ERR(task);
- }
+ node = svc_pool_map_get_node(pool->sp_id);
- rqstp->rq_task = task;
- if (serv->sv_nrpools > 1)
- svc_pool_map_set_cpumask(task, pool->sp_id);
+ rqstp = svc_prepare_thread(serv, pool, node);
+ if (!rqstp)
+ return -ENOMEM;
+ task = kthread_create_on_node(serv->sv_threadfn, rqstp,
+ node, "%s", serv->sv_name);
+ if (IS_ERR(task)) {
+ err = PTR_ERR(task);
+ goto out;
+ }
- svc_sock_update_bufs(serv);
- wake_up_process(task);
+ rqstp->rq_task = task;
+ if (serv->sv_nrpools > 1)
+ svc_pool_map_set_cpumask(task, pool->sp_id);
- wait_var_event(&rqstp->rq_err, rqstp->rq_err != -EAGAIN);
- err = rqstp->rq_err;
- if (err) {
- svc_exit_thread(rqstp);
- return err;
- }
- } while (nrservs > 0);
+ svc_sock_update_bufs(serv);
+ wake_up_process(task);
- return 0;
+ wait_var_event(&rqstp->rq_err, rqstp->rq_err != -EAGAIN);
+ err = rqstp->rq_err;
+out:
+ if (err)
+ svc_exit_thread(rqstp);
+ return err;
+}
+EXPORT_SYMBOL_GPL(svc_new_thread);
+
+static int
+svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
+{
+ int err = 0;
+
+ while (!err && nrservs--)
+ err = svc_new_thread(serv, pool);
+
+ return err;
}
static int
--
2.52.0
next prev parent reply other threads:[~2026-01-06 19:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 18:59 [PATCH v2 0/8] nfsd, sunrpc: allow for a dynamically-sized threadpool Jeff Layton
2026-01-06 18:59 ` [PATCH v2 1/8] sunrpc: split svc_set_num_threads() into two functions Jeff Layton
2026-01-06 18:59 ` [PATCH v2 2/8] sunrpc: remove special handling of NULL pool from svc_start/stop_kthreads() Jeff Layton
2026-01-06 18:59 ` [PATCH v2 3/8] sunrpc: track the max number of requested threads in a pool Jeff Layton
2026-01-06 18:59 ` [PATCH v2 4/8] sunrpc: introduce the concept of a minimum number of threads per pool Jeff Layton
2026-01-06 18:59 ` Jeff Layton [this message]
2026-01-06 18:59 ` [PATCH v2 6/8] sunrpc: allow svc_recv() to return -ETIMEDOUT and -EBUSY Jeff Layton
2026-01-06 18:59 ` [PATCH v2 7/8] nfsd: adjust number of running nfsd threads based on activity Jeff Layton
2026-01-06 18:59 ` [PATCH v2 8/8] nfsd: add controls to set the minimum number of threads per pool Jeff Layton
2026-01-06 21:26 ` [PATCH v2 0/8] nfsd, sunrpc: allow for a dynamically-sized threadpool Chuck Lever
2026-01-06 21:53 ` Jeff Layton
2026-01-08 0:28 ` Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260106-nfsd-dynathread-v2-5-416e5f27b2b6@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=anna@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®