locking/rwsem: fix comments about reader optimistic lock stealing conditions
PATCH 1/2 locking/rwsem: fix comments about reader optimistic lock stealing conditions
After the commit 617f3ef95177 ("locking/rwsem: Remove reader optimistic spinning"), reader doesn't support optimistic spinning anymore, there is no need meet the condition which OSQ is empty.
BTW, add an unlikely() for the max reader wakeup check.
Signed-off-by Yanfei Xu <[email protected]>
--- kernel/locking/rwsem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/locking/rwsem.c +1 -2
@@ -56,7 +56,6 @@* * A fast path reader optimistic lock stealing is supported when the rwsem * is previously owned by a writer and the following conditions are met: -* - OSQ is empty * - rwsem is not currently writer owned * - the handoff isn't set. */
@@ -485,7 +484,7 @@ static void rwsem_mark_wake(struct rw_semaphore *sem,/* * Limit # of readers that can be woken up per wakeup call. */ -if (woken >=MAX_READERS_WAKEUP ) +if (unlikely (woken >=MAX_READERS_WAKEUP ))break ; }
Signature · 1 line
2.27.0
PATCH 2/2 locking/rwsem: add preempt_disable/enable for spin region
The rwsem_optimistic_spin() invokes the rwsem_spin_on_owner() with preemption disabled, but rwsem_down_write_slowpath() doesn't. Because the spin region should not be preempted, add preempt_disable/enable() in rwsem_spin_on_owner().
Signed-off-by Yanfei Xu <[email protected]>
--- kernel/locking/rwsem.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/locking/rwsem.c +2 -0
@@ -674,6 +674,7 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)if (state !=OWNER_WRITER )return state; +preempt_disable ();rcu_read_lock ();for (;;) {/*
@@ -704,6 +705,7 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)cpu_relax (); }rcu_read_unlock (); +preempt_enable ();return state; }
Signature · 1 line
2.27.0