From: Peter Zijlstra <peterz@infradead.org>
To: NeilBrown <neilb@suse.de>
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Trond Myklebust <trondmy@hammerspace.com>,
Michal Hocko <mhocko@suse.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH rfc] workqueue: honour cond_resched() more effectively.
Date: Mon, 9 Nov 2020 09:00:38 +0100 [thread overview]
Message-ID: <20201109080038.GY2594@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <87v9efp7cs.fsf@notabene.neil.brown.name>
On Mon, Nov 09, 2020 at 01:54:59PM +1100, NeilBrown wrote:
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 4418f5cb8324..728870965df1 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1784,7 +1784,12 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)
> #ifndef CONFIG_PREEMPTION
> extern int _cond_resched(void);
> #else
> -static inline int _cond_resched(void) { return 0; }
> +static inline int _cond_resched(void)
> +{
> + if (current->flags & PF_WQ_WORKER)
> + workqueue_cond_resched();
> + return 0;
> +}
> #endif
>
> #define cond_resched() ({ \
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 9a2fbf98fd6f..5b2e38567a0c 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -5620,6 +5620,8 @@ SYSCALL_DEFINE0(sched_yield)
> #ifndef CONFIG_PREEMPTION
> int __sched _cond_resched(void)
> {
> + if (current->flags & PF_WQ_WORKER)
> + workqueue_cond_resched();
> if (should_resched(0)) {
> preempt_schedule_common();
> return 1;
Much hate for this.. :/ cond_resched() should be a NOP on !PREEMPT and
you wreck that. Also, you call into that workqueue_cond_resched()
unconditionally, even when it wouldn't have rescheduled, which seems
very wrong too.
On top of all that, you're adding an extra load to the funcion :/
At some poine Paul tried to frob cond_resched() for RCU and ran into all
sorts of performance issues, I'm thinking this will too.
Going by your justification for all this:
> I think that once a worker calls cond_resched(), it should be treated as
> though it was run from a WQ_CPU_INTENSIVE queue, because only cpu-intensive
> tasks need to call cond_resched(). This would allow other workers to be
> scheduled.
I'm thinking the real problem is that you're abusing workqueues. Just
don't stuff so much work into it that this becomes a problem. Or rather,
if you do, don't lie to it about it.
next prev parent reply other threads:[~2020-11-09 8:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 2:54 [PATCH rfc] workqueue: honour cond_resched() more effectively NeilBrown
2020-11-09 7:50 ` Michal Hocko
2020-11-09 8:00 ` Peter Zijlstra [this message]
2020-11-09 13:50 ` Trond Myklebust
2020-11-09 14:01 ` tj
2020-11-09 14:11 ` Trond Myklebust
2020-11-09 16:10 ` tj
2020-11-17 22:16 ` NeilBrown
[not found] ` <20201118025820.307-1-hdanton@sina.com>
2020-11-18 5:11 ` NeilBrown
[not found] ` <20201118055108.358-1-hdanton@sina.com>
2020-11-19 23:07 ` NeilBrown
2020-12-02 20:20 ` tj
[not found] ` <20201120025953.607-1-hdanton@sina.com>
2020-11-20 4:33 ` NeilBrown
[not found] ` <20201126100646.1790-1-hdanton@sina.com>
2020-11-26 23:44 ` NeilBrown
2020-11-19 23:23 ` NeilBrown
2020-11-25 12:36 ` tj
2020-11-26 23:30 ` NeilBrown
2020-11-09 14:20 ` Peter Zijlstra
2020-11-10 2:26 ` NeilBrown
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=20201109080038.GY2594@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=jiangshanlai@gmail.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=neilb@suse.de \
--cc=tj@kernel.org \
--cc=trondmy@hammerspace.com \
--cc=vincent.guittot@linaro.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;
as well as URLs for NNTP newsgroup(s).