From eeeb928ccc6d86e93cb573fb93ce4f6aeb8576fb Mon Sep 17 00:00:00 2001 From: Vlastimil Babka Date: Wed, 2 Apr 2025 10:13:28 +0200 Subject: [PATCH] fixup! locking/local_lock, mm: Replace localtry_ helpers with local_trylock_t type --- include/linux/local_lock.h | 5 +++++ include/linux/local_lock_internal.h | 23 +++++++++++++---------- mm/memcontrol.c | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/linux/local_lock.h b/include/linux/local_lock.h index 7ac9385cd475d..16a2ee4f8310b 100644 --- a/include/linux/local_lock.h +++ b/include/linux/local_lock.h @@ -51,6 +51,11 @@ #define local_unlock_irqrestore(lock, flags) \ __local_unlock_irqrestore(lock, flags) +/** + * local_lock_init - Runtime initialize a lock instance + */ +#define local_trylock_init(lock) __local_trylock_init(lock) + /** * local_trylock - Try to acquire a per CPU local lock * @lock: The lock variable diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h index 2389ae4f69a69..6ccb2c4ef86f3 100644 --- a/include/linux/local_lock_internal.h +++ b/include/linux/local_lock_internal.h @@ -17,15 +17,8 @@ typedef struct { /* local_trylock() and local_trylock_irqsave() only work with local_trylock_t */ typedef struct { -#ifdef CONFIG_DEBUG_LOCK_ALLOC - struct lockdep_map dep_map; - struct task_struct *owner; -#endif - /* - * Same layout as local_lock_t with 'acquired' field at the end. - * (local_trylock_t *) will be cast to (local_lock_t *). - */ - int acquired; + local_lock_t llock; + int acquired; } local_trylock_t; #ifdef CONFIG_DEBUG_LOCK_ALLOC @@ -37,6 +30,9 @@ typedef struct { }, \ .owner = NULL, +# define LOCAL_TRYLOCK_DEBUG_INIT(lockname) \ + .llock = { LOCAL_LOCK_DEBUG_INIT((lockname).llock) }, + static inline void local_lock_acquire(local_lock_t *l) { lock_map_acquire(&l->dep_map); @@ -64,6 +60,7 @@ static inline void local_lock_debug_init(local_lock_t *l) } #else /* CONFIG_DEBUG_LOCK_ALLOC */ # define LOCAL_LOCK_DEBUG_INIT(lockname) +# define LOCAL_TRYLOCK_DEBUG_INIT(lockname) static inline void local_lock_acquire(local_lock_t *l) { } static inline void local_trylock_acquire(local_lock_t *l) { } static inline void local_lock_release(local_lock_t *l) { } @@ -71,6 +68,7 @@ static inline void local_lock_debug_init(local_lock_t *l) { } #endif /* !CONFIG_DEBUG_LOCK_ALLOC */ #define INIT_LOCAL_LOCK(lockname) { LOCAL_LOCK_DEBUG_INIT(lockname) } +#define INIT_LOCAL_TRYLOCK(lockname) { LOCAL_TRYLOCK_DEBUG_INIT(lockname) } #define __local_lock_init(lock) \ do { \ @@ -80,9 +78,11 @@ do { \ lockdep_init_map_type(&(lock)->dep_map, #lock, &__key, \ 0, LD_WAIT_CONFIG, LD_WAIT_INV, \ LD_LOCK_PERCPU); \ - local_lock_debug_init((local_lock_t *)lock); \ + local_lock_debug_init(lock); \ } while (0) +#define __local_trylock_init(lock) __local_lock_init(lock.llock) + #define __spinlock_nested_bh_init(lock) \ do { \ static struct lock_class_key __key; \ @@ -215,12 +215,15 @@ typedef spinlock_t local_lock_t; typedef spinlock_t local_trylock_t; #define INIT_LOCAL_LOCK(lockname) __LOCAL_SPIN_LOCK_UNLOCKED((lockname)) +#define INIT_LOCAL_TRYLOCK(lockname) __LOCAL_SPIN_LOCK_UNLOCKED((lockname)) #define __local_lock_init(l) \ do { \ local_spin_lock_init((l)); \ } while (0) +#define __local_trylock_init(l) __local_lock_init(l) + #define __local_lock(__lock) \ do { \ migrate_disable(); \ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index bca86961754e1..0401fb7b6c6a8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1754,7 +1754,7 @@ struct memcg_stock_pcp { #define FLUSHING_CACHED_CHARGE 0 }; static DEFINE_PER_CPU(struct memcg_stock_pcp, memcg_stock) = { - .stock_lock = INIT_LOCAL_LOCK(stock_lock), + .stock_lock = INIT_LOCAL_TRYLOCK(stock_lock), }; static DEFINE_MUTEX(percpu_charge_mutex); -- 2.50.1