Re: [PATCHv4 02/17] zram: do not use per-CPU compression streams

From: Sergey Senozhatsky
Date: Sun Feb 09 2025 - 02:42:45 EST


On (25/02/09 15:22), Sergey Senozhatsky wrote:
> On (25/02/09 01:20), Sergey Senozhatsky wrote:
> > So I moved lockdep class keys to per-zram device and per-zsmalloc pool
> > to separate the lockdep chains. Looks like that did the trick.
>
> Also need to indicate "try lock":
>
> drivers/block/zram/zram_drv.c
> @@ -86,7 +86,7 @@ static __must_check bool zram_slot_try_lock(struct zram *zram, u32 index)
>
> if (!test_and_set_bit_lock(ZRAM_ENTRY_LOCK, lock)) {
> #ifdef CONFIG_DEBUG_LOCK_ALLOC
> - mutex_acquire(&zram->table[index].lockdep_map, 0, 0, _RET_IP_);
> + mutex_acquire(&zram->table[index].lockdep_map, 0, 1, _RET_IP_);
> #endif
> return true;
> }
>
> and
>
> mm/zsmalloc.c
> @@ -388,7 +388,7 @@ static __must_check bool zspage_try_write_lock(struct zspage *zspage)
> preempt_disable();
> if (atomic_try_cmpxchg_acquire(lock, &old, ZS_PAGE_WRLOCKED)) {
> #ifdef CONFIG_DEBUG_LOCK_ALLOC
> - rwsem_acquire(&zspage->lockdep_map, 0, 0, _RET_IP_);
> + rwsem_acquire(&zspage->lockdep_map, 0, 1, _RET_IP_);
> #endif
> return true;
> }

I guess this was the point lockdep was making.

lockdep knows about strm->lock -> shrink_folio_list which goes to ptllock
via folio_referenced and cluter_into lock via try_to_unmap. Then lockdep
knows about zram entry->lock -> strm->lock and, most importantly, lockdep
knows about cluter_into lock -> zram_slot_free_notify() -> zram-entry->lock.
What lockdep doesn't know is that zram_slot_free_notify() is a try lock,
we don't re-enter zram unconditionally.