Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] dm persistent data: __shadow_block() exceeds max concurrent locks - [Medium] dm persistent data: space map block leak on error in __shadow_block() --
commit f51a9340a7ed4ff57bea163d1f75e930e3c7038c Author: Denis V. Lunev <[email protected]> dm persistent data: drop the original block only once it is copied This commit moves the dm_sm_dec_block() call in __shadow_block() after the original block is read, copied into the newly allocated block, and unlocked. > diff --git a/drivers/md/persistent-data/dm-transaction-manager.c > b/drivers/md/persistent-data/dm-transaction-manager.c > index 7401add01d12e..159aac9da07ae 100644 > --- a/drivers/md/persistent-data/dm-transaction-manager.c > +++ b/drivers/md/persistent-data/dm-transaction-manager.c > @@ -297,10 +297,6 @@ static int __shadow_block(struct dm_transaction_manager > *tm, dm_block_t orig, > if (r < 0) > return r; > > - r = dm_sm_dec_block(tm->sm, orig); > - if (r < 0) > - return r; > - > r = dm_bm_read_lock(tm->bm, orig, v, &orig_block); > if (r < 0) > return r; > @@ -322,7 +318,14 @@ static int __shadow_block(struct dm_transaction_manager > *tm, dm_block_t orig, > dm_bm_block_size(tm->bm)); > > dm_bm_unlock(orig_block); > - return r; > + > + r = dm_sm_dec_block(tm->sm, orig); > + if (r < 0) { > + dm_bm_unlock(*result); > + return r; > + } > + > + return 0; > } [Severity: High] Can calling dm_sm_dec_block() while *result is still write-locked exceed the maximum concurrent block locks reserved by dm-bufio and deadlock under memory pressure? Previously, __shadow_block() ran in three sequential phases that each held at most two locks internally: dm_sm_new_block(), dm_sm_dec_block(), and dm_bm_read_lock(orig) + dm_bm_write_lock_zero(new). Commit 490ae017f54e ("dm thin metadata: THIN_MAX_CONCURRENT_LOCKS should be 6") sized THIN_MAX_CONCURRENT_LOCKS to 6 for rebalance3(), which holds 4 locks (2 in the shadow spine plus left and center children) when init_child() calls dm_tm_shadow_block() for the right child (4 + 2 = 6). With dm_sm_dec_block(tm->sm, orig) moved after dm_bm_write_lock_zero(), *result is already held when dm_sm_dec_block() runs. When smm->recursion_count is 0 and orig's bitmap block has not been shadowed yet in the current transaction, sm_metadata_dec_blocks() -> sm_ll_dec() -> __sm_ll_dec() -> shadow_bitmap() recursively enters __shadow_block() for the bitmap block and takes dm_bm_read_lock() and dm_bm_write_lock_zero(). That brings the peak lock count to caller_locks + 3, reaching 7 concurrent locks in rebalance3() (exceeding THIN_MAX_CONCURRENT_LOCKS = 6) and 6 in rebalance2() (exceeding ERA_MAX_CONCURRENT_LOCKS = 5, CACHE_MAX_CONCURRENT_LOCKS = 5, and DM_CLONE_MAX_CONCURRENT_LOCKS = 5). When dm-bufio falls back to its reserved_buffers pool under memory pressure, a single metadata thread holding all reserved buffers cannot evict its own held buffers and blocks forever in __alloc_buffer_wait_no_callback() -> __wait_for_free_buffer(). [Severity: Medium] Does __shadow_block() also leak the newly allocated block new in the space map when dm_bm_read_lock(), dm_bm_write_lock_zero(), or dm_sm_dec_block() fails? At the start of __shadow_block(), dm_sm_new_block(tm->sm, &new) allocates new with a reference count of 1. If a transient read error in dm_bm_read_lock() (or a failure in dm_bm_write_lock_zero() or dm_sm_dec_block(tm->sm, orig)) aborts the shadow and a subsequent commit succeeds, new is never released with dm_sm_dec_block(tm->sm, new) (unlike dm_tm_new_block() right above, which decrements new_block on error) and remains permanently allocated in the space map with no metadata pointing to it. On the dm_sm_dec_block(tm->sm, orig) failure path, dm_bm_unlock(*result) also marks the buffer for new dirty in dm-bufio. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
