public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: David Howells <dhowells@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Trond.Myklebust@netapp.com, serue@us.ibm.com, steved@redhat.com,
	viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org,
	Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] slow_work_thread() should do the exclusive wait
Date: Thu, 23 Apr 2009 18:18:32 +0200	[thread overview]
Message-ID: <20090423161832.GA5646@redhat.com> (raw)
In-Reply-To: <20712.1240502435@redhat.com>

(add Ingo)

On 04/23, David Howells wrote:
>
> Andrew Morton <akpm@linux-foundation.org> wrote:
>
> > I wonder if slow_work_cull_timeout() should have some sort of barrier,
> > so the write is suitably visible to the woken thread.  Bearing in mind
> > that the thread might _already_ have been woken by someone else?
>
> Perhaps the attached patch?
>
> David
> ---
> From: David Howells <dhowells@redhat.com>
> Subject: [PATCH] slow_work_cull_timeout() should have a memory barrier
>
> slow_work_cull_timeout() should have a write memory barrier so that the setting
> of the cull flag is seen before the wakeup takes place.  This is required
> because wake_up() does not guarantee any memory barriership at all.
>
> Concomitant to this, slow_work_thread() should have a read memory barrier
> between its return from schedule() and its testing of slow_work_cull() as
> finish_wait() isn't a guaranteed barrier either.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
>
>  kernel/slow-work.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
>
> diff --git a/kernel/slow-work.c b/kernel/slow-work.c
> index 521ed20..96e418d 100644
> --- a/kernel/slow-work.c
> +++ b/kernel/slow-work.c
> @@ -382,6 +382,7 @@ static int slow_work_thread(void *_data)
>  		finish_wait(&slow_work_thread_wq, &wait);
>
>  		try_to_freeze();
> +		smp_rmb();
>
>  		vsmax = vslow_work_proportion;
>  		vsmax *= atomic_read(&slow_work_thread_count);
> @@ -416,6 +417,7 @@ static int slow_work_thread(void *_data)
>  static void slow_work_cull_timeout(unsigned long data)
>  {
>  	slow_work_cull = true;
> +	smp_wmb();
>  	wake_up(&slow_work_thread_wq);
>  }

Confused. If we need this barrier, a lot of similar code is broken.

	slow_work_cull_timeout:

		slow_work_cull = true;
		wake_up(&slow_work_thread_wq);


	slow_work_thread:

		prepare_to_wait(&slow_work_thread_wq);
		if (!slow_work_cull)
			schedule();
		finish_wait(&slow_work_thread_wq);

		if (slow_work_cull)
			.....

Both wake_up() and prepare_to_wait() take the same wait_queue_head_t->lock,
and prepare_to_wait() does set_current_state() under this lock.

How can we miss the event? If wake_up() happens before prepare_to_wait(),
slow_work_thread() must see slow_work_cull = T, otherwise the subsequent
wake_up() must see the result of list_add() + set_current_state() and
wake up the sleeping thread.

Could you please clarify?

Oleg.


  reply	other threads:[~2009-04-23 16:24 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-13 18:17 [PATCH] slow_work_thread() should do the exclusive wait Oleg Nesterov
2009-04-13 19:03 ` Trond Myklebust
2009-04-13 19:14   ` Oleg Nesterov
2009-04-13 21:40   ` David Howells
2009-04-13 21:48     ` Oleg Nesterov
2009-04-13 21:57       ` Trond Myklebust
2009-04-13 22:24         ` Oleg Nesterov
2009-04-15 23:27           ` Andrew Morton
2009-04-16  9:10             ` David Howells
2009-04-16 14:33               ` Oleg Nesterov
2009-04-22 13:37                 ` [PATCH] Document that wake_up(), complete() and co. imply a full memory barrier David Howells
2009-04-22 13:51                   ` Ingo Molnar
2009-04-22 14:39                     ` Oleg Nesterov
2009-04-22 14:56                       ` Ingo Molnar
2009-04-22 15:07                         ` Oleg Nesterov
2009-04-22 15:12                     ` David Howells
2009-04-22 15:19                       ` Ingo Molnar
2009-04-22 16:23                       ` David Howells
2009-04-22 17:57                         ` Ingo Molnar
2009-04-23 16:32                           ` [PATCH] It may not be assumed that wake_up(), finish_wait() and co. imply a " David Howells
2009-04-23 16:55                             ` Oleg Nesterov
2009-04-24 11:46                               ` David Howells
2009-04-24 15:08                                 ` Paul E. McKenney
2009-04-24 17:08                                   ` Oleg Nesterov
2009-04-24 17:43                                     ` Paul E. McKenney
2009-04-24 17:48                                   ` David Howells
2009-04-24 18:06                                     ` Paul E. McKenney
2009-04-28 10:18                                       ` David Howells
2009-04-28 13:00                                         ` Paul E. McKenney
2009-04-24 17:28                                 ` Oleg Nesterov
2009-04-24 17:53                                   ` David Howells
2009-04-24 18:30                                     ` Oleg Nesterov
2009-04-23 17:07                             ` Linus Torvalds
2009-04-23 20:35                               ` David Howells
2009-04-23 21:12                                 ` Linus Torvalds
2009-04-23 21:24                                   ` Ingo Molnar
2009-04-23 16:36                           ` [PATCH] Document that wake_up(), complete() and co. imply a full " Oleg Nesterov
2009-04-23 20:37                             ` David Howells
2009-04-23 16:00             ` [PATCH] slow_work_thread() should do the exclusive wait David Howells
2009-04-23 16:18               ` Oleg Nesterov [this message]
2009-04-13 21:35 ` David Howells
  -- strict thread matches above, loose matches on Subject: below --
2009-06-11 12:12 David Howells

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=20090423161832.GA5646@redhat.com \
    --to=oleg@redhat.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=serue@us.ibm.com \
    --cc=steved@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /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