Whamcloud - gitweb
LU-4257 clio: replace semaphore with mutex 95/9095/2
authorDmitry Eremin <dmitry.eremin@intel.com>
Mon, 3 Feb 2014 16:07:27 +0000 (20:07 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 3 Apr 2014 00:53:26 +0000 (00:53 +0000)
commit96f482b509867bb70cc26e94e60903df82b09f30
tree3d8f060683b78a21aee2d3534314a9db562b5a06
parenta38ac90d1a3681928e434de2b471f57470911d04
LU-4257 clio: replace semaphore with mutex

According https://www.kernel.org/doc/Documentation/mutex-design.txt:
 - the mutex subsystem is slightly faster and has better scalability
   for contended workloads. In terms of 'ops per CPU cycle', the
   semaphore kernel performed 551 ops/sec per 1% of CPU time used,
   while the mutex kernel performed 3825 ops/sec per 1% of CPU time
   used - it was 6.9 times more efficient.
 - there are no fastpath tradeoffs, the mutex fastpath is just as
   tight as the semaphore fastpath. On x86, the locking fastpath is
   2 instructions.
 - 'struct mutex' semantics are well-defined and are enforced if
   CONFIG_DEBUG_MUTEXES is turned on. Semaphores on the other hand
   have virtually no debugging code or instrumentation.

One more benefit of mutex is optimistic spinning. It try to spin for
acquisition when there are no pending waiters and the lock owner is
currently running on a (different) CPU. The rationale is that if the
lock owner is running, it is likely to release the lock soon.

This significantly reduce amount of context switches when locked
region is small and we have high contention.

Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Change-Id: Ic13179ab7e5ee628f550e5dfd251af31ac6d4211
Reviewed-on: http://review.whamcloud.com/9095
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
lustre/llite/llite_internal.h
lustre/llite/llite_lib.c