From: Haifeng Xu <haifeng.xu@shopee.com>
To: Tang Yizhou <yizhou.tang@shopee.com>
Cc: Waiman Long <longman@redhat.com>,
peterz@infradead.org, mingo@redhat.com, will@kernel.org,
boqun.feng@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] locking/rwsem: Remove unnessary check in rwsem_down_read_slowpath()
Date: Fri, 10 Nov 2023 19:00:33 +0800 [thread overview]
Message-ID: <89bd35a9-ea64-4974-af8e-a033b93d005a@shopee.com> (raw)
In-Reply-To: <CACuPKxnSKQuyWWCtjmmNWP0apja28jWpdYWaKWouArsQA02axQ@mail.gmail.com>
On 2023/11/10 14:54, Tang Yizhou wrote:
> On Thu, Nov 9, 2023 at 11:17 AM Haifeng Xu <haifeng.xu@shopee.com> wrote:
>>
>> reader writer reader
>>
>> acquire
>> release
>> rwsem_write_trylock
>> set RWSEM_WRITER_LOCKED
>> rwsem_down_read_slowpath
>> set owner
>>
>> If prev lock holder is a reader, when it releases the lock, the owner isn't cleared(CONFIG_DEBUG_RWSEMS isn't enabled).
>> A writer comes and can set the RWSEM_WRITER_LOCKED bit succsessfully, then a new reader run into slow path, before
>> the writer set the owner, the new reader will see that both the RWSEM_READER_OWNED bit and RWSEM_WRITER_LOCKED bit are
>> set.
>>
>
> For the above example, it won't cause a problem. When the writer
> successfully sets RWSEM_WRITER_LOCKED, the reader, when reading rcnt
> through rwsem_down_read_slowpath(), will see that rcnt is 0 and will
> jump to the queue label.
>
> Thanks,
> Tang
In this case, rcnt is not 0, it's 1, because rwsem_read_trylock() has add RWSEM_READER_BIAS, so if more than one new reader comes,
it could be the case.
reader writer reader reader
acquire
release
rwsem_write_trylock
set RWSEM_WRITER_LOCKED
rwsem_down_read_slowpath rwsem_down_read_slowpath
... check RWSEM_WRITER_LOCKED bit(rcnt=2)
count = atomic_long_add_return(adjustment, &sem->count);
set owner
prev parent reply other threads:[~2023-11-10 18:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 10:56 Haifeng Xu
2023-11-08 14:04 ` Waiman Long
2023-11-09 3:17 ` Haifeng Xu
2023-11-10 6:54 ` Tang Yizhou
2023-11-10 10:29 ` Haifeng Xu
2023-11-10 13:38 ` Waiman Long
2023-11-10 11:00 ` Haifeng Xu [this message]
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=89bd35a9-ea64-4974-af8e-a033b93d005a@shopee.com \
--to=haifeng.xu@shopee.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
--cc=yizhou.tang@shopee.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®