All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nick Piggin <npiggin@suse.de>
Cc: Peter Klotz <peter.klotz@aon.at>,
	stable@kernel.org,
	Linux Memory Management List <linux-mm@kvack.org>,
	Christoph Hellwig <hch@infradead.org>,
	Roman Kononov <kernel@kononov.ftml.net>,
	linux-kernel@vger.kernel.org, xfs@oss.sgi.com,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [patch] mm: fix lockless pagecache reordering bug (was Re: BUG: soft lockup - is this XFS problem?)
Date: Mon, 5 Jan 2009 11:39:29 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0901051131090.3057@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0901051027011.3057@localhost.localdomain>



On Mon, 5 Jan 2009, Linus Torvalds wrote:
> 
> Either the value can change, or it can not. It's that simple.
> 
> If it cannot change, then we can load it just once, or we can load it 
> multiple times, and it won't matter. Barriers won't do anything but screw 
> up the code.
> 
> If it can change from under us, you need to use rcu_dereference(), or 
> open-code it with an ACCESS_ONCE() or put in barriers. But your placement 
> of a barrier was NONSENSICAL. Your barrier didn't protect anything else - 
> like the test for the RADIX_TREE_INDIRECT_PTR bit.
> 
> And that was the fundamental problem.

Btw, this is the real issue with anything that does "locking vs 
optimistic" accesses.

If you use locking, then by definition (if you did things right), the 
values you are working with do not change. As a result, it doesn't matter 
if the compiler re-orders accesses, splits them up, or coalesces them. 
It's why normal code should never need barriers, because it doesn't matter 
whether some access gets optimized away or gets done multiple times.

But whenever you use an optimistic algorithm, and the data may change 
under you, you need to use barriers or other things to limit the things 
the CPU and/or compiler does.

And yes, "rcu_dereference()" is one such thing - it's not a barrier in the 
sense that it doesn't necessarily affect ordering of accesses to other 
variables around it (although the read_barrier_depends() obviously _is_ a 
very special kind of ordering wrt the pointer itself on alpha). But it 
does make sure that the compiler at least does not coalesce - or split - 
that _one_ particular access.

It's true that it has "rcu" in its name, and it's also true that that may 
be a bit misleading in that it's very much useful not just for rcu, but 
for _any_ algorithm that depends on rcu-like behavior - ie optimistic 
accesses to data that may change underneath it. RCU is just the most 
commonly used (and perhaps best codified) variant of that kind of code.

			Linus

WARNING: multiple messages have this Message-ID (diff)
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nick Piggin <npiggin@suse.de>
Cc: linux-kernel@vger.kernel.org,
	Roman Kononov <kernel@kononov.ftml.net>,
	xfs@oss.sgi.com, Christoph Hellwig <hch@infradead.org>,
	Linux Memory Management List <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Klotz <peter.klotz@aon.at>,
	stable@kernel.org
Subject: Re: [patch] mm: fix lockless pagecache reordering bug (was Re: BUG: soft lockup - is this XFS problem?)
Date: Mon, 5 Jan 2009 11:39:29 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0901051131090.3057@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0901051027011.3057@localhost.localdomain>



On Mon, 5 Jan 2009, Linus Torvalds wrote:
> 
> Either the value can change, or it can not. It's that simple.
> 
> If it cannot change, then we can load it just once, or we can load it 
> multiple times, and it won't matter. Barriers won't do anything but screw 
> up the code.
> 
> If it can change from under us, you need to use rcu_dereference(), or 
> open-code it with an ACCESS_ONCE() or put in barriers. But your placement 
> of a barrier was NONSENSICAL. Your barrier didn't protect anything else - 
> like the test for the RADIX_TREE_INDIRECT_PTR bit.
> 
> And that was the fundamental problem.

Btw, this is the real issue with anything that does "locking vs 
optimistic" accesses.

If you use locking, then by definition (if you did things right), the 
values you are working with do not change. As a result, it doesn't matter 
if the compiler re-orders accesses, splits them up, or coalesces them. 
It's why normal code should never need barriers, because it doesn't matter 
whether some access gets optimized away or gets done multiple times.

