From: Lai Jiangshan <jiangshanlai@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>,
Naohiro.Aota@wdc.com, Lai Jiangshan <jiangshan.ljs@antgroup.com>,
Lai Jiangshan <jiangshanlai@gmail.com>
Subject: [PATCH 4/7] workqueue: Wrap common code into wq_adjust_pwqs_max_active()
Date: Wed, 27 Dec 2023 22:51:40 +0800 [thread overview]
Message-ID: <20231227145143.2399-5-jiangshanlai@gmail.com> (raw)
In-Reply-To: <20231227145143.2399-1-jiangshanlai@gmail.com>
From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
There are 3 places using the same code, so wrap them into a common helper.
Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
---
kernel/workqueue.c | 37 +++++++++++++++----------------------
1 file changed, 15 insertions(+), 22 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 3347ba3a734f..e0101b2b5fa3 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4190,6 +4190,16 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)
raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
}
+static void wq_adjust_pwqs_max_active(struct workqueue_struct *wq)
+{
+ struct pool_workqueue *pwq;
+
+ mutex_lock(&wq->mutex);
+ for_each_pwq(pwq, wq)
+ pwq_adjust_max_active(pwq);
+ mutex_unlock(&wq->mutex);
+}
+
/* initialize newly allocated @pwq which is associated with @wq and @pool */
static void init_pwq(struct pool_workqueue *pwq, struct workqueue_struct *wq,
struct worker_pool *pool)
@@ -4700,7 +4710,6 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
{
va_list args;
struct workqueue_struct *wq;
- struct pool_workqueue *pwq;
/*
* Unbound && max_active == 1 used to imply ordered, which is no longer
@@ -4761,14 +4770,8 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
* list.
*/
mutex_lock(&wq_pool_mutex);
-
- mutex_lock(&wq->mutex);
- for_each_pwq(pwq, wq)
- pwq_adjust_max_active(pwq);
- mutex_unlock(&wq->mutex);
-
+ wq_adjust_pwqs_max_active(wq);
list_add_tail_rcu(&wq->list, &workqueues);
-
mutex_unlock(&wq_pool_mutex);
return wq;
@@ -5698,19 +5701,14 @@ EXPORT_SYMBOL_GPL(work_on_cpu_safe_key);
void freeze_workqueues_begin(void)
{
struct workqueue_struct *wq;
- struct pool_workqueue *pwq;
mutex_lock(&wq_pool_mutex);
WARN_ON_ONCE(workqueue_freezing);
workqueue_freezing = true;
- list_for_each_entry(wq, &workqueues, list) {
- mutex_lock(&wq->mutex);
- for_each_pwq(pwq, wq)
- pwq_adjust_max_active(pwq);
- mutex_unlock(&wq->mutex);
- }
+ list_for_each_entry(wq, &workqueues, list)
+ wq_adjust_pwqs_max_active(wq);
mutex_unlock(&wq_pool_mutex);
}
@@ -5773,7 +5771,6 @@ bool freeze_workqueues_busy(void)
void thaw_workqueues(void)
{
struct workqueue_struct *wq;
- struct pool_workqueue *pwq;
mutex_lock(&wq_pool_mutex);
@@ -5783,12 +5780,8 @@ void thaw_workqueues(void)
workqueue_freezing = false;
/* restore max_active and repopulate worklist */
- list_for_each_entry(wq, &workqueues, list) {
- mutex_lock(&wq->mutex);
- for_each_pwq(pwq, wq)
- pwq_adjust_max_active(pwq);
- mutex_unlock(&wq->mutex);
- }
+ list_for_each_entry(wq, &workqueues, list)
+ wq_adjust_pwqs_max_active(wq);
out_unlock:
mutex_unlock(&wq_pool_mutex);
--
2.19.1.6.gb485710b
next prev parent reply other threads:[~2023-12-27 14:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-27 14:51 [PATCH 0/7] workqueue: Share the same PWQ for the CPUs of a pod and distribute max_active across pods Lai Jiangshan
2023-12-27 14:51 ` [PATCH 1/7] workqueue: Reuse the default PWQ as much as possible Lai Jiangshan
2023-12-27 14:51 ` [PATCH 2/7] workqueue: Share the same PWQ for the CPUs of a pod Lai Jiangshan
2024-01-03 2:55 ` kernel test robot
2024-01-03 9:01 ` Lai Jiangshan
2023-12-27 14:51 ` [PATCH 3/7] workqueue: Add pwq_calculate_max_active() Lai Jiangshan
2023-12-27 14:51 ` Lai Jiangshan [this message]
2023-12-27 14:51 ` [PATCH 5/7] workqueue: Addjust pwq's max_active when CPU online/offine Lai Jiangshan
2023-12-27 14:51 ` [PATCH 6/7] workqueue: Implement system-wide max_active enforcement for unbound workqueues Lai Jiangshan
2023-12-27 23:06 ` Tejun Heo
2023-12-27 14:51 ` [PATCH 7/7] workqueue: Rename wq->saved_max_active to wq->max_active Lai Jiangshan
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=20231227145143.2399-5-jiangshanlai@gmail.com \
--to=jiangshanlai@gmail.com \
--cc=Naohiro.Aota@wdc.com \
--cc=jiangshan.ljs@antgroup.com \
--cc=linux-kernel@vger.kernel.org \
--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®