All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chris Mason <chris.mason@oracle.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Matthew Wilcox <matthew@wil.cx>, Chuck Lever <cel@citi.umich.edu>,
	Nick Piggin <nickpiggin@yahoo.com.au>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v3] wait: prevent waiter starvation in __wait_on_bit_lock
Date: Wed, 21 Jan 2009 15:36:02 +0100	[thread overview]
Message-ID: <20090121143602.GA16584@redhat.com> (raw)
In-Reply-To: <20090120203131.GA20985@cmpxchg.org>

On 01/20, Johannes Weiner wrote:
>
> > But, more importantly, I'm afraid we can also have the false negative,
> > this "if (!test_bit())" test lacks the barriers. This can't happen with
> > sync_page_killable() because it always calls schedule(). But let's
> > suppose we modify it to check signal_pending() first:
> >
> > 	static int sync_page_killable(void *word)
> > 	{
> > 		if (fatal_signal_pending(current))
> > 			return -EINTR;
> > 		return sync_page(word);
> > 	}
> >
> > It is still correct, but unless I missed something now __wait_on_bit_lock()
> > has problems again.
>
> Hm, this would require the lock bit to be set without someone else
> doing the wakeup.  How could this happen?
>
> I could think of wake_up_page() happening BEFORE clear_bit_unlock()
> and we have to be on the front of the waitqueue.  Then we are already
> running, the wake up is a nop, the !test_bit() is false and noone
> wakes up the next real contender.
>
> But the wake up side uses a smp barrier after clearing the bit, so if
> the bit is not cleared we can expect a wake up, no?

Yes we have the barriers on the "wakeup", but this doesn't mean the
woken task must see the result of clear_bit() (unless it was really
unscheduled of course).

> Or do we still need a read-side barrier before the test bit?

Even this can't help afaics.

Because the the whole clear_bit + wakeup sequence can happen after
the "if (!test_bit()) check and before finish_wait(). Please note
that from the waker's pov we are sleeping in TASK_KILLABLE state,
it will wake up us if we are at the front of the waitqueue.

(to clarify, I am talking about the imaginary sync_page_killable()
 above).

Oleg.


WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chris Mason <chris.mason@oracle.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Matthew Wilcox <matthew@wil.cx>, Chuck Lever <cel@citi.umich.edu>,
	Nick Piggin <nickpiggin@yahoo.com.au>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v3] wait: prevent waiter starvation in __wait_on_bit_lock
Date: Wed, 21 Jan 2009 15:36:02 +0100	[thread overview]
Message-ID: <20090121143602.GA16584@redhat.com> (raw)
In-Reply-To: <20090120203131.GA20985@cmpxchg.org>

On 01/20, Johannes Weiner wrote:
>
> > But, more importantly, I'm afraid we can also have the false negative,
> > this "if (!test_bit())" test lacks the barriers. This can't happen with
> > sync_page_killable() because it always calls schedule(). But let's
> > suppose we modify it to check signal_pending() first:
> >
> > 	static int sync_page_killable(void *word)
> > 	{
> > 		if (fatal_signal_pending(current))
> > 			return -EINTR;
> > 		return sync_page(word);
> > 	}
> >
> > It is still correct, but unless I missed something now __wait_on_bit_lock()
> > has problems again.
>
> Hm, this would require the lock bit to be set without someone else
> doing the wakeup.  How could this happen?
>
> I could think of wake_up_page() happening BEFORE clear_bit_unlock()
> and we have to be on the front of the waitqueue.  Then we are already
> running, the wake up is a nop, the !test_bit() is false and noone
> wakes up the next real contender.
>
> But the wake up side uses a smp barrier after clearing the bit, so if
> the bit is not cleared we can expect a wake up, no?

Yes we have the barriers on the "wakeup", but this doesn't mean the
woken task must see the result of clear_bit() (unless it was really
unscheduled of course).

> Or do we still need a read-side barrier before the test bit?

Even this can't help afaics.