But whenever you use an optimistic algorithm, and the data may change 
under you, you need to use barriers or other things to limit the things 
the CPU and/or compiler does.

And yes, "rcu_dereference()" is one such thing - it's not a barrier in the 
sense that it doesn't necessarily affect ordering of accesses to other 
variables around it (although the read_barrier_depends() obviously _is_ a 
very special kind of ordering wrt the pointer itself on alpha). But it 
does make sure that the compiler at least does not coalesce - or split - 
that _one_ particular access.

It's true that it has "rcu" in its name, and it's also true that that may 
be a bit misleading in that it's very much useful not just for rcu, but 
for _any_ algorithm that depends on rcu-like behavior - ie optimistic 
accesses to data that may change underneath it. RCU is just the most 
commonly used (and perhaps best codified) variant of that kind of code.

			Linus

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

WARNING: multiple messages have this Message-ID (diff)
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nick Piggin <npiggin@suse.de>
Cc: Peter Klotz <peter.klotz@aon.at>,
	stable@kernel.org,
	Linux Memory Management List <linux-mm@kvack.org>,
	Christoph Hellwig <hch@infradead.org>,
	Roman Kononov <kernel@kononov.ftml.net>,
	linux-kernel@vger.kernel.org, xfs@oss.sgi.com,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [patch] mm: fix lockless pagecache reordering bug (was Re: BUG: soft lockup - is this XFS problem?)
Date: Mon, 5 Jan 2009 11:39:29 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0901051131090.3057@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0901051027011.3057@localhost.localdomain>



On Mon, 5 Jan 2009, Linus Torvalds wrote:
> 
> Either the value can change, or it can not. It's that simple.
> 
> If it cannot change, then we can load it just once, or we can load it 
> multiple times, and it won't matter. Barriers won't do anything but screw 
> up the code.
> 
> If it can change from under us, you need to use rcu_dereference(), or 
> open-code it with an ACCESS_ONCE() or put in barriers. But your placement 
> of a barrier was NONSENSICAL. Your barrier didn't protect anything else - 
> like the test for the RADIX_TREE_INDIRECT_PTR bit.
> 
> And that was the fundamental problem.

Btw, this is the real issue with anything that does "locking vs 
optimistic" accesses.

If you use locking, then by definition (if you did things right), the 
values you are working with do not change. As a result, it doesn't matter 
if the compiler re-orders accesses, splits them up, or coalesces them. 
It's why normal code should never need barriers, because it doesn't matter 
whether some access gets optimized away or gets done multiple times.

But whenever you use an optimistic algorithm, and the data may change 
under you, you need to use barriers or other things to limit the things 
the CPU and/or compiler does.

And yes, "rcu_dereference()" is one such thing - it's not a barrier in the 
sense that it doesn't necessarily affect ordering of accesses to other 
variables around it (although the read_barrier_depends() obviously _is_ a 
very special kind of ordering wrt the pointer itself on alpha). But it 
does make sure that the compiler at least does not coalesce - or split - 
that _one_ particular access.

It's true that it has "rcu" in its name, and it's also true that that may 
be a bit misleading in that it's very much useful not just for rcu, but 
for _any_ algorithm that depends on rcu-like behavior - ie optimistic 
accesses to data that may change underneath it. RCU is just the most 
commonly used (and perhaps best codified) variant of that kind of code.

			Linus

