diff mbox series

[2/4] btrfs: move out now unused BG from the reclaim list

Message ID 6a25b9266b8fb08ff990214aae9efd04fed6b549.1686028197.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fixes for reclaim | expand

Commit Message

Naohiro Aota June 6, 2023, 5:36 a.m. UTC
An unused block group is easy to remove to free up space and should be
reclaimed fast. Such block group can often already be a target of the
reclaim process. As we check list_empty(&bg->bg_list), we keep it in the
reclaim list. That block group is never reclaimed until the file system is
filled e.g, 75%.

Instead, we can move unused block group to the unused list and delete it
fast.

Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones")
CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/block-group.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Filipe Manana June 6, 2023, 10:06 a.m. UTC | #1
On Tue, Jun 6, 2023 at 7:06 AM Naohiro Aota <naota@elisp.net> wrote:
>
> An unused block group is easy to remove to free up space and should be
> reclaimed fast. Such block group can often already be a target of the
> reclaim process. As we check list_empty(&bg->bg_list), we keep it in the
> reclaim list. That block group is never reclaimed until the file system is
> filled e.g, 75%.
>
> Instead, we can move unused block group to the unused list and delete it
> fast.
>
> Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones")
> CC: stable@vger.kernel.org # 5.15+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good, thanks.

> ---
>  fs/btrfs/block-group.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index c5547da0f6eb..d5bba02167be 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -1633,11 +1633,14 @@ void btrfs_mark_bg_unused(struct btrfs_block_group *bg)
>  {
>         struct btrfs_fs_info *fs_info = bg->fs_info;
>
> +       trace_btrfs_add_unused_block_group(bg);
>         spin_lock(&fs_info->unused_bgs_lock);
>         if (list_empty(&bg->bg_list)) {
>                 btrfs_get_block_group(bg);
> -               trace_btrfs_add_unused_block_group(bg);
>                 list_add_tail(&bg->bg_list, &fs_info->unused_bgs);
> +       } else {
> +               /* Pull out the BG from the reclaim_bgs list. */
> +               list_move_tail(&bg->bg_list, &fs_info->unused_bgs);
>         }
>         spin_unlock(&fs_info->unused_bgs_lock);
>  }
> --
> 2.40.1
>
Johannes Thumshirn June 6, 2023, 11:33 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index c5547da0f6eb..d5bba02167be 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1633,11 +1633,14 @@  void btrfs_mark_bg_unused(struct btrfs_block_group *bg)
 {
 	struct btrfs_fs_info *fs_info = bg->fs_info;
 
+	trace_btrfs_add_unused_block_group(bg);
 	spin_lock(&fs_info->unused_bgs_lock);
 	if (list_empty(&bg->bg_list)) {
 		btrfs_get_block_group(bg);
-		trace_btrfs_add_unused_block_group(bg);
 		list_add_tail(&bg->bg_list, &fs_info->unused_bgs);
+	} else {
+		/* Pull out the BG from the reclaim_bgs list. */
+		list_move_tail(&bg->bg_list, &fs_info->unused_bgs);
 	}
 	spin_unlock(&fs_info->unused_bgs_lock);
 }