From: Will Deacon <will@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
"Christoph Lameter (Ampere)" <cl@gentwo.org>,
Thomas Gleixner <tglx@linutronix.de>,
Catalin Marinas <catalin.marinas@arm.com>,
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: Mon, 28 Oct 2024 14:10:37 +0000 [thread overview]
Message-ID: <20241028141036.GA2008@willie-the-truck> (raw)
In-Reply-To: <CAHk-=wi=Ji6-xi32167i3M1JL_YyRj6tgUAJS=YQ94GKzMBvkg@mail.gmail.com>
On Wed, Oct 23, 2024 at 01:34:16PM -0700, Linus Torvalds wrote:
> On Wed, 23 Oct 2024 at 12:45, Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > Do we want to do the complementing patch and make write_seqcount_end()
> > use smp_store_release() ?
> >
> > I think at least ARM (the 32bit thing) has wmb but uses mb for
> > store_release. But I also think I don't really care about that.
>
> So unlike the "acquire vs rmb", there are architectures where "wmb" is
> noticeably cheaper than a "store release".
>
> Just as an example, on alpha, a "store release" is a full memory
> barrier followed by the store, because it needs to serialize previous
> loads too. But wmp_wmb() is lightweight.
>
> Typically in traditional (pre acquire/release) architectures "wmb"
> only ordered the CPU write queues, so "wmb" has always been cheap
> pretty much everywhere.
>
> And I *suspect* that alpha isn't the outlier in having a much cheaper
> wmb than store-release.
>
> But yeah, it's kind of ugly how we now have three completely different
> orderings for seqcounts:
>
> - the initial load is done with the smp_read_acquire
>
> - the final load (the "retry") is done with a smp_rmb (because an
> acquire orders _subsequent_ loads, not the ones inside the lock: we'd
> actually want a "smp_load_release()", but such a thing doesn't exist)
>
> - the writer side uses smp_wmb
>
> (and arguably there's a fourth pattern: the latching cases uses double
> smp_wmb, because it orders the sequence count wrt both preceding and
> subsequent stores)
>
> Anyway, obviously on x86 (and s390) none of this matters.
>
> On arm64, I _suspect_ they are mostly the same, but it's going to be
> very microarchitecture-dependent. Neither should be expensive, but wmb
> really is a fundamentally lightweight operation.
I agree here. An STLR additionally orders PO-prior loads on arm64, so
I'd stick with the wmb().
Will
next prev parent reply other threads:[~2024-10-28 14:10 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
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 [this message]
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=20241028141036.GA2008@willie-the-truck \
--to=will@kernel.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=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