public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christoph Lameter <cl@gentwo.org>,
	Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Rusty Russell <rusty@rustcorp.com.au>, Tejun Heo <tj@kernel.org>,
	David Howells <dhowells@redhat.com>,
	Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH RFC] percpu: add data dependency barrier in percpu accessors and operations
Date: Tue, 15 Jul 2014 10:45:19 -0700	[thread overview]
Message-ID: <20140715174519.GH8690@linux.vnet.ibm.com> (raw)
In-Reply-To: <CA+55aFxU166V5-vH4vmK9OBdTZKyede=71RjjbOVSN9Qh+Se+A@mail.gmail.com>

On Tue, Jul 15, 2014 at 10:32:13AM -0700, Linus Torvalds wrote:
> On Jul 15, 2014 9:12 AM, "Christoph Lameter" <cl@gentwo.org> wrote:
> >
> > I mentioned that there is a barrier because the process of handing over
> > the offset to the other includes synchronization. In the slab case this is
> > a semaphore that is use to protect the structure and the list of
> > kmem_cache structures. The control struct containing the offset must be
> > entered somehow into something that tracks it for the future and thus
> > there is synchronization by the subsytem.
> 
> Maybe. It's not at all obvious, though. That control structure may be a
> lockless percpu thing, after all. We have front end caches to the
> allocators etc..
> 
> So yes, if there is a lock+unlock, that can be a memory barrier - but even
> that is not necessarily true on all architectures.
> 
> Is there even always one, though? And what about the other CPU? Does it
> have any paired barrier?
> 
> > And now we still see the old data. The cacheline changes of the initial
> > processor are ignored?
> 
> They aren't "ignored". But without the proper barriers, the zeroing writes
> may still be buffered on the other CPU, and may not even have had a cache
> line allocated to them!
> 
> That's the kind of thing that makes a barrier possibly required.
> 
> But yes, the barrier may be implied by other synchronization if that
> exists. A lock doesn't necessarily help, though. A write before a lock can
> migrate down into the locked region, and a write after the lock may
> similarly migrate into the locked region, and then two such writes may be
> seen out of order on another CPU that doesn't take the lock itself to
> serialize.
> 
> See? It's those kinds of things that can cause really subtle memory
> ordering problems. We generally never see them on x86, since writes are
> always ordered against other writes, and reads are allays ordered wrt other
> reads (but not reads against writes) and all locks are full memory barriers.
> 
> But on other architectures even a lock+unlock may not be a barrier, since
> things moving into the locked region is fine (the lock means that things
> had better not move *out* of s locked region).
> 
> So depending on serialization may not always be all that obvious. Even if
> it does happen to all work on x86.
> 
> And don't get me wrong. I despise weak memory models. I think they are a
> mistake. I absolutely detest the alpha model, and I think PowerPC and ARM
> are wrong too. It's just that we have to try to care about their broken
> crap )^:

Well at least all the required barriers are free on TSO systems like
x86 and mainframe, and the read-side barriers are free evne on ARM and
PowerPC (not so much on DEC Alpha, but you can't have everything).  OK,
OK, there is a volatile cast and/or a barrier() directive that might
constrain the compiler a bit in some cases.

So this might well be crap, but at least it is (nearly) zero-cost crap
from the viewpoint of TSO machines like x86.  ;-)

							Thanx, Paul


  parent reply	other threads:[~2014-07-15 17:45 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-12 13:56 [PATCH RFC] percpu: add data dependency barrier in percpu accessors and operations Tejun Heo
2014-06-12 15:34 ` Paul E. McKenney
2014-06-12 15:52   ` Tejun Heo
2014-06-17 14:41     ` Paul E. McKenney
2014-06-17 15:27       ` Tejun Heo
2014-06-17 15:56         ` Christoph Lameter
2014-06-17 16:00           ` Tejun Heo
2014-06-17 16:05             ` Tejun Heo
2014-06-17 16:28               ` Christoph Lameter
     [not found]                 ` <CA+55aFxHr8JXwDR-4g4z1mkXvZRtY=OosYcUMPZRD2upfooS1w@mail.gmail.com>
2014-06-17 18:47                   ` Christoph Lameter
2014-06-17 18:55                     ` Paul E. McKenney
2014-06-17 19:39                       ` Christoph Lameter
2014-06-17 19:47                         ` Tejun Heo
2014-06-17 19:56                         ` Paul E. McKenney
2014-06-19 20:39                           ` Christoph Lameter
2014-06-17 16:57         ` Paul E. McKenney
2014-06-17 18:56           ` Tejun Heo
2014-06-17 19:42             ` Christoph Lameter
2014-06-17 20:44               ` Tejun Heo
2014-07-09  0:55         ` Rusty Russell
2014-07-14 11:39           ` Paul E. McKenney
2014-07-14 15:22             ` Christoph Lameter
2014-07-15 10:11               ` Paul E. McKenney
2014-07-15 14:06                 ` Christoph Lameter
2014-07-15 14:32                   ` Paul E. McKenney
2014-07-15 15:06                     ` Christoph Lameter
2014-07-15 15:41                       ` Linus Torvalds
2014-07-15 16:12                         ` Christoph Lameter
     [not found]                           ` <CA+55aFxU166V5-vH4vmK9OBdTZKyede=71RjjbOVSN9Qh+Se+A@mail.gmail.com>
2014-07-15 17:45                             ` Paul E. McKenney [this message]
2014-07-15 17:41                       ` Paul E. McKenney
2014-07-16 14:40                         ` Christoph Lameter
2014-07-15 11:50             ` Rusty Russell
2014-06-17 19:27 ` Christoph Lameter
2014-06-17 19:40   ` Paul E. McKenney
2014-06-19 20:42     ` Christoph Lameter
2014-06-19 20:46       ` Tejun Heo
2014-06-19 21:11         ` Christoph Lameter
2014-06-19 21:15           ` Tejun Heo
2014-06-20 15:23             ` Christoph Lameter
2014-06-20 15:52               ` Tejun Heo
2014-06-19 20:51       ` Paul E. McKenney
2014-06-20 15:29         ` Christoph Lameter
2014-06-20 15:50           ` Paul E. McKenney

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=20140715174519.GH8690@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=tj@kernel.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