Because the the whole clear_bit + wakeup sequence can happen after
the "if (!test_bit()) check and before finish_wait(). Please note
that from the waker's pov we are sleeping in TASK_KILLABLE state,
it will wake up us if we are at the front of the waitqueue.

(to clarify, I am talking about the imaginary sync_page_killable()
 above).

Oleg.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2009-01-21 14:41 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-17 21:51 + lock_page_killable-avoid-lost-wakeups.patch added to -mm tree Oleg Nesterov
2009-01-18  1:38 ` [PATCH v3] wait: prevent waiter starvation in __wait_on_bit_lock Johannes Weiner
2009-01-18  1:38   ` Johannes Weiner
2009-01-18  2:32   ` Oleg Nesterov
2009-01-18  2:32     ` Oleg Nesterov
2009-01-20 20:31     ` Johannes Weiner
2009-01-20 20:31       ` Johannes Weiner
2009-01-21 14:36       ` Oleg Nesterov [this message]
2009-01-21 14:36         ` Oleg Nesterov
2009-01-21 21:38         ` [RFC v4] " Johannes Weiner
2009-01-21 21:38           ` Johannes Weiner
2009-01-22 20:25           ` Oleg Nesterov
2009-01-22 20:25             ` Oleg Nesterov
2009-01-23  0:26             ` Dmitry Adamushko
2009-01-23  0:26               ` Dmitry Adamushko
2009-01-23  0:47               ` Oleg Nesterov
2009-01-23  0:47                 ` Oleg Nesterov
2009-01-23 10:07                 ` Dmitry Adamushko
2009-01-23 10:07                   ` Dmitry Adamushko
2009-01-23 11:05                   ` Oleg Nesterov
2009-01-23 11:05                     ` Oleg Nesterov
2009-01-23 12:36                     ` Dmitry Adamushko
2009-01-23 12:36                       ` Dmitry Adamushko
2009-01-23  9:59             ` Johannes Weiner
2009-01-23  9:59               ` Johannes Weiner
2009-01-23 11:35               ` Oleg Nesterov
2009-01-23 11:35                 ` Oleg Nesterov
2009-01-23 13:30                 ` Oleg Nesterov
2009-01-23 13:30                   ` Oleg Nesterov
2009-01-26 21:59                   ` [RFC v5] wait: prevent exclusive waiter starvation Johannes Weiner
2009-01-26 21:59                     ` Johannes Weiner
2009-01-27  3:23                     ` Oleg Nesterov
2009-01-27  3:23                       ` Oleg Nesterov
2009-01-27 19:34                       ` [RFC v6] " Johannes Weiner
2009-01-27 19:34                         ` Johannes Weiner
2009-01-27 20:05                         ` Oleg Nesterov
2009-01-27 20:05                           ` Oleg Nesterov
2009-01-27 22:31                           ` Johannes Weiner
2009-01-27 22:31                             ` Johannes Weiner
2009-01-28  9:14                           ` [RFC v7] " Johannes Weiner
2009-01-28  9:14                             ` Johannes Weiner
2009-01-29  4:42                             ` Oleg Nesterov
2009-01-29  4:42                               ` Oleg Nesterov
2009-01-29  7:37                               ` Andrew Morton
2009-01-29  7:37                                 ` Andrew Morton
2009-01-29  8:31                                 ` Oleg Nesterov
2009-01-29  8:31                                   ` Oleg Nesterov
2009-01-29  9:11                                   ` Andrew Morton
2009-01-29  9:11                                     ` Andrew Morton
2009-01-29 14:34                                     ` Chris Mason
2009-01-29 14:34                                       ` Chris Mason
2009-02-02 15:47                                       ` Chris Mason
2009-02-02 15:47                                         ` Chris Mason
2009-01-23 19:24                 ` [RFC v4] wait: prevent waiter starvation in __wait_on_bit_lock Johannes Weiner
2009-01-23 19:24                   ` Johannes Weiner

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=20090121143602.GA16584@redhat.com \
    --to=oleg@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=cel@citi.umich.edu \
    --cc=chris.mason@oracle.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew@wil.cx \
    --cc=nickpiggin@yahoo.com.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.