Skip to content

Commit 3ed0161

Browse files
naotakdave
authored andcommitted
btrfs: delete unused BGs while reclaiming BGs
The reclaiming process only starts after the filesystem volumes are allocated to a certain level (75% by default). Thus, the list of reclaiming target block groups can build up so huge at the time the reclaim process kicks in. On a test run, there were over 1000 BGs in the reclaim list. As the reclaim involves rewriting the data, it takes really long time to reclaim the BGs. While the reclaim is running, btrfs_delete_unused_bgs() won't proceed because the reclaim side is holding fs_info->reclaim_bgs_lock. As a result, we will have a large number of unused BGs kept in the unused list. On my test run, I got 1057 unused BGs. Since deleting a block group is relatively easy and fast work, we can call btrfs_delete_unused_bgs() while it reclaims BGs, to avoid building up unused BGs. Fixes: 18bb8bb ("btrfs: zoned: automatically reclaim zones") CC: stable@vger.kernel.org # 5.15+ Reviewed-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 0d394cc commit 3ed0161

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

fs/btrfs/block-group.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,10 +1824,24 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18241824

18251825
next:
18261826
btrfs_put_block_group(bg);
1827+
1828+
mutex_unlock(&fs_info->reclaim_bgs_lock);
1829+
/*
1830+
* Reclaiming all the block groups in the list can take really
1831+
* long. Prioritize cleaning up unused block groups.
1832+
*/
1833+
btrfs_delete_unused_bgs(fs_info);
1834+
/*
1835+
* If we are interrupted by a balance, we can just bail out. The
1836+
* cleaner thread restart again if necessary.
1837+
*/
1838+
if (!mutex_trylock(&fs_info->reclaim_bgs_lock))
1839+
goto end;
18271840
spin_lock(&fs_info->unused_bgs_lock);
18281841
}
18291842
spin_unlock(&fs_info->unused_bgs_lock);
18301843
mutex_unlock(&fs_info->reclaim_bgs_lock);
1844+
end:
18311845
btrfs_exclop_finish(fs_info);
18321846
sb_end_write(fs_info->sb);
18331847
}

0 commit comments

Comments
 (0)