From: Trond Myklebust <trondmy@hammerspace.com>
To: "bfields@fieldses.org" <bfields@fieldses.org>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH] SUNRPC: Don't allow compiler optimisation of svc_xprt_release_slot()
Date: Tue, 8 Jan 2019 16:21:40 +0000 [thread overview]
Message-ID: <4077991d3d3acee4c37c7c8c6dc2b76930c9584e.camel@hammerspace.com> (raw)
In-Reply-To: <20190108150107.GA15921@fieldses.org>
On Tue, 2019-01-08 at 10:01 -0500, bfields@fieldses.org wrote:
> On Mon, Jan 07, 2019 at 10:06:19PM +0000, Trond Myklebust wrote:
> > On Mon, 2019-01-07 at 16:32 -0500, bfields@fieldses.org wrote:
> > > So maybe we actually need
> > >
> > > static bool (struct svc_xprt *xprt)
> > > {
> > > + mb();
> >
> > You would at best need a 'smp_rmb()'. There is nothing to gain from
> > adding a write barrier here,
>
> That's not my understanding.
>
> What we have is basically:
>
> 1 2
> ---- ----
> WRITE to A WRITE to B
>
> READ from A and B READ from A and B
>
> and we want to guarantee that at least one of those two reads will
> see
> both of the writes.
>
> A read barrier only orders reads with respect to the barrier, it
> doesn't
> do anything about writes, so doesn't guarantee anything here.
In this context 'WRITE to A' and/or 'WRITE to B' are presumably the
operations of setting the flag bits in xprt->xpt_flags, no? That's not
occurring here, it is occurring elsewhere.
The test_and_set_bit(XPT_DATA, &xprt->xpt_flags) in svc_data_ready()
performs an explicit barrier, so we shouldn't really care. The other
cases where we do set_bit(XPT_DATA) don't matter since the socket has
its own locking, and so the XPT_DATA is really just a test for whether
or not we need to enqueue the svc_xprt.
In the only place where XPT_DEFERRED is set, you have an implicit write
barrier (due to a spin_unlock) between the call to set_bit() and the
call to svc_xprt_enqueue(), so all data writes are guaranteed to be
complete before any attempt to enqueue the socket.
I can't see that you really care for the case of XPT_CONN, since the
just-created socket isn't going to be visible to other cpus until
you've added it to &pool->sp_sockets (which also has implicit write
barriers due to spin locks).
I don't think you really care for the case of XPT_CLOSE either since
svc_delete_xprt() doesn't depend on any other data writes that aren't
already protected by spinlocks.
So the conclusion would be to add smp_rmb() in
svc_xprt_has_something_to_do(). No extra write barriers are needed
AFAICS.
You may still need the READ_ONCE() in order to add a data dependency
barrier (i.e. to ensure that alpha processors don't reorder reads of
the xpt_flags with other speculative reads). That should reduce to a
standard read on all non-alpha architectures.
>
> --b.
>
>
>
> > and you don't even need a read barrier in
> > the non-smp case.
> >
> > > if (xprt->xpt_flags & ((1<<XPT_CONN)|(1<<XPT_CLOSE)))
> > > return true;
> > > if (xprt->xpt_flags & ((1<<XPT_DATA)|(1<<XPT_DEFERRED))) {
> > >
> > > Then whichever memory barrier executes second guarantees that the
> > > following check sees the result of both the XPT_DATA and
> > > xpt_nr_rqsts
> > > changes. I think....
> >
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com
next prev parent reply other threads:[~2019-01-08 16:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-03 14:17 [PATCH] SUNRPC: Don't allow compiler optimisation of svc_xprt_release_slot() Trond Myklebust
2019-01-03 22:45 ` J Bruce Fields
2019-01-03 23:40 ` Trond Myklebust
2019-01-04 17:39 ` bfields
2019-01-07 21:32 ` bfields
2019-01-07 22:06 ` Trond Myklebust
2019-01-08 15:01 ` bfields
2019-01-08 16:21 ` Trond Myklebust [this message]
2019-01-09 16:51 ` bfields
2019-01-09 17:41 ` Trond Myklebust
2019-01-11 21:12 ` bfields
2019-01-11 21:52 ` Chuck Lever
2019-01-11 21:54 ` Chuck Lever
2019-01-11 22:10 ` Bruce Fields
2019-01-11 22:27 ` Chuck Lever
2019-01-12 0:56 ` Bruce Fields
2019-01-14 17:24 ` Chuck Lever
2019-01-25 20:30 ` Bruce Fields
2019-01-25 21:32 ` Chuck Lever
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=4077991d3d3acee4c37c7c8c6dc2b76930c9584e.camel@hammerspace.com \
--to=trondmy@hammerspace.com \
--cc=bfields@fieldses.org \
--cc=linux-nfs@vger.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;
as well as URLs for NNTP newsgroup(s).