From: David Howells <dhowells@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: dhowells@redhat.com, Marc Dionne <marc.dionne@auristor.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Chuck Lever <chuck.lever@oracle.com>,
linux-afs@lists.infradead.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rxrpc_find_service_conn_rcu: use read_seqbegin() rather than read_seqbegin_or_lock()
Date: Wed, 01 Nov 2023 15:45:16 +0000 [thread overview]
Message-ID: <1952182.1698853516@warthog.procyon.org.uk> (raw)
In-Reply-To: <20231027095842.GA30868@redhat.com>
Oleg Nesterov <oleg@redhat.com> wrote:
> read_seqbegin_or_lock() makes no sense unless you make "seq" odd
> after the lockless access failed.
I think you're wrong.
write_seqlock() turns it odd. For instance, if the read lock is taken first:
sequence seq CPU 1 CPU 2
======= ======= =============================== ===============
0
0 0 seq = 0 // MUST BE EVEN ACCORDING TO DOC
0 0 read_seqbegin_or_lock() [lockless]
...
1 0 write_seqlock()
1 0 need_seqretry() [seq=even; sequence!=seq: retry]
1 1 read_seqbegin_or_lock() [exclusive]
-->spin_lock(lock);
2 1 write_sequnlock()
<--locked
...
2 1 need_seqretry()
However, if the write lock is taken first:
sequence seq CPU 1 CPU 2
======= ======= =============================== ===============
0
1 write_seqlock()
1 0 seq = 0 // MUST BE EVEN ACCORDING TO DOC
1 0 read_seqbegin_or_lock() [lockless]
1 0 __read_seqcount_begin()
while (lock.sequence is odd)
cpu_relax();
2 0 write_sequnlock()
2 2 [loop end]
...
2 2 need_seqretry() [seq=even; sequence==seq; done]
Note that it spins in __read_seqcount_begin() until we get an even seq,
indicating that no write is currently in progress - at which point we can
perform a lockless pass.
> See thread_group_cputime() as an example, note that it does nextseq = 1 for
> the 2nd round.
That's not especially convincing.
David
next prev parent reply other threads:[~2023-11-01 15:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-27 9:58 [PATCH] rxrpc_find_service_conn_rcu: use read_seqbegin() rather than read_seqbegin_or_lock() Oleg Nesterov
2023-10-27 10:00 ` Oleg Nesterov
2023-11-01 15:45 ` David Howells [this message]
2023-11-01 20:23 ` Oleg Nesterov
2023-11-01 20:40 ` Oleg Nesterov
2023-11-01 21:22 ` David Howells
2023-11-01 22:38 ` Oleg Nesterov
2023-11-01 20:52 ` Al Viro
2023-11-01 21:52 ` Oleg Nesterov
2023-11-01 22:48 ` Al Viro
2023-11-01 23:17 ` Oleg Nesterov
2023-11-01 21:20 ` David Howells
2023-11-01 22:15 ` Oleg Nesterov
2023-11-01 22:29 ` Oleg Nesterov
2023-11-16 13:18 ` Oleg Nesterov
2023-11-16 13:41 ` David Howells
2023-11-16 14:19 ` Oleg Nesterov
2023-11-16 15:02 ` David Howells
2023-11-16 15:06 ` Oleg Nesterov
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=1952182.1698853516@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.dionne@auristor.com \
--cc=netdev@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=pabeni@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.