public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Waiman Long <llong@redhat.com>
Cc: Boqun Feng <boqun.feng@gmail.com>,
	David Howells <dhowells@redhat.com>,
	Ingo Molnar <mingo@redhat.com>,
	Li RongQing <lirongqing@baidu.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Will Deacon <will@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] documentation: seqlock: fix the wrong documentation of read_seqbegin_or_lock/need_seqretry
Date: Wed, 1 Oct 2025 21:06:26 +0200	[thread overview]
Message-ID: <20251001190625.GA32506@redhat.com> (raw)
In-Reply-To: <b83e9c1d-2623-4abf-8c63-1110a0b92d2e@redhat.com>

On 10/01, Waiman Long wrote:
>
> On 9/28/25 12:20 PM, Oleg Nesterov wrote:
> >
> >--- a/Documentation/locking/seqlock.rst
> >+++ b/Documentation/locking/seqlock.rst
> >@@ -218,13 +218,14 @@ Read path, three categories:
> >     according to a passed marker. This is used to avoid lockless readers
> >     starvation (too much retry loops) in case of a sharp spike in write
> >     activity. First, a lockless read is tried (even marker passed). If
> >-   that trial fails (odd sequence counter is returned, which is used as
> >-   the next iteration marker), the lockless read is transformed to a
> >-   full locking read and no retry loop is necessary::
> >+   that trial fails (sequence counter doesn't match), make the marker
> >+   odd for the next iteration, the lockless read is transformed to a
> >+   full locking read and no retry loop is necessary, for example::
> >  	/* marker; even initialization */
> >-	int seq = 0;
> >+	int seq = 1;
> >  	do {
> >+		seq++; /* 2 on the 1st/lockless path, otherwise odd */
> >  		read_seqbegin_or_lock(&foo_seqlock, &seq);
> >  		/* ... [[read-side critical section]] ... */
>
> It is kind of odd to initialize the sequence to 1 and add an sequence
> increment inside the loop.

Sure. But a) in this patch my only point is that the current documentation is
wrong, and b) the pseudo-code after this change becomes correct and the new
pattern already have the users. For example, do_io_accounting() and more.

> Perhaps we can do something like:

Perhaps. But could you please read the "RFC 2/1" thread? To me it is kind of
odd that the simple loops like this example have to even touch the sequence
counter inside the loop.

> +static inline int need_seqretry_once(seqlock_t *lock, int *seq)
> +{
> +       int ret = !(*seq & 1) && read_seqretry(lock, *seq);
> +
> +       if (ret)
> +               *seq = 1;       /* Enforce locking in next iteration */
> +       return ret;
> +}

And this is exactly what I tried to propose in "RFC 2/1". Plus more...