--
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-05 19:40 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-19  6:59 BUG: soft lockup - is this XFS problem? Roman Kononov
2008-12-23 17:12 ` Christoph Hellwig
2008-12-23 17:12   ` Christoph Hellwig
2008-12-30  4:23   ` Nick Piggin
2008-12-30  4:23     ` Nick Piggin
2009-01-03 21:44     ` Christoph Hellwig
2009-01-03 21:44       ` Christoph Hellwig
2009-01-05  1:48       ` Nick Piggin
2009-01-05  1:48         ` Nick Piggin
2009-01-05  4:19         ` Nick Piggin
2009-01-05  4:19           ` Nick Piggin
2009-01-05  6:48           ` Nick Piggin
2009-01-05  6:48             ` Nick Piggin
2009-01-05 14:25             ` Roman Kononov
2009-01-05 14:25               ` Roman Kononov
2009-01-05 16:21             ` Peter Klotz
2009-01-05 16:21               ` Peter Klotz
2009-01-05 16:41               ` [patch] mm: fix lockless pagecache reordering bug (was Re: BUG: soft lockup - is this XFS problem?) Nick Piggin
2009-01-05 16:41                 ` Nick Piggin
2009-01-05 16:41                 ` Nick Piggin
2009-01-05 17:30                 ` Linus Torvalds
2009-01-05 17:30                   ` Linus Torvalds
2009-01-05 17:30                   ` Linus Torvalds
2009-01-05 18:00                   ` Nick Piggin
2009-01-05 18:00                     ` Nick Piggin
2009-01-05 18:00                     ` Nick Piggin
2009-01-05 18:44                     ` Linus Torvalds
2009-01-05 18:44                       ` Linus Torvalds
2009-01-05 18:44                       ` Linus Torvalds
2009-01-05 19:39                       ` Linus Torvalds [this message]
2009-01-05 19:39                         ` Linus Torvalds
2009-01-05 19:39                         ` Linus Torvalds
2009-01-06 17:17                         ` Paul E. McKenney
2009-01-06 17:17                           ` Paul E. McKenney
2009-01-06 17:17                           ` Paul E. McKenney
2009-01-05 20:12                       ` Paul E. McKenney
2009-01-05 20:12                         ` Paul E. McKenney
2009-01-05 20:12                         ` Paul E. McKenney
2009-01-05 20:39                         ` Linus Torvalds
2009-01-05 20:39                           ` Linus Torvalds
2009-01-05 20:39                           ` Linus Torvalds
2009-01-05 21:57                           ` Paul E. McKenney
2009-01-05 21:57                             ` Paul E. McKenney
2009-01-05 21:57                             ` Paul E. McKenney
2009-01-06  2:05                             ` Nick Piggin
2009-01-06  2:05                               ` Nick Piggin
2009-01-06  2:05                               ` Nick Piggin
2009-01-06  2:23                               ` Paul E. McKenney
2009-01-06  2:23                                 ` Paul E. McKenney
2009-01-06  2:23                                 ` Paul E. McKenney
2009-01-06  2:29                               ` Linus Torvalds
2009-01-06  2:29                                 ` Linus Torvalds
2009-01-06  2:29                                 ` Linus Torvalds
2009-01-06  8:38                               ` Peter Klotz
2009-01-06  8:38                                 ` Peter Klotz
2009-01-06  8:38                                 ` Peter Klotz
2009-01-06  8:43                                 ` Nick Piggin
2009-01-06  8:43                                   ` Nick Piggin
2009-01-06  8:43                                   ` Nick Piggin
2009-01-06 16:16                               ` Roman Kononov
2009-01-06 16:16                                 ` Roman Kononov
2009-01-06 16:16                                 ` Roman Kononov
2009-01-05 21:04                         ` [patch] mm: fix lockless pagecache reordering bug (was Peter Zijlstra
2009-01-05 21:04                           ` Peter Zijlstra
2009-01-05 21:04                           ` Peter Zijlstra
2009-01-05 21:58                           ` Paul E. McKenney
2009-01-05 21:58                             ` Paul E. McKenney
2009-01-05 21:58                             ` Paul E. McKenney
2011-07-14 11:23             ` BUG: soft lockup - is this XFS problem? Guus Sliepen
2011-07-14 11:23               ` Guus Sliepen
2011-07-14 18:03               ` Peter Klotz
2011-07-14 18:03                 ` Peter Klotz
2011-07-14 19:29                 ` Guus Sliepen
2011-07-14 19:29                   ` Guus Sliepen

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=alpine.LFD.2.00.0901051131090.3057@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=kernel@kononov.ftml.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@suse.de \
    --cc=peter.klotz@aon.at \
    --cc=stable@kernel.org \
    --cc=xfs@oss.sgi.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 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.