From: Marco Crivellari <marco.crivellari@suse.com>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
Frederic Weisbecker <frederic@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Marco Crivellari <marco.crivellari@suse.com>,
Michal Hocko <mhocko@suse.com>, Breno Leitao <leitao@debian.org>
Subject: [PATCH v2 1/2] workqueue: Make alloc_workqueue() unbound by default
Date: Thu, 3 Sep 2026 18:52:50 +0200 [thread overview]
Message-ID: <20260903165251.481362-2-marco.crivellari@suse.com> (raw)
In-Reply-To: <20260903165251.481362-1-marco.crivellari@suse.com>
Currently alloc_workqueue() ensure that one among WQ_PERCPU or WQ_UNBOUND
is present. Now every user has one among these two flags.
In order to achive the future goal of removing WQ_UNBOUND from the code,
start changing the default behavior making alloc_workqueue() act this way:
- if WQ_PERCPU and WQ_UNBOUND are present: remove WQ_PERCPU (as before)
- if neither are present: add WQ_UNBOUND
The WARN_ONCE() when neither flags are present has been removed and it has
been replaced by pr_warn_once(): from now on, every alloc_users()
without WQ_PERCPU will be considered unbound.
The pr_warn_once() will be removed along with WQ_UNBOUND in the future.
Link: https://lore.kernel.org/all/20250221112003.1dSuoGyc@linutronix.de/
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
---
kernel/workqueue.c | 43 +++++++++++++++++++++++++++----------------
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 1ae3732a2c51..c1e5f2c6c8dd 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5895,6 +5895,8 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
struct workqueue_struct *wq;
size_t wq_size;
int name_len;
+ bool wq_unbound_by_default = false;
+ bool wq_dropped_percpu = false;
if (flags & WQ_BH) {
if (WARN_ON_ONCE(flags & ~__WQ_BH_ALLOWS))
@@ -5903,6 +5905,24 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
return NULL;
}
+ /*
+ * Every caller that doesn't explicitly specify WQ_PERCPU will be
+ * unbound (WQ_UNBOUND) by default.
+ *
+ * If both flags are present at the same time, WQ_PERCPU will be
+ * removed.
+ *
+ * This must happen before wq_size is computed below, since that
+ * depends on the finalized WQ_UNBOUND flag.
+ */
+ if (unlikely(!(flags & (WQ_UNBOUND | WQ_PERCPU)))) {
+ flags |= WQ_UNBOUND;
+ wq_unbound_by_default = true;
+ } else if (unlikely((flags & WQ_PERCPU) && (flags & WQ_UNBOUND))) {
+ flags &= ~WQ_PERCPU;
+ wq_dropped_percpu = true;
+ }
+
/* see the comment above the definition of WQ_POWER_EFFICIENT */
if ((flags & WQ_POWER_EFFICIENT) && wq_power_efficient)
flags = (flags & ~WQ_PERCPU) | WQ_UNBOUND;
@@ -5927,22 +5947,13 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
pr_warn_once("workqueue: name exceeds WQ_NAME_LEN. Truncating to: %s\n",
wq->name);
- /*
- * One among WQ_PERCPU and WQ_UNBOUND must be set, but not both.
- * - If neither is set, default to WQ_PERCPU
- * - If both are set, default to WQ_UNBOUND
- *
- * This code can be removed after workqueue are unbound by default
- */
- if (unlikely(!(flags & (WQ_UNBOUND | WQ_PERCPU)))) {
- WARN_ONCE(1, "workqueue: %s is using neither WQ_PERCPU or WQ_UNBOUND. "
- "Setting WQ_PERCPU.\n", wq->name);
- flags |= WQ_PERCPU;
- } else if (unlikely((flags & WQ_PERCPU) && (flags & WQ_UNBOUND))) {
- WARN_ONCE(1, "workqueue: %s uses both WQ_PERCPU and WQ_UNBOUND. "
- "Dropped WQ_PERCPU, keeping WQ_UNBOUND.\n", wq->name);
- flags &= ~WQ_PERCPU;
- }
+ if (unlikely(wq_unbound_by_default))
+ pr_warn_once("workqueue: %s is using neither WQ_PERCPU or WQ_UNBOUND. "
+ "Setting WQ_UNBOUND.\n", wq->name);
+
+ WARN_ONCE(wq_dropped_percpu,
+ "workqueue: %s uses both WQ_PERCPU and WQ_UNBOUND. "
+ "Dropped WQ_PERCPU, keeping WQ_UNBOUND.\n", wq->name);
if (flags & WQ_BH) {
/*
--
2.55.0
next prev parent reply other threads:[~2026-09-03 16:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 16:52 [PATCH v2 0/2] workqueue: Make WQ_UNBOUND the default behavior Marco Crivellari
2026-09-03 16:52 ` Marco Crivellari [this message]
2026-09-03 18:42 ` [PATCH v2 1/2] workqueue: Make alloc_workqueue() unbound by default Tejun Heo
2026-09-04 8:24 ` Marco Crivellari
2026-09-03 16:52 ` [PATCH v2 2/2] doc: Update WQ_UNBOUND documentation Marco Crivellari
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=20260903165251.481362-2-marco.crivellari@suse.com \
--to=marco.crivellari@suse.com \
--cc=bigeasy@linutronix.de \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=tj@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®