Skip to content

Commit ce069fc

Browse files
Jason Lowingomolnar
authored andcommitted
locking/rwsem: Reduce the size of struct rw_semaphore
Recent optimistic spinning additions to rwsem provide significant performance benefits on many workloads on large machines. The cost of it was increasing the size of the rwsem structure by up to 128 bits. However, now that the previous patches in this series bring the overhead of struct optimistic_spin_queue to 32 bits, this patch reorders some fields in struct rw_semaphore such that we can reduce the overhead of the rwsem structure by 64 bits (on 64 bit systems). The extra overhead required for rwsem optimistic spinning would now be up to 8 additional bytes instead of up to 16 bytes. Additionally, the size of rwsem would now be more in line with mutexes. Signed-off-by: Jason Low <jason.low2@hp.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Scott Norton <scott.norton@hp.com> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Dave Chinner <david@fromorbit.com> Cc: Waiman Long <waiman.long@hp.com> Cc: Davidlohr Bueso <davidlohr@hp.com> Cc: Rik van Riel <riel@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Aswin Chandramouleeswaran <aswin@hp.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Chris Mason <clm@fb.com> Cc: Josef Bacik <jbacik@fusionio.com> Link: http://lkml.kernel.org/r/1405358872-3732-6-git-send-email-jason.low2@hp.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 13b9a96 commit ce069fc

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

‎include/linux/rwsem.h‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ struct rw_semaphore;
2424
/* All arch specific implementations share the same struct */
2525
struct rw_semaphore {
2626
long count;
27-
raw_spinlock_t wait_lock;
2827
struct list_head wait_list;
28+
raw_spinlock_t wait_lock;
2929
#ifdef CONFIG_SMP
30+
struct optimistic_spin_queue osq; /* spinner MCS lock */
3031
/*
3132
* Write owner. Used as a speculative check to see
3233
* if the owner is running on the cpu.
3334
*/
3435
struct task_struct *owner;
35-
struct optimistic_spin_queue osq; /* spinner MCS lock */
3636
#endif
3737
#ifdef CONFIG_DEBUG_LOCK_ALLOC
3838
struct lockdep_map dep_map;
@@ -64,21 +64,18 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
6464
#endif
6565

6666
#if defined(CONFIG_SMP) && !defined(CONFIG_RWSEM_GENERIC_SPINLOCK)
67-
#define __RWSEM_INITIALIZER(name) \
68-
{ RWSEM_UNLOCKED_VALUE, \
69-
__RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
70-
LIST_HEAD_INIT((name).wait_list), \
71-
NULL, /* owner */ \
72-
OSQ_LOCK_UNLOCKED /* osq */ \
73-
__RWSEM_DEP_MAP_INIT(name) }
67+
#define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED, .owner = NULL
7468
#else
75-
#define __RWSEM_INITIALIZER(name) \
76-
{ RWSEM_UNLOCKED_VALUE, \
77-
__RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
78-
LIST_HEAD_INIT((name).wait_list) \
79-
__RWSEM_DEP_MAP_INIT(name) }
69+
#define __RWSEM_OPT_INIT(lockname)
8070
#endif
8171

72+
#define __RWSEM_INITIALIZER(name) \
73+
{ .count = RWSEM_UNLOCKED_VALUE, \
74+
.wait_list = LIST_HEAD_INIT((name).wait_list), \
75+
.wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock) \
76+
__RWSEM_OPT_INIT(name) \
77+
__RWSEM_DEP_MAP_INIT(name) }
78+
8279
#define DECLARE_RWSEM(name) \
8380
struct rw_semaphore name = __RWSEM_INITIALIZER(name)
8481

0 commit comments

Comments
 (0)