mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Haifeng Xu <haifeng.xu@shopee.com>
Cc: 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: Wed, 8 Nov 2023 09:04:48 -0500	[thread overview]
Message-ID: <6da49b39-653a-1eda-2d21-1f1b50cb14f0@redhat.com> (raw)
In-Reply-To: <20231108105639.70088-1-haifeng.xu@shopee.com>

On 11/8/23 05:56, Haifeng Xu wrote:
> When the owner of rw_semaphore is reader, the count can't be
> RWSEM_WRITER_LOCKED, so there is no need to check it.
>
> Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
> ---
>   kernel/locking/rwsem.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 2340b6d90ec6..7a4d8a9ebd9c 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -1005,8 +1005,7 @@ rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, unsigned int stat
>   	 * waiter, don't attempt optimistic lock stealing if the lock is
>   	 * currently owned by readers.
>   	 */
> -	if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
> -	    (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))
> +	if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) && (rcnt > 1))
>   		goto queue;
>   
>   	/*

Unlike RWSEM_WRITER_LOCKED bit in count, the RWSEM_READER_OWNED bit in 
owner is just a hint, not an authoritative state of the rwsem. So it is 
possible that both the RWSEM_READER_OWNED bit can be set in owner and 
RWSEM_WRITER_LOCKED bit set in count in a transition period right after 
RWSEM_WRITER_LOCKED bit is set. So the RWSEM_WRITER_LOCKED check can 
still provide some value. We should probably update the comment to 
reflect that.

Cheers,
Longman


  reply	other threads:[~2023-11-08 14:05 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 [this message]
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

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=6da49b39-653a-1eda-2d21-1f1b50cb14f0@redhat.com \
    --to=longman@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=haifeng.xu@shopee.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®