From: Wilson Felipe Pereira <wfelipe@google.com>
To: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Wilson Felipe Pereira <wfelipe@google.com>,
Shuhao Tan <tanshuhao@google.com>
Subject: [PATCH 1/3] workqueue: preserve pwq->stats[] when unbound pwqs are released
Date: Thu, 22 Oct 2026 15:53:34 +0000 [thread overview]
Message-ID: <20261022155352.1293020-2-wfelipe@google.com> (raw)
In-Reply-To: <20261022155352.1293020-1-wfelipe@google.com>
When an unbound pool_workqueue is replaced (e.g. during CPU hotplug or
apply_workqueue_attrs()), pwq_release_workfn() unlinks and frees the old
pwq along with its pwq->stats[]. This causes cumulative per-workqueue
counters to go backwards.
Add retired_stats[] to struct workqueue_struct and accumulate a released
pwq's stats into wq->retired_stats[] under wq->mutex before freeing it.
Signed-off-by: Wilson Felipe Pereira <wfelipe@google.com>
---
kernel/workqueue.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index f2e8071a6f4e..88c8cc2b38d8 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -397,6 +397,8 @@ struct workqueue_struct {
struct workqueue_attrs *attrs; /* PW: workqueue attributes */
struct pool_workqueue __rcu *dfl_pwq; /* PW: only for unbound wqs */
+ u64 retired_stats[PWQ_NR_STATS]; /* WQ: stats from released pwqs */
+
#ifdef CONFIG_SYSFS
struct wq_device *wq_dev; /* I: for sysfs interface */
#endif
@@ -5475,8 +5477,12 @@ static void pwq_release_workfn(struct kthread_work *work)
* @wq, and @wq is invalid to access.
*/
if (!list_empty(&pwq->pwqs_node)) {
+ int i;
+
mutex_lock(&wq->mutex);
list_del_rcu(&pwq->pwqs_node);
+ for (i = 0; i < PWQ_NR_STATS; i++)
+ wq->retired_stats[i] += pwq->stats[i];
is_last = list_empty(&wq->pwqs);
/*
--
2.56.0.218.g1ec904b173-goog
next prev parent reply other threads:[~2026-10-22 15:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 15:53 [PATCH 0/3] workqueue: expose per-workqueue stats in debugfs Wilson Felipe Pereira
2026-10-22 15:53 ` Wilson Felipe Pereira [this message]
2026-10-22 15:53 ` [PATCH 2/3] " Wilson Felipe Pereira
2026-10-22 15:53 ` [PATCH 3/3] tools/workqueue: report queued items and retired stats in wq_monitor.py Wilson Felipe Pereira
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=20261022155352.1293020-2-wfelipe@google.com \
--to=wfelipe@google.com \
--cc=corbet@lwn.net \
--cc=jiangshanlai@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=tanshuhao@google.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®