From 4f8e643afe9d8cc558566e1dda05ef597cb2526e Mon Sep 17 00:00:00 2001 From: Chunwei Chen Date: Tue, 1 Sep 2015 21:55:06 +0800 Subject: [PATCH] Don't take spin lock on rwlock owner The spin lock around rw_owner is completely unnecessary. The reason is that it is only modified in the down_write context. If you race against another thread modifying it, that means that you aren't holding the rwlock, so taking the spin lock don't eliminate the race. Also, we only check rw_owner in RW_WRITE_HELD because spl_rwsem_is_locked is unnecessary and might need to take spin lock. Signed-off-by: Chunwei Chen Signed-off-by: Brian Behlendorf Issue #473 --- include/sys/rwlock.h | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/include/sys/rwlock.h b/include/sys/rwlock.h index 7064e8f1f2..62544f3a81 100644 --- a/include/sys/rwlock.h +++ b/include/sys/rwlock.h @@ -50,34 +50,19 @@ typedef struct { static inline void spl_rw_set_owner(krwlock_t *rwp) { - unsigned long flags; - - spl_rwsem_lock_irqsave(&SEM(rwp)->wait_lock, flags); - rwp->rw_owner = current; - spl_rwsem_unlock_irqrestore(&SEM(rwp)->wait_lock, flags); + rwp->rw_owner = current; } static inline void spl_rw_clear_owner(krwlock_t *rwp) { - unsigned long flags; - - spl_rwsem_lock_irqsave(&SEM(rwp)->wait_lock, flags); - rwp->rw_owner = NULL; - spl_rwsem_unlock_irqrestore(&SEM(rwp)->wait_lock, flags); + rwp->rw_owner = NULL; } static inline kthread_t * rw_owner(krwlock_t *rwp) { - unsigned long flags; - kthread_t *owner; - - spl_rwsem_lock_irqsave(&SEM(rwp)->wait_lock, flags); - owner = rwp->rw_owner; - spl_rwsem_unlock_irqrestore(&SEM(rwp)->wait_lock, flags); - - return owner; + return rwp->rw_owner; } static inline int @@ -89,7 +74,7 @@ RW_READ_HELD(krwlock_t *rwp) static inline int RW_WRITE_HELD(krwlock_t *rwp) { - return (spl_rwsem_is_locked(SEM(rwp)) && rw_owner(rwp) == current); + return (rw_owner(rwp) == current); } static inline int