From: Breno Leitao <leitao@debian.org>
To: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com,
Breno Leitao <leitao@debian.org>,
kernel-team@meta.com
Subject: [PATCH wq/for-7.4 v2 1/3] workqueue: Move the initial max_active setup into a helper
Date: Fri, 25 Sep 2026 06:09:50 -0700 [thread overview]
Message-ID: <20260925-wq_final-v2-1-860ee052169e@debian.org> (raw)
In-Reply-To: <20260925-wq_final-v2-0-860ee052169e@debian.org>
Extract the max/min active assignment into a helper, simplifying
__alloc_workqueue() and keeping the next patch easier to review and reason
about.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
kernel/workqueue.c | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index e618108c6127da..97d2c9c0a7d6ab 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -6031,6 +6031,32 @@ static int init_rescuer(struct workqueue_struct *wq)
return 0;
}
+static void wq_init_max_active(struct workqueue_struct *wq, int max_active)
+{
+ int effective_max_active;
+
+ if (wq->flags & WQ_BH) {
+ /*
+ * BH workqueues always share a single execution context per CPU
+ * and don't impose any max_active limit.
+ */
+ effective_max_active = INT_MAX;
+ } else {
+ effective_max_active = max_active ?: WQ_DFL_ACTIVE;
+ effective_max_active = wq_clamp_max_active(effective_max_active,
+ wq->flags, wq->name);
+ }
+
+ if (wq->flags & WQ_UNBOUND) {
+ wq->max_active = effective_max_active;
+ wq->min_active = min(effective_max_active, WQ_DFL_MIN_ACTIVE);
+ wq->saved_min_active = wq->min_active;
+ } else {
+ wq->percpu_max_active = effective_max_active;
+ }
+ wq->saved_max_active = effective_max_active;
+}
+
/**
* wq_adjust_max_active - update a wq's max_active to the current setting
* @wq: target workqueue
@@ -6156,27 +6182,9 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
flags &= ~WQ_PERCPU;
}
- if (flags & WQ_BH) {
- /*
- * BH workqueues always share a single execution context per CPU
- * and don't impose any max_active limit.
- */
- max_active = INT_MAX;
- } else {
- max_active = max_active ?: WQ_DFL_ACTIVE;
- max_active = wq_clamp_max_active(max_active, flags, wq->name);
- }
-
/* init wq */
wq->flags = flags;
- if (flags & WQ_UNBOUND) {
- wq->max_active = max_active;
- wq->min_active = min(max_active, WQ_DFL_MIN_ACTIVE);
- wq->saved_min_active = wq->min_active;
- } else {
- wq->percpu_max_active = max_active;
- }
- wq->saved_max_active = max_active;
+ wq_init_max_active(wq, max_active);
mutex_init(&wq->mutex);
atomic_set(&wq->nr_pwqs_to_flush, 0);
INIT_LIST_HEAD(&wq->pwqs);
--
2.53.0-Meta
next prev parent reply other threads:[~2026-09-25 13:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 13:09 [PATCH wq/for-7.4 v2 0/3] workqueue: Keep max_active and percpu_max_active in sync Breno Leitao
2026-09-25 13:09 ` Breno Leitao [this message]
2026-09-25 13:09 ` [PATCH wq/for-7.4 v2 2/3] workqueue: Keep the limits of both max_active domains current Breno Leitao
2026-09-28 20:15 ` Tejun Heo
2026-09-25 13:09 ` [PATCH wq/for-7.4 v2 3/3] workqueue: add a percpu_concurrency_managed workqueue attribute Breno Leitao
2026-09-28 21:31 ` Tejun Heo
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=20260925-wq_final-v2-1-860ee052169e@debian.org \
--to=leitao@debian.org \
--cc=jiangshanlai@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marco.crivellari@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®