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 <tuxoko@gmail.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #473
This commit is contained in:
parent
3e1e4c735c
commit
4f8e643afe
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue