[PATCH] locking/rwsem: save unnecessary rwsem_set_owner() after slow path
From: Peng Wang
Date: Thu Jun 13 2019 - 11:41:00 EST
rwsem_down_write_failed() and rwsem_down_write_failed_killable() return
with sem->owner set if acquire semaphore successfully, so we can skip
rwsem_set_owner() to keep pace with reading.
Signed-off-by: Peng Wang <rocking@xxxxxxxxxx>
---
kernel/locking/rwsem.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/locking/rwsem.h b/kernel/locking/rwsem.h
index 64877f5294e3..4fa21f737151 100644
--- a/kernel/locking/rwsem.h
+++ b/kernel/locking/rwsem.h
@@ -225,7 +225,8 @@ static inline void __down_write(struct rw_semaphore *sem)
&sem->count);
if (unlikely(tmp != RWSEM_ACTIVE_WRITE_BIAS))
rwsem_down_write_failed(sem);
- rwsem_set_owner(sem);
+ else
+ rwsem_set_owner(sem);
}
static inline int __down_write_killable(struct rw_semaphore *sem)
@@ -234,10 +235,12 @@ static inline int __down_write_killable(struct rw_semaphore *sem)
tmp = atomic_long_add_return_acquire(RWSEM_ACTIVE_WRITE_BIAS,
&sem->count);
- if (unlikely(tmp != RWSEM_ACTIVE_WRITE_BIAS))
+ if (unlikely(tmp != RWSEM_ACTIVE_WRITE_BIAS)) {
if (IS_ERR(rwsem_down_write_failed_killable(sem)))
return -EINTR;
- rwsem_set_owner(sem);
+ } else {
+ rwsem_set_owner(sem);
+ }
return 0;
}
--
2.19.1