All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Harmstone <mark@harmstone.com>
To: Boris Burkov <boris@bur.io>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v5 09/16] btrfs: handle deletions from remapped block group
Date: Thu, 13 Nov 2025 11:09:18 +0000	[thread overview]
Message-ID: <cda4868d-91c3-491c-b22c-3f41562cb150@harmstone.com> (raw)
In-Reply-To: <c2db973e-a5ff-4268-adc9-df36aa0e59a9@harmstone.com>

On 12/11/2025 6.51 pm, Mark Harmstone wrote:
... snip ...
>> As far as I can tell, this code is called from contexts which might not
>> be holding the reclaim mutex (extent freeing delayed ref logic) which
>> means it could run concurrently with btrfs_delete_unused_bgs(). Or is
>> the fact that we are not yet fully remapped mean that the remap logic is
>> still running while holding that mutex, so delete_unused_bgs can't run?
>>
>> With that in mind, I am somewhat concerned about the possibility that we
>> might be *on* the unused bgs list at this time, unless you know the
>> delete can't run concurrently, or that the remapped handling all assumes
>> it's possible we have concurrently run delete?
> 
> btrfs_mark_bg_fully_remapped() is called when the last identity remap of 
> a BG is removed: either from the relocation thread, or from deleting an 
> inode. So if balance is interrupted, it's possible for it to be run 
> without the reclaim mutex being held.
> 
> I think I need to investigate exactly why this can be called for a BG 
> that's on the unused_bgs list, it's not obvious why that can happen.

The answer is that btrfs_create_pending_block_groups(), which can create 
a new block group to satisfy a reservation, then immediately puts it on 
the unused list.

It remains on that list when allocations are made to it, but 
btrfs_delete_unused_bgs() will remove it from the list but bail when it 
sees it's actually used. (If you're looking to tighten up the BG list 
system this might be of interest.)

So I need to change it so that the bool bg->fully_remapped gets set 
holding the same bg->lock at the same time as identity_remap_count falls 
to 0, rather than later in btrfs_mark_bg_fully_remapped().

This is the fixed version of the potential race:

CPU0					CPU1
----					----

btrfs_create_pending_block_groups()
creates BG and adds to unused list

extent created in BG

balance started

balance cancelled before identity
remap processed (so reclaim mutex
doesn't prevent BG deletion job)

last identity map removed by rm,
bg->fully_remapped set

					btrfs_delete_unused_bgs()
					called, bails because of
					bg->fully_remapped

BG added to fully remapped list


  reply	other threads:[~2025-11-13 11:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-10 17:14 [PATCH v5 00/16] Remap tree Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 01/16] btrfs: add definitions and constants for remap-tree Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 02/16] btrfs: add REMAP chunk type Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 03/16] btrfs: allow remapped chunks to have zero stripes Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 04/16] btrfs: remove remapped block groups from the free-space tree Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 05/16] btrfs: don't add metadata items for the remap tree to the extent tree Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 06/16] btrfs: add extended version of struct block_group_item Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 07/16] btrfs: allow mounting filesystems with remap-tree incompat flag Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 08/16] btrfs: redirect I/O for remapped block groups Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 09/16] btrfs: handle deletions from remapped block group Mark Harmstone
2025-11-12  5:14   ` Boris Burkov
2025-11-12 18:51     ` Mark Harmstone
2025-11-13 11:09       ` Mark Harmstone [this message]
2025-11-12  6:15   ` Boris Burkov
2025-11-10 17:14 ` [PATCH v5 10/16] btrfs: handle setting up relocation of block group with remap-tree Mark Harmstone
2025-11-12  5:35   ` Boris Burkov
2025-11-12 17:38     ` Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 11/16] btrfs: move existing remaps before relocating block group Mark Harmstone
2025-11-12  5:41   ` Boris Burkov
2025-11-10 17:14 ` [PATCH v5 12/16] btrfs: replace identity remaps with actual remaps when doing relocations Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 13/16] btrfs: add do_remap param to btrfs_discard_extent() Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 14/16] btrfs: allow balancing remap tree Mark Harmstone
2025-11-10 17:14 ` [PATCH v5 15/16] btrfs: handle discarding fully-remapped block groups Mark Harmstone
2025-11-12  5:55   ` Boris Burkov
2025-11-10 17:14 ` [PATCH v5 16/16] btrfs: populate fully_remapped_bgs_list on mount Mark Harmstone
2025-11-12  5:57   ` Boris Burkov

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=cda4868d-91c3-491c-b22c-3f41562cb150@harmstone.com \
    --to=mark@harmstone.com \
    --cc=boris@bur.io \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.