From: Bob Liu <bob.liu@oracle.com>
To: Lai Jiangshan <jiangshanlai+lkml@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, Tejun Heo <tj@kernel.org>,
martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
open-iscsi@googlegroups.com, lduncan@suse.com,
michael.christie@oracle.com
Subject: Re: [PATCH 1/2] workqueue: don't always set __WQ_ORDERED implicitly
Date: Mon, 29 Jun 2020 08:11:34 +0800 [thread overview]
Message-ID: <52fa1d81-e585-37eb-55e5-0ed07ce7adc0@oracle.com> (raw)
In-Reply-To: <CAJhGHyDQLuoCkjwnze_6ZOLwXPtbNxnjxOr=fqqqsR_yxB9xtA@mail.gmail.com>
On 6/28/20 11:54 PM, Lai Jiangshan wrote:
> On Thu, Jun 11, 2020 at 6:29 PM Bob Liu <bob.liu@oracle.com> wrote:
>>
>> Current code always set 'Unbound && max_active == 1' workqueues to ordered
>> implicitly, while this may be not an expected behaviour for some use cases.
>>
>> E.g some scsi and iscsi workqueues(unbound && max_active = 1) want to be bind
>> to different cpu so as to get better isolation, but their cpumask can't be
>> changed because WQ_ORDERED is set implicitly.
>
> Hello
>
> If I read the code correctly, the reason why their cpumask can't
> be changed is because __WQ_ORDERED_EXPLICIT, not __WQ_ORDERED.
>
>>
>> This patch adds a flag __WQ_ORDERED_DISABLE and also
>> create_singlethread_workqueue_noorder() to offer an new option.
>>
>> Signed-off-by: Bob Liu <bob.liu@oracle.com>
>> ---
>> include/linux/workqueue.h | 4 ++++
>> kernel/workqueue.c | 4 +++-
>> 2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
>> index e48554e..4c86913 100644
>> --- a/include/linux/workqueue.h
>> +++ b/include/linux/workqueue.h
>> @@ -344,6 +344,7 @@ enum {
>> __WQ_ORDERED = 1 << 17, /* internal: workqueue is ordered */
>> __WQ_LEGACY = 1 << 18, /* internal: create*_workqueue() */
>> __WQ_ORDERED_EXPLICIT = 1 << 19, /* internal: alloc_ordered_workqueue() */
>> + __WQ_ORDERED_DISABLE = 1 << 20, /* internal: don't set __WQ_ORDERED implicitly */
>>
>> WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */
>> WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */
>> @@ -433,6 +434,9 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
>> #define create_singlethread_workqueue(name) \
>> alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name)
>>
>> +#define create_singlethread_workqueue_noorder(name) \
>> + alloc_workqueue("%s", WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | \
>> + WQ_UNBOUND | __WQ_ORDERED_DISABLE, 1, (name))
>
> I think using __WQ_ORDERED without __WQ_ORDERED_EXPLICIT is what you
> need, in which case cpumask is allowed to be changed.
>
I don't think so, see function workqueue_apply_unbound_cpumask():
wq_unbound_cpumask_store()
> workqueue_set_unbound_cpumask()
> workqueue_apply_unbound_cpumask() {
...
5276 /* creating multiple pwqs breaks ordering guarantee */
5277 if (wq->flags & __WQ_ORDERED)
5278 continue;
^^^^
Here will skip apply cpumask if only __WQ_ORDERED is set.
5280 ctx = apply_wqattrs_prepare(wq, wq->unbound_attrs);
}
Thanks for your review.
Bob
> Just use alloc_workqueue() with __WQ_ORDERED and max_active=1. It can
> be wrapped as a new function or macro, but I don't think> create_singlethread_workqueue_noorder() is a good name for it.
>
>> extern void destroy_workqueue(struct workqueue_struct *wq);
>>
>> struct workqueue_attrs *alloc_workqueue_attrs(void);
>> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
>> index 4e01c44..2167013 100644
>> --- a/kernel/workqueue.c
>> +++ b/kernel/workqueue.c
>> @@ -4237,7 +4237,9 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
>> * on NUMA.
>> */
>> if ((flags & WQ_UNBOUND) && max_active == 1)
>> - flags |= __WQ_ORDERED;
>> + /* the caller may don't want __WQ_ORDERED to be set implicitly. */
>> + if (!(flags & __WQ_ORDERED_DISABLE))
>> + flags |= __WQ_ORDERED;
>>
>> /* see the comment above the definition of WQ_POWER_EFFICIENT */
>> if ((flags & WQ_POWER_EFFICIENT) && wq_power_efficient)
>> --
>> 2.9.5
>>
next prev parent reply other threads:[~2020-06-29 0:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 10:07 [PATCH 1/2] workqueue: don't always set __WQ_ORDERED implicitly Bob Liu
2020-06-11 10:07 ` [PATCH 2/2] scsi: register sysfs for scsi/iscsi workqueues Bob Liu
2020-06-22 15:40 ` Mike Christie
2020-06-23 10:44 ` Benjamin Block
2020-06-22 3:08 ` [PATCH 1/2] workqueue: don't always set __WQ_ORDERED implicitly Bob Liu
2020-06-28 15:54 ` Lai Jiangshan
2020-06-29 0:11 ` Bob Liu [this message]
2020-06-29 0:37 ` Lai Jiangshan
2020-06-29 0:54 ` Bob Liu
2020-07-01 3:06 ` Bob Liu
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=52fa1d81-e585-37eb-55e5-0ed07ce7adc0@oracle.com \
--to=bob.liu@oracle.com \
--cc=jiangshanlai+lkml@gmail.com \
--cc=lduncan@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=open-iscsi@googlegroups.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