Oleg.


  reply	other threads:[~2025-10-01 19:07 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-28 16:19 [PATCH 0/1] documentation: seqlock: fix the wrong documentation of read_seqbegin_or_lock/need_seqretry Oleg Nesterov
2025-09-28 16:20 ` [PATCH 1/1] " Oleg Nesterov
2025-10-01 18:21   ` Waiman Long
2025-10-01 19:06     ` Oleg Nesterov [this message]
2025-10-01 19:24       ` Waiman Long
2025-10-01 19:34         ` Waiman Long
2025-10-02 11:01     ` Oleg Nesterov
2025-10-21 10:35   ` [tip: locking/core] " tip-bot2 for Oleg Nesterov
2025-09-28 16:20 ` [RFC 2/1] seqlock: make the read_seqbegin_or_lock() API more simple and less error-prone ? Oleg Nesterov
2025-09-29  0:41   ` [????] " Li,Rongqing
2025-09-29  6:47     ` Oleg Nesterov
2025-09-30 22:09   ` David Howells
2025-10-01 11:51     ` Oleg Nesterov
2025-10-01 13:02   ` Peter Zijlstra
2025-10-01 13:13     ` Oleg Nesterov
2025-10-01 13:46       ` Oleg Nesterov
2025-10-02 12:58       ` Oleg Nesterov
2025-10-05 14:47 ` [PATCH 0/5] seqlock: introduce SEQLOCK_READ_SECTION() Oleg Nesterov
2025-10-05 14:49 ` Oleg Nesterov
2025-10-05 14:50   ` [PATCH 1/5] " Oleg Nesterov
2025-10-05 15:34     ` Linus Torvalds
2025-10-05 16:07       ` Oleg Nesterov
2025-10-05 16:35         ` Linus Torvalds
2025-10-05 14:50   ` [PATCH 2/5] seqlock: change thread_group_cputime() to use SEQLOCK_READ_SECTION() Oleg Nesterov
2025-10-05 14:50   ` [PATCH 3/5] seqlock: change do_task_stat() " Oleg Nesterov
2025-10-05 14:50   ` [PATCH 4/5] seqlock: change do_io_accounting() " Oleg Nesterov
2025-10-05 14:50   ` [PATCH 5/5] seqlock: change __dentry_path() to use __SEQLOCK_READ_SECTION() Oleg Nesterov
2025-10-05 15:48     ` Linus Torvalds
2025-10-05 15:30   ` [PATCH 0/5] seqlock: introduce SEQLOCK_READ_SECTION() Al Viro
2025-10-05 17:40     ` Oleg Nesterov
2025-10-07 14:20 ` [PATCH 0/4] seqlock: introduce scoped_seqlock_read() and scoped_seqlock_read_irqsave() Oleg Nesterov
2025-10-07 14:21   ` [PATCH 1/4] " Oleg Nesterov
2025-10-07 16:35     ` Waiman Long
2025-10-07 17:18       ` Oleg Nesterov
2025-10-07 17:21         ` Waiman Long
2025-10-07 14:21   ` [PATCH 2/4] seqlock: change thread_group_cputime() to use scoped_seqlock_read_irqsave() Oleg Nesterov
2025-10-07 14:21   ` [PATCH 3/4] seqlock: change do_task_stat() " Oleg Nesterov
2025-10-07 14:21   ` [PATCH 4/4] seqlock: change do_io_accounting() " Oleg Nesterov
2025-10-07 15:38   ` [PATCH 0/4] seqlock: introduce scoped_seqlock_read() and scoped_seqlock_read_irqsave() Linus Torvalds
2025-10-07 16:34     ` Oleg Nesterov
2025-10-08 12:30 ` [PATCH v2 " Oleg Nesterov
2025-10-08 12:30   ` [PATCH v2 1/4] " Oleg Nesterov
2025-10-08 12:55     ` Peter Zijlstra
2025-10-08 12:59       ` Oleg Nesterov
2025-10-08 13:54         ` Peter Zijlstra
2025-10-08 16:05     ` Linus Torvalds
2025-10-08 16:55       ` Oleg Nesterov
2025-10-09  5:31       ` Linus Torvalds
2025-10-09  7:04         ` Linus Torvalds
2025-10-09 14:37           ` Oleg Nesterov
2025-10-09 16:18             ` Linus Torvalds
2025-10-09 19:50             ` Peter Zijlstra
2025-10-09 20:11               ` Peter Zijlstra
2025-10-09 20:24                 ` Linus Torvalds
2025-10-09 22:12                   ` Peter Zijlstra
2025-10-09 22:55                     ` Linus Torvalds
2025-10-10  8:03                       ` Peter Zijlstra
2025-10-10 12:32                         ` Oleg Nesterov
2025-10-10 13:14                           ` Oleg Nesterov
2025-10-13  9:03                             ` Peter Zijlstra
2025-10-13 11:50                               ` Oleg Nesterov
2025-10-10 15:30                           ` Linus Torvalds
2025-10-09 23:20                     ` Peter Zijlstra
2025-10-09 23:26                       ` Linus Torvalds
2025-10-21 10:35                 ` [tip: locking/core] seqlock: Introduce scoped_seqlock_read() tip-bot2 for Peter Zijlstra
2025-10-08 12:30   ` [PATCH v2 2/4] seqlock: change thread_group_cputime() to use scoped_seqlock_read_irqsave() Oleg Nesterov
2025-10-21 10:35     ` [tip: locking/core] seqlock: Change thread_group_cputime() to use scoped_seqlock_read() tip-bot2 for Oleg Nesterov
2025-10-08 12:30   ` [PATCH v2 3/4] seqlock: change do_task_stat() to use scoped_seqlock_read_irqsave() Oleg Nesterov
2025-10-21 10:35     ` [tip: locking/core] seqlock: Change do_task_stat() to use scoped_seqlock_read() tip-bot2 for Oleg Nesterov
2025-10-08 12:31   ` [PATCH v2 4/4] seqlock: change do_io_accounting() to use scoped_seqlock_read_irqsave() Oleg Nesterov
2025-10-21 10:35     ` [tip: locking/core] seqlock: Change do_io_accounting() to use scoped_seqlock_read() tip-bot2 for Oleg Nesterov
2025-10-08 12:56   ` [PATCH v2 0/4] seqlock: introduce scoped_seqlock_read() and scoped_seqlock_read_irqsave() Peter Zijlstra
2025-10-08 13:13     ` Oleg Nesterov
2025-10-08 13:55       ` Peter Zijlstra

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=20251001190625.GA32506@redhat.com \
    --to=oleg@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=llong@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --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