From: Linus Torvalds <torvalds@linux-foundation.org>
To: "Christoph Lameter (Ampere)" <cl@gentwo.org>
Cc: Will Deacon <will@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Catalin Marinas <catalin.marinas@arm.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Waiman Long <longman@redhat.com>,
Boqun Feng <boqun.feng@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-arch@vger.kernel.org
Subject: Re: [PATCH v3] Avoid memory barrier in read_seqcount() through load acquire
Date: Wed, 18 Sep 2024 17:22:17 +0200 [thread overview]
Message-ID: <CAHk-=wgw3UErQuBuUOOfjzejGek6Cao1sSW4AosR9WPZ1dfyZg@mail.gmail.com> (raw)
In-Reply-To: <4b546151-d5e1-22a3-a6d5-167a82c5724d@gentwo.org>
On Wed, 18 Sept 2024 at 13:15, Christoph Lameter (Ampere) <cl@gentwo.org> wrote:
>
> Other arches do not have acquire / release and will create additional
> barriers in the fallback implementation of smp_load_acquire. So it needs
> to be an arch config option.
Actually, I looked at a few cases, and it doesn't really seem to be true.
For example, powerpc doesn't have a "native" acquire model, but both
smp_load_acquire() and smp_rmb() end up being LWSYNC after the load
(which in the good case is a "lwsync" instruction, in bad case it's a
heavier "sync" instruction on older cores, but the point is that it's
the same thing for smp_rmb() and for smp_load_acquire()).
So on powerpc, smp_load_acquire() isn't any better than
"READ_ONCE()+smp_rmb()", but it also isn't any worse.
And at least alpha is the same - it doesn't have smp_load_acquire(),
and it falls back on a full memory barrier for that case - but that's
what smp_rmb() is too. However, because READ_ONCE() on alpha already
contains a smp_mb(), it turns out that on alpha having "READ_ONCE +
smp_rmb()" actually results in *two* barriers, while a
"smp_load_acquire()" is just one.
And obviously technically x86 doesn't have explicit acquire, but with
every load being an acquire, it's a no-op either way.
So on at least three very different architectures, smp_load_acquire()
is at least no worse than READ_ONCE() followed by a smp_rmb(). And on
alpha and arm64, it's better.
So it does look like making it conditional doesn't actually buy us
anything. We might as well just unconditionally use the
smp_load_acquire() over "READ_ONCE+smp_rmb".
Other random architectures from a quick look:
RISC-V technically turns smp_rmb() into a "fence r,r", while a
smp_load_acquire() ends up being a "fence r,rw", so technically the
fences are different. But honestly, any microarchitecture that makes
those two be different is just crazy garbage (there's never any valid
reason to move later writes up before earlier reads).
Loongarch has acquire and is better off with it.
parisc has acquire and is better off with it.
s390 and sparc64 are like x86, in that it's just a build barrier either way.
End result: let's just simplify the patch and make it entirely unconditional.
Linus
next prev parent reply other threads:[~2024-09-18 15:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-12 22:44 Christoph Lameter via B4 Relay
2024-09-13 13:41 ` kernel test robot
2024-09-16 17:52 ` Christoph Lameter (Ampere)
2024-09-17 7:37 ` Will Deacon
2024-09-17 11:50 ` Thomas Gleixner
2024-09-18 0:45 ` Vivi, Rodrigo
2024-09-13 13:41 ` kernel test robot
2024-09-17 7:12 ` Will Deacon
2024-09-18 11:03 ` Christoph Lameter (Ampere)
2024-09-18 15:22 ` Linus Torvalds [this message]
2024-09-23 16:28 ` Linus Torvalds
2024-10-23 19:45 ` Peter Zijlstra
2024-10-23 20:34 ` Linus Torvalds
2024-10-28 14:10 ` Will Deacon
2024-10-23 23:42 ` Christoph Lameter (Ampere)
2024-10-25 7:42 ` Peter Zijlstra
2024-10-25 19:30 ` Christoph Lameter (Ampere)
2024-09-17 11:52 ` Thomas Gleixner
2024-09-18 11:11 ` Christoph Lameter (Ampere)
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='CAHk-=wgw3UErQuBuUOOfjzejGek6Cao1sSW4AosR9WPZ1dfyZg@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=boqun.feng@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.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