Skip to content

Commit 1d8fe7d

Browse files
Jason Lowingomolnar
authored andcommitted
locking/mutexes: Unlock the mutex without the wait_lock
When running workloads that have high contention in mutexes on an 8 socket machine, mutex spinners would often spin for a long time with no lock owner. The main reason why this is occuring is in __mutex_unlock_common_slowpath(), if __mutex_slowpath_needs_to_unlock(), then the owner needs to acquire the mutex->wait_lock before releasing the mutex (setting lock->count to 1). When the wait_lock is contended, this delays the mutex from being released. We should be able to release the mutex without holding the wait_lock. Signed-off-by: Jason Low <jason.low2@hp.com> Cc: chegu_vinod@hp.com Cc: paulmck@linux.vnet.ibm.com Cc: Waiman.Long@hp.com Cc: torvalds@linux-foundation.org Cc: tglx@linutronix.de Cc: riel@redhat.com Cc: akpm@linux-foundation.org Cc: davidlohr@hp.com Cc: hpa@zytor.com Cc: andi@firstfloor.org Cc: aswin@hp.com Cc: scott.norton@hp.com Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1390936396-3962-4-git-send-email-jason.low2@hp.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 47667fa commit 1d8fe7d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎kernel/locking/mutex.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,6 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested)
671671
struct mutex *lock = container_of(lock_count, struct mutex, count);
672672
unsigned long flags;
673673

674-
spin_lock_mutex(&lock->wait_lock, flags);
675-
mutex_release(&lock->dep_map, nested, _RET_IP_);
676-
debug_mutex_unlock(lock);
677-
678674
/*
679675
* some architectures leave the lock unlocked in the fastpath failure
680676
* case, others need to leave it locked. In the later case we have to
@@ -683,6 +679,10 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested)
683679
if (__mutex_slowpath_needs_to_unlock())
684680
atomic_set(&lock->count, 1);
685681

682+
spin_lock_mutex(&lock->wait_lock, flags);
683+
mutex_release(&lock->dep_map, nested, _RET_IP_);
684+
debug_mutex_unlock(lock);
685+
686686
if (!list_empty(&lock->wait_list)) {
687687
/* get the first entry from the wait-list: */
688688
struct mutex_waiter *waiter =

0 commit comments

Comments
 (0)