locking/rwsem: Redo __rwsem_init()
Waiman Long
reviewerPATCH 1/1 locking/rwsem: Redo __rwsem_init()
This is a rwsem version of the Sebastian's commit 3572e2edc7b6 ("locking/mutex: Redo __mutex_init()"). The aim is to avoid storing the lock name strings which consume memory that are never used.
The __rwsem_init() will be split into a _generic version with lockdep (CONFIG_DEBUG_LOCK_ALLOC) disabled and a _lockdep version when it is enabled. This will make the rwsem code behavior similar to the mutex code.
This results in the following kernel size reduction with defconfig based config files:
text data bss dec filename 30200741 8165526 1188464 39554731 vmlinux 30200725 8161430 1188464 39550619 vmlinux (patched)
32417939 8475218 12946524 53839681 vmlinux.lockdep 32417945 8475218 12946524 53839687 vmlinux.lockdep (patched)
27119989 7195918 2075852 36391759 vmlinux.preempt_rt 27119996 7195918 2075852 36391766 vmlinux.preempt_rt (patched)
29349572 7509862 13792416 50651850 vmlinux.preempt_rt.lockdep
The kernel size reduction for the lockdep disabled cases isn't that noticeable when compared with the mutex case as there is an order of magnitude more mutex_init() calls than the init_rwsem() calls in the kernel.
--- include/linux/rwsem.h | 45 +++++++++++++++++++++++++++++++++------ kernel/locking/rwsem.c | 48 ++++++++++++++++++++++++++++-------------- 2 files changed, 71 insertions(+), 22 deletions(-)
include/linux/rwsem.h +39 -6
@@ -111,15 +111,32 @@ static inline void rwsem_assert_held_write_nolockdep(const struct rw_semaphore *#define DECLARE_RWSEM (name) \ struct rw_semaphore name = __RWSEM_INITIALIZER(name) -extern void __init_rwsem (struct rw_semaphore *sem,const char *name, -struct lock_class_key *key); +#ifndef CONFIG_DEBUG_LOCK_ALLOC +extern void rwsem_init_generic (struct rw_semaphore *sem); + +static inline void __init_rwsem (struct rw_semaphore *sem,const char *name, +struct lock_class_key *key) +{ +rwsem_init_generic (sem); +} + +#define init_rwsem (sem) rwsem_init_generic(sem) +#else +extern void rwsem_init_lockdep (struct rw_semaphore *sem,const char *name, +struct lock_class_key *key); +static inline void __init_rwsem (struct rw_semaphore *sem,const char *name, +struct lock_class_key *key) +{ +rwsem_init_lockdep (sem, name, key); +}#define init_rwsem (sem) \ do { \ static struct lock_class_key __key; \ \ - __init_rwsem((sem), #sem, &__key); \ + rwsem_init_lockdep((sem), #sem, &__key); \ } while (0) +#endif /* CONFIG_DEBUG_LOCK_ALLOC */ /* * This is the same regardless of which rwsem implementation that is being used.
@@ -164,15 +181,31 @@ struct rw_semaphore {#define DECLARE_RWSEM (lockname) \ struct rw_semaphore lockname = __RWSEM_INITIALIZER(lockname) -extern void __init_rwsem (struct rw_semaphore *rwsem,const char *name, -struct lock_class_key *key); +#ifndef CONFIG_DEBUG_LOCK_ALLOC +extern void rwsem_rt_init_generic (struct rw_semaphore *rwsem); +static inline void __init_rwsem (struct rw_semaphore *rwsem,const char *name, +struct lock_class_key *key) +{ +rwsem_rt_init_generic (rwsem); +} + +#define init_rwsem (sem) rwsem_rt_init_generic(sem) +#else +extern void rwsem_rt_init_lockdep (struct rw_semaphore *rwsem,const char *name, +struct lock_class_key *key); +static inline void __init_rwsem (struct rw_semaphore *rwsem,const char *name, +struct lock_class_key *key) +{ +rwsem_rt_init_lockdep (rwsem, name, key); +}#define init_rwsem (sem) \ do { \ static struct lock_class_key __key; \ \ - __init_rwsem((sem), #sem, &__key); \ + rwsem_rt_init_lockdep((sem), #sem, &__key); \ } while (0) +#endif /* CONFIG_DEBUG_LOCK_ALLOC */ static __always_inline int rwsem_is_locked(const struct rw_semaphore *sem) {
kernel/locking/rwsem.c +32 -16
72 lines not on this page · raw message
Signature · 1 line
2.51.1
Quoted 3 lines · Waiman Long
This is a rwsem version of the Sebastian's commit
3572e2edc7b6("locking/mutex: Redo__mutex_init()"). The aim is to avoid storing the lock name strings which consume memory that are never used.
…
Quoted 1 line
Signed-off-by Waiman Long <[email protected]>
Sebastian