From: Breno Leitao <leitao@debian.org>
To: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, Breno Leitao <leitao@debian.org>,
kernel-team@meta.com, marco.crivellari@suse.com
Subject: [PATCH 4/6] workqueue: account nr_active by the backing pool
Date: Fri, 31 Jul 2026 04:57:36 -0700 [thread overview]
Message-ID: <20260731-wq-pool-refactor-v1-4-8eaf71cdab5f@debian.org> (raw)
In-Reply-To: <20260731-wq-pool-refactor-v1-0-8eaf71cdab5f@debian.org>
Use is_pool_cpu_specific() instead of wq_node_nr_active() to check for
per workqueues.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
kernel/workqueue.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 513193be00a7d..d17fdcaaf1685 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1782,13 +1782,16 @@ static bool pwq_tryinc_nr_active(struct pool_workqueue *pwq, bool fill)
{
struct workqueue_struct *wq = pwq->wq;
struct worker_pool *pool = pwq->pool;
- struct wq_node_nr_active *nna = wq_node_nr_active(wq, pool->node);
+ struct wq_node_nr_active *nna;
bool obtained = false;
lockdep_assert_held(&pool->lock);
- if (!nna) {
- /* BH or per-cpu workqueue, pwq->nr_active is sufficient */
+ /*
+ * A concurrency-managed per-cpu pool accounts nr_active per pwq, so
+ * pwq->nr_active against wq->max_active is sufficient.
+ */
+ if (is_pool_cpu_specific(pool)) {
obtained = pwq->nr_active < READ_ONCE(wq->max_active);
goto out;
}
@@ -1796,6 +1799,10 @@ static bool pwq_tryinc_nr_active(struct pool_workqueue *pwq, bool fill)
if (unlikely(pwq->plugged))
return false;
+ nna = wq_node_nr_active(wq, pool->node);
+ if (WARN_ON_ONCE(!nna))
+ return false;
+
/*
* Unbound workqueue uses per-node shared nr_active $nna. If @pwq is
* already waiting on $nna, pwq_dec_nr_active() will maintain the
@@ -2013,7 +2020,7 @@ static void node_activate_pending_pwq(struct wq_node_nr_active *nna,
static void pwq_dec_nr_active(struct pool_workqueue *pwq)
{
struct worker_pool *pool = pwq->pool;
- struct wq_node_nr_active *nna = wq_node_nr_active(pwq->wq, pool->node);
+ struct wq_node_nr_active *nna;
lockdep_assert_held(&pool->lock);
@@ -2024,14 +2031,18 @@ static void pwq_dec_nr_active(struct pool_workqueue *pwq)
pwq->nr_active--;
/*
- * For a percpu workqueue, it's simple. Just need to kick the first
+ * A concurrency-managed per-cpu pool only needs to kick the first
* inactive work item on @pwq itself.
*/
- if (!nna) {
+ if (is_pool_cpu_specific(pool)) {
pwq_activate_first_inactive(pwq, false);
return;
}
+ nna = wq_node_nr_active(pwq->wq, pool->node);
+ if (WARN_ON_ONCE(!nna))
+ return;
+
/*
* If @pwq is for an unbound workqueue, it's more complicated because
* multiple pwqs and pools may be sharing the nr_active count. When a
--
2.53.0-Meta
next prev parent reply other threads:[~2026-07-31 11:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 11:57 [PATCH 0/6] workqueue: base pwq pool release and nr_active on " Breno Leitao
2026-07-31 11:57 ` [PATCH 1/6] workqueue: factor out get_percpu_pool() Breno Leitao
2026-07-31 11:57 ` [PATCH 2/6] workqueue: factor out alloc_and_link_percpu_pwqs() Breno Leitao
2026-07-31 11:57 ` [PATCH 3/6] workqueue: release pwq pools by pool type Breno Leitao
2026-08-03 0:31 ` Tejun Heo
2026-08-03 14:02 ` Breno Leitao
2026-08-03 16:50 ` Tejun Heo
2026-07-31 11:57 ` Breno Leitao [this message]
2026-08-03 0:34 ` [PATCH 4/6] workqueue: account nr_active by the backing pool Tejun Heo
2026-08-03 14:19 ` Breno Leitao
2026-07-31 11:57 ` [PATCH 5/6] workqueue: add a per-cpu backend for unbound pwqs Breno Leitao
2026-08-03 0:36 ` Tejun Heo
2026-08-03 16:35 ` Breno Leitao
2026-08-03 16:58 ` Tejun Heo
2026-07-31 11:57 ` [PATCH 6/6] workqueue: install per-cpu pwqs at creation for __WQ_PERCPU_POOLS Breno Leitao
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=20260731-wq-pool-refactor-v1-4-8eaf71cdab5f@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®