Skip to content

Commit 20feab7

Browse files
committed
btrfs: remove btrfs_root's delalloc_mutex
When running metadata space reclaim under high I/O concurrency, we observe hung tasks caused by lock contention on `btrfs_root::delalloc_mutex`. For example: INFO: task kworker/u132:1:2177 blocked for more than 122 seconds. Not tainted 6.16.0-rc3+ torvalds#1246 Workqueue: events_unbound btrfs_preempt_reclaim_metadata_space Call Trace: __schedule+0x2f9/0x7b0 schedule+0x27/0x80 __mutex_lock.constprop.0+0x4af/0x890 start_delalloc_inodes+0x6e/0x400 btrfs_start_delalloc_roots+0x162/0x270 shrink_delalloc+0x10c/0x2d0 flush_space+0x202/0x280 btrfs_preempt_reclaim_metadata_space+0xe7/0x340 The `delalloc_mutex` serializes delalloc flushing per root but is no longer necessary. All critical paths (inode flushing, extent writing, metadata updates) are already synchronized using finer-grained locking at the inode, page, and tree levels. In particular, concurrent flushers coordinate via inode locking, and no shared state requires global serialization across the root. Removing this mutex avoids unnecessary blocking in reclaim paths and improves responsiveness under pressure, especially on systems with many flushers or multi-queue SSDs/ZNS devices. Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]>
1 parent 1c688b4 commit 20feab7

File tree

3 files changed

+0
-4
lines changed

3 files changed

+0
-4
lines changed

fs/btrfs/ctree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ struct btrfs_root {
238238
spinlock_t root_item_lock;
239239
refcount_t refs;
240240

241-
struct mutex delalloc_mutex;
242241
spinlock_t delalloc_lock;
243242
/*
244243
* all of the inodes that have delalloc bytes. It is possible for

fs/btrfs/disk-io.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
678678
mutex_init(&root->objectid_mutex);
679679
mutex_init(&root->log_mutex);
680680
mutex_init(&root->ordered_extent_mutex);
681-
mutex_init(&root->delalloc_mutex);
682681
init_waitqueue_head(&root->qgroup_flush_wait);
683682
init_waitqueue_head(&root->log_writer_wait);
684683
init_waitqueue_head(&root->log_commit_wait[0]);

fs/btrfs/inode.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8673,7 +8673,6 @@ static int start_delalloc_inodes(struct btrfs_root *root,
86738673
int ret = 0;
86748674
bool full_flush = wbc->nr_to_write == LONG_MAX;
86758675

8676-
mutex_lock(&root->delalloc_mutex);
86778676
spin_lock(&root->delalloc_lock);
86788677
list_splice_init(&root->delalloc_inodes, &splice);
86798678
while (!list_empty(&splice)) {
@@ -8730,7 +8729,6 @@ static int start_delalloc_inodes(struct btrfs_root *root,
87308729
list_splice_tail(&splice, &root->delalloc_inodes);
87318730
spin_unlock(&root->delalloc_lock);
87328731
}
8733-
mutex_unlock(&root->delalloc_mutex);
87348732
return ret;
87358733
}
87368734

0 commit comments

Comments
 (0)