Skip to content

Commit 4eb4e85

Browse files
boryaskdave
authored andcommitted
btrfs: retry block group reclaim without infinite loop
If inc_block_group_ro systematically fails (e.g. due to ETXTBUSY from swap) or btrfs_relocate_chunk systematically fails (from lack of space), then this worker becomes an infinite loop. At the very least, this strands the cleaner thread, but can also result in hung tasks/RCU stalls on PREEMPT_NONE kernels and if the reclaim_bgs_lock mutex is not contended. I believe the best long term fix is to manage reclaim via work queue, where we queue up a relocation on the triggering condition and re-queue on failure. In the meantime, this is an easy fix to apply to avoid the immediate pain. Fixes: 7e27180 ("btrfs: reinsert BGs failed to reclaim") CC: [email protected] # 6.6+ Signed-off-by: Boris Burkov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f3a5367 commit 4eb4e85

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/btrfs/block-group.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,7 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
17851785
container_of(work, struct btrfs_fs_info, reclaim_bgs_work);
17861786
struct btrfs_block_group *bg;
17871787
struct btrfs_space_info *space_info;
1788+
LIST_HEAD(retry_list);
17881789

17891790
if (!test_bit(BTRFS_FS_OPEN, &fs_info->flags))
17901791
return;
@@ -1921,8 +1922,11 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
19211922
}
19221923

19231924
next:
1924-
if (ret)
1925-
btrfs_mark_bg_to_reclaim(bg);
1925+
if (ret) {
1926+
/* Refcount held by the reclaim_bgs list after splice. */
1927+
btrfs_get_block_group(bg);
1928+
list_add_tail(&bg->bg_list, &retry_list);
1929+
}
19261930
btrfs_put_block_group(bg);
19271931

19281932
mutex_unlock(&fs_info->reclaim_bgs_lock);
@@ -1942,6 +1946,9 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
19421946
spin_unlock(&fs_info->unused_bgs_lock);
19431947
mutex_unlock(&fs_info->reclaim_bgs_lock);
19441948
end:
1949+
spin_lock(&fs_info->unused_bgs_lock);
1950+
list_splice_tail(&retry_list, &fs_info->reclaim_bgs);
1951+
spin_unlock(&fs_info->unused_bgs_lock);
19451952
btrfs_exclop_finish(fs_info);
19461953
sb_end_write(fs_info->sb);
19471954
}

0 commit comments

Comments
 (0)