From: Benjamin Coddington <bcodding@redhat.com>
To: Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>, Tejun Heo <tj@kernel.org>,
Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
djeffery@redhat.com, loberman@redhat.com
Subject: [PATCH 1/2] workqueue: Add a helper to identify current workqueue
Date: Mon, 7 Jul 2025 14:46:03 -0400 [thread overview]
Message-ID: <baad3adf8ea80b65d83dd196ab715992a0f1b768.1751913604.git.bcodding@redhat.com> (raw)
In-Reply-To: <cover.1751913604.git.bcodding@redhat.com>
Introduce a new helper current_workqueue() which returns the current task's
workqueue pointer or NULL if not a workqueue worker.
This will allow the NFS client to recognize the case where writeback occurs
within the nfsiod workqueue or is being submitted directly. NFS would like
to change the GFP_ flags for memory allocation to avoid stalls or cycles in
memory pools based on which context writeback is occurring. In a following
patch, this helper detects the case rather than checking the PF_WQ_WORKER
flag which can be passed along from another workqueue worker.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
include/linux/workqueue.h | 1 +
kernel/workqueue.c | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 6e30f275da77..29e1096e6dfa 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -623,6 +623,7 @@ extern void workqueue_set_max_active(struct workqueue_struct *wq,
extern void workqueue_set_min_active(struct workqueue_struct *wq,
int min_active);
extern struct work_struct *current_work(void);
+extern struct workqueue_struct *current_workqueue(void);
extern bool current_is_workqueue_rescuer(void);
extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
extern unsigned int work_busy(struct work_struct *work);
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 9f9148075828..a96eb209d5e0 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -6009,6 +6009,24 @@ struct work_struct *current_work(void)
}
EXPORT_SYMBOL(current_work);
+/**
+ * current_workqueue - retrieve %current task's work queue
+ *
+ * Determine if %current task is a workqueue worker and what workqueue it's
+ * working on. Useful to find out the context that the %current task is
+ * running in.
+ *
+ * Return: workqueue_struct if %current task is a workqueue worker, %NULL
+ * otherwise.
+ */
+struct workqueue_struct *current_workqueue(void)
+{
+ struct worker *worker = current_wq_worker();
+
+ return worker ? worker->current_pwq->wq : NULL;
+}
+EXPORT_SYMBOL(current_workqueue);
+
/**
* current_is_workqueue_rescuer - is %current workqueue rescuer?
*
--
2.47.0
next prev parent reply other threads:[~2025-07-07 18:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 18:46 [PATCH 0/2] Fix loopback mounted filesystems on NFS Benjamin Coddington
2025-07-07 18:46 ` Benjamin Coddington [this message]
2025-07-08 4:37 ` [PATCH 1/2] workqueue: Add a helper to identify current workqueue Tejun Heo
2025-07-08 10:25 ` Benjamin Coddington
2025-07-07 18:46 ` [PATCH 2/2] NFS: Improve nfsiod workqueue detection for allocation flags Benjamin Coddington
2025-07-07 19:25 ` Trond Myklebust
2025-07-07 20:12 ` Benjamin Coddington
2025-07-07 20:42 ` Trond Myklebust
2025-07-07 20:28 ` Laurence Oberman
2025-07-08 16:50 ` Laurence Oberman
2025-07-08 17:03 ` Benjamin Coddington
2025-07-08 17:09 ` Laurence Oberman
[not found] ` <F889E706-9B2B-48CA-B30E-60FB5EFE2578@redhat.com>
2025-07-09 14:36 ` [PATCH] NFS: Fixup allocation flags for nfsiod's __GFP_NORETRY Laurence Oberman
2025-07-07 19:15 ` [PATCH 0/2] Fix loopback mounted filesystems on NFS Jeff Layton
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=baad3adf8ea80b65d83dd196ab715992a0f1b768.1751913604.git.bcodding@redhat.com \
--to=bcodding@redhat.com \
--cc=anna@kernel.org \
--cc=djeffery@redhat.com \
--cc=jiangshanlai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=loberman@redhat.com \
--cc=tj@kernel.org \
--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