From: Peter Zijlstra <peterz@infradead.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Qian Cai <cai@lca.pw>,
akpm@linux-foundation.org, hch@lst.de, oleg@redhat.com,
gkohli@codeaurora.org, mingo@redhat.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] block: fix a crash in do_task_dead()
Date: Mon, 3 Jun 2019 14:37:05 +0200 [thread overview]
Message-ID: <20190603123705.GB3419@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <82e88482-1b53-9423-baad-484312957e48@kernel.dk>
On Fri, May 31, 2019 at 03:12:13PM -0600, Jens Axboe wrote:
> On 5/30/19 2:03 AM, Peter Zijlstra wrote:
> > What is the purpose of that patch ?! The Changelog doesn't mention any
> > benefit or performance gain. So why not revert that?
>
> Yeah that is actually pretty weak. There are substantial performance
> gains for small IOs using this trick, the changelog should have
> included those. I guess that was left on the list...
OK. I've looked at the try_to_wake_up() path for these exact
conditions and we're certainly sub-optimal there, and I think we can put
much of this special case in there. Please see below.
> I know it's not super kosher, your patch, but I don't think it's that
> bad hidden in a generic helper.
How about the thing that Oleg proposed? That is, not set a waiter when
we know the loop is polling? That would avoid the need for this
alltogether, it would also avoid any set_current_state() on the wait
side of things.
Anyway, Oleg, do you see anything blatantly buggered with this patch?
(the stats were already dodgy for rq-stats, this patch makes them dodgy
for task-stats too)
---
kernel/sched/core.c | 38 ++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 102dfcf0a29a..474aa4c8e9d2 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1990,6 +1990,28 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
unsigned long flags;
int cpu, success = 0;
+ if (p == current) {
+ /*
+ * We're waking current, this means 'p->on_rq' and 'task_cpu(p)
+ * == smp_processor_id()'. Together this means we can special
+ * case the whole 'p->on_rq && ttwu_remote()' case below
+ * without taking any locks.
+ *
+ * In particular:
+ * - we rely on Program-Order guarantees for all the ordering,
+ * - we're serialized against set_special_state() by virtue of
+ * it disabling IRQs (this allows not taking ->pi_lock).
+ */
+ if (!(p->state & state))
+ goto out;
+
+ success = 1;
+ trace_sched_waking(p);
+ p->state = TASK_RUNNING;
+ trace_sched_woken(p);
+ goto out;
+ }
+
/*
* If we are going to wake up a thread waiting for CONDITION we
* need to ensure that CONDITION=1 done by the caller can not be
@@ -1999,7 +2021,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
raw_spin_lock_irqsave(&p->pi_lock, flags);
smp_mb__after_spinlock();
if (!(p->state & state))
- goto out;
+ goto unlock;
trace_sched_waking(p);
@@ -2029,7 +2051,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
*/
smp_rmb();
if (p->on_rq && ttwu_remote(p, wake_flags))
- goto stat;
+ goto unlock;
#ifdef CONFIG_SMP
/*
@@ -2089,12 +2111,16 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
#endif /* CONFIG_SMP */
ttwu_queue(p, cpu, wake_flags);
-stat:
- ttwu_stat(p, cpu, wake_flags);
-out:
+unlock:
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
- return success;
+out:
+ if (success) {
+ ttwu_stat(p, cpu, wake_flags);
+ return true;
+ }
+
+ return false;
}
/**
next prev parent reply other threads:[~2019-06-03 12:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-29 20:25 Qian Cai
2019-05-29 20:31 ` Jens Axboe
2019-05-30 8:03 ` Peter Zijlstra
2019-05-31 21:12 ` Jens Axboe
2019-06-03 12:37 ` Peter Zijlstra [this message]
2019-06-03 12:44 ` Peter Zijlstra
2019-06-03 16:09 ` Oleg Nesterov
2019-06-03 16:19 ` Peter Zijlstra
2019-06-03 16:23 ` Jens Axboe
2019-06-05 15:04 ` Jens Axboe
2019-06-07 13:35 ` Peter Zijlstra
2019-06-07 14:23 ` Peter Zijlstra
2019-06-08 8:39 ` Jens Axboe
2019-06-10 13:13 ` Gaurav Kohli
2019-06-10 14:46 ` Oleg Nesterov
2019-06-11 4:39 ` Gaurav Kohli
2019-06-30 23:06 ` Hugh Dickins
2019-07-01 14:22 ` Jens Axboe
2019-07-02 22:06 ` Andrew Morton
2019-07-03 17:35 ` Oleg Nesterov
2019-07-03 17:44 ` Hugh Dickins
2019-07-04 16:00 ` Oleg Nesterov
2019-07-03 17:52 ` Jens Axboe
2019-05-30 11:15 ` Oleg Nesterov
2019-05-31 21:10 ` Jens Axboe
2019-07-04 16:03 ` [PATCH] swap_readpage: avoid blk_wake_io_task() if !synchronous Oleg Nesterov
2019-07-04 19:32 ` Andrew Morton
2019-07-04 21:15 ` Hugh Dickins
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=20190603123705.GB3419@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=cai@lca.pw \
--cc=gkohli@codeaurora.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
/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