From: Boris Burkov <boris@bur.io>
To: Mark Harmstone <maharmstone@fb.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 04/12] btrfs: remove remapped block groups from the free-space tree
Date: Fri, 13 Jun 2025 15:00:15 -0700 [thread overview]
Message-ID: <20250613220015.GD3621880@zen.localdomain> (raw)
In-Reply-To: <20250605162345.2561026-5-maharmstone@fb.com>
On Thu, Jun 05, 2025 at 05:23:34PM +0100, Mark Harmstone wrote:
> No new allocations can be done from block groups that have the REMAPPED flag
> set, so there's no value in their having entries in the free-space tree.
>
> Prevent a search through the free-space tree being scheduled for such a
> block group, and prevent discard being run for a fully-remapped block
> group.
>
> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
> ---
> fs/btrfs/block-group.c | 21 ++++++++++++++++-----
> fs/btrfs/discard.c | 9 +++++++++
> 2 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 5b0cb04b2b93..9b3b5358f1ba 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -920,6 +920,13 @@ int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait)
> if (btrfs_is_zoned(fs_info))
> return 0;
>
> + /*
> + * No allocations can be done from remapped block groups, so they have
> + * no entries in the free-space tree.
> + */
> + if (cache->flags & BTRFS_BLOCK_GROUP_REMAPPED)
> + return 0;
> +
> caching_ctl = kzalloc(sizeof(*caching_ctl), GFP_NOFS);
> if (!caching_ctl)
> return -ENOMEM;
> @@ -1235,9 +1242,11 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
> * another task to attempt to create another block group with the same
> * item key (and failing with -EEXIST and a transaction abort).
> */
> - ret = remove_block_group_free_space(trans, block_group);
> - if (ret)
> - goto out;
nit: it feels nicer to hide the check inside the function.
> + if (!(block_group->flags & BTRFS_BLOCK_GROUP_REMAPPED)) {
> + ret = remove_block_group_free_space(trans, block_group);
> + if (ret)
> + goto out;
> + }
>
> ret = remove_block_group_item(trans, path, block_group);
> if (ret < 0)
> @@ -2457,10 +2466,12 @@ static int read_one_block_group(struct btrfs_fs_info *info,
> if (btrfs_chunk_writeable(info, cache->start)) {
> if (cache->used == 0) {
> ASSERT(list_empty(&cache->bg_list));
> - if (btrfs_test_opt(info, DISCARD_ASYNC))
> + if (btrfs_test_opt(info, DISCARD_ASYNC) &&
I asked this on the previous patch, but I guess this means we will never
discard these blocks? Is that desirable? Or are we discarding them at
some other point in the life-cycle?
> + !(cache->flags && BTRFS_BLOCK_GROUP_REMAPPED)) {
> btrfs_discard_queue_work(&info->discard_ctl, cache);
> - else
> + } else {
> btrfs_mark_bg_unused(cache);
> + }
> }
> } else {
> inc_block_group_ro(cache, 1);
> diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c
> index 89fe85778115..1015a4d37fb2 100644
> --- a/fs/btrfs/discard.c
> +++ b/fs/btrfs/discard.c
> @@ -698,6 +698,15 @@ void btrfs_discard_punt_unused_bgs_list(struct btrfs_fs_info *fs_info)
> /* We enabled async discard, so punt all to the queue */
> list_for_each_entry_safe(block_group, next, &fs_info->unused_bgs,
> bg_list) {
> + /* Fully remapped BGs have nothing to discard */
Same question. If we simply *don't* discard them, I feel like this
comment is misleadingly worded.
> + spin_lock(&block_group->lock);
> + if (block_group->flags & BTRFS_BLOCK_GROUP_REMAPPED &&
> + !btrfs_is_block_group_used(block_group)) {
> + spin_unlock(&block_group->lock);
> + continue;
> + }
> + spin_unlock(&block_group->lock);
> +
> list_del_init(&block_group->bg_list);
> btrfs_discard_queue_work(&fs_info->discard_ctl, block_group);
> /*
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-06-13 22:00 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 16:23 [PATCH 00/12] btrfs: remap tree Mark Harmstone
2025-06-05 16:23 ` [PATCH 01/12] btrfs: add definitions and constants for remap-tree Mark Harmstone
2025-06-13 21:02 ` Boris Burkov
2025-06-05 16:23 ` [PATCH 02/12] btrfs: add REMAP chunk type Mark Harmstone
2025-06-13 21:22 ` Boris Burkov
2025-06-05 16:23 ` [PATCH 03/12] btrfs: allow remapped chunks to have zero stripes Mark Harmstone
2025-06-13 21:41 ` Boris Burkov
2025-08-08 14:12 ` Mark Harmstone
2025-06-05 16:23 ` [PATCH 04/12] btrfs: remove remapped block groups from the free-space tree Mark Harmstone
2025-06-06 6:41 ` kernel test robot
2025-06-13 22:00 ` Boris Burkov [this message]
2025-08-12 14:50 ` Mark Harmstone
2025-06-05 16:23 ` [PATCH 05/12] btrfs: don't add metadata items for the remap tree to the extent tree Mark Harmstone
2025-06-13 22:39 ` Boris Burkov
2025-06-05 16:23 ` [PATCH 06/12] btrfs: add extended version of struct block_group_item Mark Harmstone
2025-06-05 16:23 ` [PATCH 07/12] btrfs: allow mounting filesystems with remap-tree incompat flag Mark Harmstone
2025-06-05 16:23 ` [PATCH 08/12] btrfs: redirect I/O for remapped block groups Mark Harmstone
2025-06-05 16:23 ` [PATCH 09/12] btrfs: handle deletions from remapped block group Mark Harmstone
2025-06-13 23:42 ` Boris Burkov
2025-08-11 16:48 ` Mark Harmstone
2025-08-11 16:59 ` Mark Harmstone
2025-06-05 16:23 ` [PATCH 10/12] btrfs: handle setting up relocation of block group with remap-tree Mark Harmstone
2025-06-13 23:25 ` Boris Burkov
2025-08-12 11:20 ` Mark Harmstone
2025-06-05 16:23 ` [PATCH 11/12] btrfs: move existing remaps before relocating block group Mark Harmstone
2025-06-06 11:20 ` kernel test robot
2025-06-05 16:23 ` [PATCH 12/12] btrfs: replace identity maps with actual remaps when doing relocations Mark Harmstone
2025-06-05 16:43 ` [PATCH 00/12] btrfs: remap tree Jonah Sabean
2025-06-06 13:35 ` Mark Harmstone
2025-06-09 16:05 ` Anand Jain
2025-06-09 18:51 ` David Sterba
2025-06-10 9:19 ` Mark Harmstone
2025-06-10 14:31 ` Mark Harmstone
2025-06-10 23:56 ` Qu Wenruo
2025-06-11 8:06 ` Mark Harmstone
2025-06-11 15:28 ` Mark Harmstone
2025-06-14 0:04 ` Boris Burkov
2025-06-26 22:10 ` Mark Harmstone
2025-06-27 5:59 ` Neal Gompa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250613220015.GD3621880@zen.localdomain \
--to=boris@bur.io \
--cc=linux-btrfs@vger.kernel.org \
--cc=maharmstone@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox