From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Christoph Lameter <cl@gentwo.org>
Cc: Tejun Heo <tj@kernel.org>, David Howells <dhowells@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC] percpu: add data dependency barrier in percpu accessors and operations
Date: Tue, 17 Jun 2014 12:40:17 -0700 [thread overview]
Message-ID: <20140617194017.GO4669@linux.vnet.ibm.com> (raw)
In-Reply-To: <alpine.DEB.2.11.1406171401350.22064@gentwo.org>
On Tue, Jun 17, 2014 at 02:27:43PM -0500, Christoph Lameter wrote:
> On Thu, 12 Jun 2014, Tejun Heo wrote:
>
> > percpu areas are zeroed on allocation and, by its nature, accessed
> > from multiple cpus. Consider the following scenario.
>
> I am not sure that the premise is actually right. Percpu areas are
> designed to be accessed from a single cpu and we provide instances
> of variables for each cpu.
>
> There is no synchronization guarantee for accesses from other cpu. If
> these accesses occur then we tolerate some fuzziness and usualy only do
> read accesses. F.e. for statistics if we loop over all cpus to get a sum
> of percpu counters (which is a classic use case for percpu data).
>
> But there are numerous uses where no accesses from other cpus are required
> (mostly when percpu stuff is not used for statistics but for cpu local
> lists and status).
>
> Cross cpu write accesses typically occur only after the allocation and
> before the code that actually does something is aware of the existence of
> the percpu area allocated or if the processor is being offlines/onlines.
>
> > > p = NULL; >
> > CPU-1 CPU-2
> > p = alloc_percpu() if (p)
> > WARN_ON(this_cpu_read(*p));
>
> p is an offset into the per cpu area of the processor. The value of P
> first has to be made available to cpu2 somehow and this usually provides
> the opportunity for synchronization that avoids the above scenario.
>
> And so it is typical that these offsets are stored in larger structs that
> also have other means of synchronization.
>
> F.e. Allocators take a global lock and then instantiate a new
> structure with the associated per cpu area allocation which is added to a
> global list after it is ready. The address of the allocator structure
> is then made available to other processors.
>
> Another method is to perform this allocation on bootup which then also
> does not require synchronization (page allocator).
>
> Similar in swapon(). The percpu allocation is performed before access to
> the containing structure (via enable_swap_info).
Those are indeed common use cases. However...
There is code where one CPU writes to another CPU's per-CPU variables.
One example is RCU callback offloading, where a kernel thread (which
might be running anywhere) dequeues a given CPU's RCU callbacks and
processes them. The act of dequeuing requires write access to that
CPU's per-CPU rcu_data structure. And yes, atomic operations and memory
barriers are of course required to make this work.
Thanx, Paul
next prev parent reply other threads:[~2014-06-17 19:40 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
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 [this message]
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=20140617194017.GO4669@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=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