mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Tejun Heo <tj@kernel.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>,
	linux-kernel@vger.kernel.org, Juri Lelli <juri.lelli@redhat.com>,
	Cestmir Kalina <ckalina@redhat.com>,
	Alex Gladkov <agladkov@redhat.com>, Phil Auld <pauld@redhat.com>,
	Costa Shulyupin <cshulyup@redhat.com>
Subject: Re: [PATCH wq/for-6.9 v4 2/4] workqueue: Enable unbound cpumask update on ordered workqueues
Date: Wed, 7 Feb 2024 15:59:06 -0500	[thread overview]
Message-ID: <69641d8a-8f1c-4a57-81af-0b26c8b1d2cd@redhat.com> (raw)
In-Reply-To: <ZcO8-JDXkoDeMFVT@slm.duckdns.org>


On 2/7/24 12:25, Tejun Heo wrote:
> Hello, Waiman.
>
> On Tue, Feb 06, 2024 at 08:19:09PM -0500, Waiman Long wrote:
> ...
>> + * The unplugging is done either in apply_wqattrs_cleanup() [fast path] when
>> + * the workqueue was idle or in pwq_release_workfn() [slow path] when the
>> + * workqueue was busy.
> I'm not sure the distinction between fast and slow paths is all that useful
> here. Both are really cold paths.
Yes, both are cold paths. Maybe a more accurate description is with 
respect to the latency that a new work item may experience since 
apply_wqattrs_cleanup() should be executed earlier than 
pwq_release_workfn().
>
>> +static void unplug_oldest_pwq(struct workqueue_struct *wq,
>> +			      struct pool_workqueue *exlude_pwq)
>> +{
>> +	struct pool_workqueue *pwq;
>> +	unsigned long flags;
>> +	bool found = false;
>> +
>> +	for_each_pwq(pwq, wq) {
>> +		if (pwq == exlude_pwq)
>> +			continue;
>> +		if (!pwq->plugged)
>> +			return;	/* No unplug needed */
>> +		found = true;
>> +		break;
>> +	}
>> +	if (WARN_ON_ONCE(!found))
>> +		return;
>> +
>> +	raw_spin_lock_irqsave(&pwq->pool->lock, flags);
>> +	if (!pwq->plugged)
>> +		goto out_unlock;
>> +	pwq->plugged = false;
>> +	if (pwq_activate_first_inactive(pwq, true))
>> +		kick_pool(pwq->pool);
>> +out_unlock:
>> +	raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
>> +}
> I don't quite understand why this needs iteration and @exclude_pwq.
> Shouldn't something like the following be enough?
>
> static void unplug_oldest_pwq(struct workqueue_struct *wq)
> {
> 	struct pool_workqueue *pwq;
>
> 	raw_spin_lock_irq(&pwq->pool->lock);
> 	pwq = list_first_entry_or_null(&pwq->pwqs, ...);
> 	if (pwq)
> 		pwq->plugged = false;
> 	raw_spin_unlock_irq(&pwq->pool->lock);
> }
>
It is because this function can be called from apply_wqattrs_cleanup() 
where I need to exclude ctx->dfl_pwq from being considered.
>> @@ -4740,6 +4796,13 @@ static void pwq_release_workfn(struct kthread_work *work)
>>   		mutex_lock(&wq->mutex);
>>   		list_del_rcu(&pwq->pwqs_node);
>>   		is_last = list_empty(&wq->pwqs);
>> +
>> +		/*
>> +		 * For ordered workqueue with a plugged dfl_pwq, restart it now.
>> +		 */
>> +		if (!is_last && (wq->flags & __WQ_ORDERED))
>> +			unplug_oldest_pwq(wq, NULL);
> This makes sense.
>
>> @@ -4906,8 +4969,26 @@ static void apply_wqattrs_cleanup(struct apply_wqattrs_ctx *ctx)
> ...
>> +		/*
>> +		 * It is possible that ctx->dfl_pwq (previous wq->dfl_pwq)
>> +		 * may not be the oldest one with the plugged flag still set.
>> +		 * unplug_oldest_pwq() will still do the right thing to allow
>> +		 * only one unplugged pwq in the workqueue.
>> +		 */
>> +		if ((ctx->wq->flags & __WQ_ORDERED) &&
>> +		     ctx->dfl_pwq && !ctx->dfl_pwq->refcnt)
>> +			unplug_oldest_pwq(ctx->wq, ctx->dfl_pwq);
>> +		rcu_read_unlock();
> But why do we need this? Isn't all that needed to call unplug_oldest during
> workqueue initialization and chaining unplugging from pwq release from there
> on?

Yes, it is possible to just do unplug_oldest_pwq() in 
pwq_release_workfn() and don't do it in apply_wqattrs_cleanup(). As said 
above, I just want to reduce the latency when the old pwq to be retired 
is idle. I can certainly update the patch to just do it in 
pwq_release_workfn() if you don't that it is necessary to do that too in 
apply_wqattrs_cleanup(). That will eliminate the need for the extra 
arugment and simplify unplug_oldest_pwq().

Cheers,
Longman



  reply	other threads:[~2024-02-07 20:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07  1:19 [PATCH wq/for-6.9 v4 0/4] " Waiman Long
2024-02-07  1:19 ` [PATCH wq/for-6.9 v4 1/4] workqueue: Link pwq's into wq->pwqs from oldest to newest Waiman Long
2024-02-07  1:19 ` [PATCH wq/for-6.9 v4 2/4] workqueue: Enable unbound cpumask update on ordered workqueues Waiman Long
2024-02-07 17:25   ` Tejun Heo
2024-02-07 20:59     ` Waiman Long [this message]
2024-02-07 21:18       ` Tejun Heo
2024-02-07  1:19 ` [PATCH wq/for-6.9 v4 3/4] kernel/workqueue: Let rescuers follow unbound wq cpumask changes Waiman Long
2024-02-07  1:19 ` [PATCH wq/for-6.9 v4 4/4] workqueue: Bind unbound workqueue rescuer to wq_unbound_cpumask Waiman Long

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=69641d8a-8f1c-4a57-81af-0b26c8b1d2cd@redhat.com \
    --to=longman@redhat.com \
    --cc=agladkov@redhat.com \
    --cc=ckalina@redhat.com \
    --cc=cshulyup@redhat.com \
    --cc=jiangshanlai@gmail.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pauld@redhat.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®