[PATCH v3 next 1/5] Only clear node->locked in the slow osq_lock() path

david.laight.linux@gmail.com posted 5 patches 1 month ago
[PATCH v3 next 1/5] Only clear node->locked in the slow osq_lock() path
Posted by david.laight.linux@gmail.com 1 month ago
From: David Laight <david.laight@aculab.com>

node->locked is used to indicate that the owner of the lock has handed it
off to the waiting CPU.
As such it's value is only relevant in the slow path so it need not be
initialised in the fast path.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 kernel/locking/osq_lock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
index b4233dc2c2b0..96c6094157b5 100644
--- a/kernel/locking/osq_lock.c
+++ b/kernel/locking/osq_lock.c
@@ -97,7 +97,6 @@ bool osq_lock(struct optimistic_spin_queue *lock)
 	int curr = encode_cpu(smp_processor_id());
 	int old;
 
-	node->locked = 0;
 	node->next = NULL;
 	node->cpu = curr;
 
@@ -113,6 +112,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
 
 	prev = decode_cpu(old);
 	node->prev = prev;
+	node->locked = 0;
 
 	/*
 	 * osq_lock()			unqueue
-- 
2.39.5
Re: [PATCH v3 next 1/5] Only clear node->locked in the slow osq_lock() path
Posted by David Laight 1 month ago
On Fri,  6 Mar 2026 22:51:46 +0000
david.laight.linux@gmail.com wrote:

Apologies to Yafang for mistyping his address...

> From: David Laight <david.laight.linux@gmail.com>
> 
> node->locked is used to indicate that the owner of the lock has handed it
> off to the waiting CPU.
> As such it's value is only relevant in the slow path so it need not be
> initialised in the fast path.
> 
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
>  kernel/locking/osq_lock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
> index b4233dc2c2b0..96c6094157b5 100644
> --- a/kernel/locking/osq_lock.c
> +++ b/kernel/locking/osq_lock.c
> @@ -97,7 +97,6 @@ bool osq_lock(struct optimistic_spin_queue *lock)
>  	int curr = encode_cpu(smp_processor_id());
>  	int old;
>  
> -	node->locked = 0;
>  	node->next = NULL;
>  	node->cpu = curr;
>  
> @@ -113,6 +112,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
>  
>  	prev = decode_cpu(old);
>  	node->prev = prev;
> +	node->locked = 0;
>  
>  	/*
>  	 * osq_lock()			unqueue