mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: paulmck@kernel.org
Cc: Frederic Weisbecker <frederic@kernel.org>,
	boqun.feng@gmail.com, neeraj.iitr10@gmail.com, urezki@gmail.com,
	rcu@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC] srcu: Yet more detail for srcu_readers_active_idx_check() comments
Date: Thu, 15 Dec 2022 17:16:45 -0500	[thread overview]
Message-ID: <826527A4-42E6-48AB-80C9-FEC0F330F0BE@joelfernandes.org> (raw)
In-Reply-To: <20221215221014.GR4001@paulmck-ThinkPad-P17-Gen-1>



> On Dec 15, 2022, at 5:10 PM, Paul E. McKenney <paulmck@kernel.org> wrote:
> 
> On Thu, Dec 15, 2022 at 04:42:15PM -0500, Joel Fernandes wrote:
>> 
>> 
>>>> On Dec 15, 2022, at 4:39 PM, Paul E. McKenney <paulmck@kernel.org> wrote:
>>> 
>>> On Thu, Dec 15, 2022 at 03:33:39PM -0500, Joel Fernandes wrote:
>>>>> On Thu, Dec 15, 2022 at 3:03 PM Joel Fernandes <joel@joelfernandes.org> wrote:
>>>>> 
>>>>> Hi Paul,
>>>>> 
>>>>>> On Thu, Dec 15, 2022 at 2:58 PM Paul E. McKenney <paulmck@kernel.org> wrote:
>>>>> [...]
>>>>>>> If the first read section's srcu_read_unlock() and its corresponding
>>>>>>> smp_mb()  happened before the flip, then the increment of old idx
>>>>>>> would happen only once. The next srcu_read_lock() will read the new
>>>>>>> index. If the srcu_read_unlock() and it's corresponding smp_mb()
>>>>>>> happened after the flip, the old_idx will be sampled again and can be
>>>>>>> incremented twice. So it depends on how the flip races with
>>>>>>> srcu_read_unlock().
>>>>>> 
>>>>>> I do understand that a number of people like reasoning about
>>>>>> memory-barrier ordering, courtesy of the sequentially consistent portions
>>>>>> of the C and C++ memory models, but thinking in terms of the accesses
>>>>>> surrounding the memory barriers has been far less error-prone.
>>>>> 
>>>>> Sure, but we are already talking in terms of the access to idx right?
>>>>> That's what we're saying is visible by memory barriers and we are
>>>>> trying to reason here about the ordering (flip does the write to idx
>>>>> and followed by smp_mb(), and there is corresponding read of idx on
>>>>> the srcu_read_lock() side. So we are indeed talking in terms of
>>>>> access, but let me know if I missed something.
>>>>> 
>>>>>>> Also, since this is all hard to reason about I started making some
>>>>>>> diagrams, LOL. For your amusement, here is why need to scan both idx
>>>>>>> during grace period detection: https://i.imgur.com/jz4bNKd.png
>>>>>> 
>>>>>> Nice!
>>>>>> 
>>>>>> I suggest placing a gap between GP 2 and GP 3.  That way, you can make it
>>>>>> very clear that Reader 1's critical section starts after the end of GP 2
>>>>>> (thus clearly never blocking GP 2) and before GP 3 (thus possibly having
>>>>>> a reference to some data that is going to be freed at the end of GP 3).
>>>>>> 
>>>>>> I also suggest coloring Reader 1 red and Reader 2 green, given that the
>>>>>> color red generally indicates danger.
>>>>> 
>>>>> Thanks for these suggestions! I will make the update. I am planning to
>>>>> make a number of diagrams for other scenarios as well, as it helps
>>>>> visualize. Google drawing is nice for these. I am happy to share these
>>>>> with you all if there is interest :).
>>>> 
>>>> I made these updates, please see: https://i.imgur.com/hoKLvtt.png
>>>> 
>>>> Feel free to use the image for any purpose and thanks ;-)
>>> 
>>> Very good, thank you!
>>> 
>>> Would it be possible to have an arrow marked "X" or "reference to X"
>>> from the beginning of the 'Mark "x" for GC' box to the box labeled
>>> 'Enter RSCS (access "X")'?
>> 
>> I am currently away from desk. I shared the google drawing with you. Could you check and make the change, if that’s ok with you?
>> 
>> Thank you so much,
> 
> I took a cut at it.  Thoughts?

Yes perfect now :) and handy future reference! Thanks!

- Joel

> 
>                            Thanx, Paul

  reply	other threads:[~2022-12-15 22:17 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 19:13 Paul E. McKenney
2022-12-14 20:51 ` Joel Fernandes
2022-12-14 21:24   ` Paul E. McKenney
2022-12-14 23:07     ` Joel Fernandes
2022-12-14 23:10       ` Joel Fernandes
2022-12-14 23:14         ` Joel Fernandes
2022-12-15  0:04           ` Paul E. McKenney
2022-12-15  1:34             ` Joel Fernandes
2022-12-15  1:39               ` Paul E. McKenney
2022-12-15  0:01       ` Paul E. McKenney
2022-12-15 16:54 ` Frederic Weisbecker
2022-12-15 17:08   ` Paul E. McKenney
2022-12-15 17:48     ` Joel Fernandes
2022-12-15 17:58       ` Joel Fernandes
2022-12-15 20:13         ` Paul E. McKenney
2022-12-15 22:13           ` Joel Fernandes
2022-12-15 22:22             ` Joel Fernandes
2022-12-16  1:13               ` Paul E. McKenney
2022-12-16  1:09             ` Paul E. McKenney
2022-12-16 16:32               ` Joel Fernandes
2022-12-16 16:39                 ` Joel Fernandes
2022-12-16 16:51                 ` Paul E. McKenney
2022-12-16 16:54                   ` Joel Fernandes
2022-12-16 17:13                     ` Paul E. McKenney
2022-12-17  3:19                     ` Joel Fernandes
2022-12-17  3:21                       ` Joel Fernandes
2022-12-17  5:15                         ` Paul E. McKenney
2022-12-17  6:32                           ` Joel Fernandes
2022-12-15 19:58       ` Paul E. McKenney
2022-12-15 20:03         ` Joel Fernandes
2022-12-15 20:33           ` Joel Fernandes
2022-12-15 21:39             ` Paul E. McKenney
2022-12-15 21:42               ` Joel Fernandes
2022-12-15 22:10                 ` Paul E. McKenney
2022-12-15 22:16                   ` Joel Fernandes [this message]
2022-12-15 17:58     ` Frederic Weisbecker
2022-12-15 18:53       ` Paul E. McKenney

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=826527A4-42E6-48AB-80C9-FEC0F330F0BE@joelfernandes.org \
    --to=joel@joelfernandes.org \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neeraj.iitr10@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=urezki@gmail.com \
    /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

all inboxes | Powered by JetHome®