[3/4] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint

Message ID 20240213031656.1375951-4-longman@redhat.com
State New
Headers
Series locking: Some locking code cleanups |

Commit Message

Waiman Long Feb. 13, 2024, 3:16 a.m. UTC
  Clarify in the comments that the RWSEM_READER_OWNED bit in the owner
field is just a hint, not an authoritative state of the rwsem.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/locking/rwsem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Boqun Feng Feb. 22, 2024, 4:12 a.m. UTC | #1
On Mon, Feb 12, 2024 at 10:16:55PM -0500, Waiman Long wrote:
> Clarify in the comments that the RWSEM_READER_OWNED bit in the owner
> field is just a hint, not an authoritative state of the rwsem.
> 
> Signed-off-by: Waiman Long <longman@redhat.com>

Reviewed-by: Boqun Feng <boqun.feng@gmail.com>

Regards,
Boqun

> ---
>  kernel/locking/rwsem.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 2340b6d90ec6..c6d17aee4209 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -35,7 +35,7 @@
>  /*
>   * The least significant 2 bits of the owner value has the following
>   * meanings when set.
> - *  - Bit 0: RWSEM_READER_OWNED - The rwsem is owned by readers
> + *  - Bit 0: RWSEM_READER_OWNED - rwsem may be owned by readers (just a hint)
>   *  - Bit 1: RWSEM_NONSPINNABLE - Cannot spin on a reader-owned lock
>   *
>   * When the rwsem is reader-owned and a spinning writer has timed out,
> @@ -1002,8 +1002,8 @@ rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, unsigned int stat
>  
>  	/*
>  	 * To prevent a constant stream of readers from starving a sleeping
> -	 * waiter, don't attempt optimistic lock stealing if the lock is
> -	 * currently owned by readers.
> +	 * writer, don't attempt optimistic lock stealing if the lock is
> +	 * very likely owned by readers.
>  	 */
>  	if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
>  	    (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))
> -- 
> 2.39.3
>
  

Patch

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 2340b6d90ec6..c6d17aee4209 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -35,7 +35,7 @@ 
 /*
  * The least significant 2 bits of the owner value has the following
  * meanings when set.
- *  - Bit 0: RWSEM_READER_OWNED - The rwsem is owned by readers
+ *  - Bit 0: RWSEM_READER_OWNED - rwsem may be owned by readers (just a hint)
  *  - Bit 1: RWSEM_NONSPINNABLE - Cannot spin on a reader-owned lock
  *
  * When the rwsem is reader-owned and a spinning writer has timed out,
@@ -1002,8 +1002,8 @@  rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, unsigned int stat
 
 	/*
 	 * To prevent a constant stream of readers from starving a sleeping
-	 * waiter, don't attempt optimistic lock stealing if the lock is
-	 * currently owned by readers.
+	 * writer, don't attempt optimistic lock stealing if the lock is
+	 * very likely owned by readers.
 	 */
 	if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
 	    (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))