public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andi Kleen <ak@linux.intel.com>,
	Davidlohr Bueso <dave@stgolabs.net>, Jan Kara <jack@suse.cz>,
	Lukas Czerner <lczerner@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Mel Gorman <mgorman@techsingularity.net>,
	Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: wait_on_page_bit_common(TASK_KILLABLE, EXCLUSIVE) can miss wakeup?
Date: Tue, 30 Jun 2020 12:12:32 +1000	[thread overview]
Message-ID: <1593482936.bcy1487a6g.astroid@bobo.none> (raw)
In-Reply-To: <CAHk-=wjJKicPgmvf7atx=h6Li7ez9nFrpJdgTSRm5aUEnuVH6w@mail.gmail.com>

Excerpts from Linus Torvalds's message of June 30, 2020 2:36 am:
> On Mon, Jun 29, 2020 at 6:16 AM Nicholas Piggin <npiggin@gmail.com> wrote:
>>
>> No, ignore this part (which you explained well it was just a thinko,
>> and your patch of course would not have worked if this was the case):
>> the exclusive wake up doesn't get lost if schedule() was called because
>> state goes back to running regardless of what woke it.
> 
> Right.
> 
> The normal pattern for a wait-loop is
> 
>  - add yourself to the wait-queue and set yourself "sleeping" with a
> memory barrier.
> 
>  - test for the condition, exit if ok
> 
>  - go to sleep
> 
> and that pattern doesn't have the race.
> 
> The other common pattern is to check for the "do I need to sleep at
> all" at the *top* of the function, long before you bother with any
> wait-queues at all. This code does that odd "let's check in the middle
> if we need to sleep" instead, which then caused the bug.
> 
> So we had an odd setup because of three different wait conditions that
> had different rules for what they could/should do before sleeping, and
> then not sleeping reliably at all.
> 
> We could also fix it by just splitting out the three cases into their
> own wait routines that match the normal pattern. The bug really
> happened because that wait-loop is doing things such an odd way due to
> all the different cases..
> 
> I actually think it would be a lot more readable if it was three
> different cases instead of trying to be one "common" routine.
> 
> The *common* parts is the special PG_locked logic at the top, and the
> thrashing/delayacct code at the bottom.
> 
> And *that* could be a true common helper, but the wait loop (which
> isn't even a loop for the DROP case) are fundamentally different and
> probably should be separate functions.
> 
> So I think my "one-liner" fixes the problem, but I'd certainly be open
> to somebody cleaning this up properly.

I think it does. I would rather my patch which doesn't add a barrier to 
the "fast" path though (by the time we get here I think the fast path is
that we are sleeping on the page, doing the IO).

Alternatively (although this still adds more branching than necessary at
least it doesn't have a barrier for the sleeping case), you could set
the running state as an else case if you don't schedule.

Thanks,
Nick

  reply	other threads:[~2020-06-30  2:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24 16:11 wait_on_page_bit_common(TASK_KILLABLE, EXCLUSIVE) can miss wakeup? Oleg Nesterov
2020-06-24 16:20 ` Oleg Nesterov
2020-06-24 16:36   ` Linus Torvalds
2020-06-26 15:43     ` Peter Zijlstra
2020-06-28  5:39       ` Linus Torvalds
2020-06-28 13:18         ` Peter Zijlstra
2020-06-29  3:28         ` Nicholas Piggin
2020-06-29 13:16           ` Nicholas Piggin
2020-06-29 16:36             ` Linus Torvalds
2020-06-30  2:12               ` Nicholas Piggin [this message]
2020-06-29 14:02           ` Oleg Nesterov
2020-06-30  2:08             ` Nicholas Piggin
2020-06-30  6:17               ` Oleg Nesterov
2020-06-30  9:08                 ` Nicholas Piggin
2020-06-30 10:53                   ` Oleg Nesterov
2020-06-30 11:36                     ` Oleg Nesterov
2020-06-30 11:50                       ` Oleg Nesterov
2020-06-30 18:02                         ` Linus Torvalds
2020-06-30 18:29                           ` Oleg Nesterov
2020-06-30 18:57                             ` Linus Torvalds
2020-06-29 15:13         ` Oleg Nesterov
2020-06-24 16:22 ` Linus Torvalds
2020-06-24 16:43   ` Oleg Nesterov

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=1593482936.bcy1487a6g.astroid@bobo.none \
    --to=npiggin@gmail.com \
    --cc=ak@linux.intel.com \
    --cc=dave@stgolabs.net \
    --cc=jack@suse.cz \
    --cc=lczerner@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@techsingularity.net \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.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