From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Tejun Heo <tj@kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 2/2 V3] workqueue: simple refactor pwq_adjust_max_active()
Date: Mon, 21 Apr 2014 19:59:21 +0800 [thread overview]
Message-ID: <1398081561-12618-2-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1398081561-12618-1-git-send-email-laijs@cn.fujitsu.com>
Caculate the value(max_active) for pwq->max_active earlier.
Fast exit for max_active is not changed.
"if (!freezable && pwq->max_active == wq->saved_max_active)" is hardly
hit after __WQ_FREEZING was introduced. So we change the exit-condition
to a more possible condition.
Reduce wake_up_worker() rate.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
kernel/workqueue.c | 21 +++++++++++----------
1 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index beca98b..59bad6e 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -198,7 +198,7 @@ struct pool_workqueue {
int nr_in_flight[WORK_NR_COLORS];
/* L: nr of in_flight works */
int nr_active; /* L: nr of active works */
- int max_active; /* L: max active works */
+ int max_active; /* L&WQ: max active works */
struct list_head delayed_works; /* L: delayed works */
struct list_head pwqs_node; /* WR: node on wq->pwqs */
struct list_head mayday_node; /* MD: node on wq->maydays */
@@ -3756,20 +3756,23 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
static void pwq_adjust_max_active(struct pool_workqueue *pwq)
{
struct workqueue_struct *wq = pwq->wq;
- bool freezable = wq->flags & WQ_FREEZABLE;
+ int max_active = wq->saved_max_active;
/* for @wq->saved_max_active and @wq->flags */
lockdep_assert_held(&wq->mutex);
- /* fast exit for non-freezable wqs */
- if (!freezable && pwq->max_active == wq->saved_max_active)
+ if (wq->flags & __WQ_FREEZING) {
+ if (!WARN_ON_ONCE(!(wq->flags & WQ_FREEZABLE)))
+ max_active = 0;
+ }
+
+ /* fast exit for max_active is not changed */
+ if (pwq->max_active == max_active)
return;
spin_lock_irq(&pwq->pool->lock);
-
- if (!freezable || !(wq->flags & __WQ_FREEZING)) {
- pwq->max_active = wq->saved_max_active;
-
+ pwq->max_active = max_active;
+ if (pwq->nr_active < pwq->max_active) {
while (!list_empty(&pwq->delayed_works) &&
pwq->nr_active < pwq->max_active)
pwq_activate_first_delayed(pwq);
@@ -3779,8 +3782,6 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq)
* max_active is bumped. It's a slow path. Do it always.
*/
wake_up_worker(pwq->pool);
- } else {
- pwq->max_active = 0;
}
spin_unlock_irq(&pwq->pool->lock);
--
1.7.4.4
next prev parent reply other threads:[~2014-04-21 11:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-21 11:59 [PATCH 1/2 V3] workqueue: substitute POOL_FREEZING with __WQ_FREEZING Lai Jiangshan
2014-04-21 11:59 ` Lai Jiangshan [this message]
2014-04-21 22:20 ` Tejun Heo
2014-04-22 1:47 ` Lai Jiangshan
2014-04-22 20:46 ` Tejun Heo
2014-04-23 1:37 ` 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=1398081561-12618-2-git-send-email-laijs@cn.fujitsu.com \
--to=laijs@cn.fujitsu.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®