From: Boris Burkov <boris@bur.io>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 0/5] btrfs: block_group refcounting fixes
Date: Thu, 6 Mar 2025 16:29:00 -0800 [thread overview]
Message-ID: <cover.1741306938.git.boris@bur.io> (raw)
We have observed a number of WARNINGs in the Meta fleet which are the
result of a block_group refcount underflowing. The refcount error
can happen at any point in the block group's lifetime, so it is hard to
conclude that we have reproduced/fixed all the bugs, I believe I have
found a few here that will hopefully improve things.
The main thrust of this patch series is that we need to take the
fs_info->unused_bgs_lock spin lock when modifying the bg_list of a
block_group. There are a number of code paths where we atomically check
that list_head for emptiness and then add/del get/put appropriately.
If any other thread messes with it in between without locking, then that
logic gets messed up. This is most obviously evident with
mark_bg_unused.
I could imagine universally protecting bg_list's empty/not-empty nature
with a lock with smaller scope, but this is already the locking strategy
being used to synchronize reclaim/unused lists, so it seems reasonable
to just re-use it.
In addition, I attempted to simplify the refcounting logic in the
discard workfn, as the last time I fixed a bug in there, I made it far
too subtle. Hopefully this more explicit variant is easier to analyze in
the future.
Boris Burkov (5):
btrfs: fix bg refcount race in btrfs_create_pending_block_groups
btrfs: fix bg->bg_list list_del refcount races
btrfs: make discard_workfn block_group ref explicit
btrfs: explicitly ref count block_group on new_bgs list
btrfs: codify pattern for adding block_group to bg_list
fs/btrfs/block-group.c | 57 +++++++++++++++++++++++++-----------------
fs/btrfs/discard.c | 34 ++++++++++++-------------
fs/btrfs/extent-tree.c | 3 +++
fs/btrfs/transaction.c | 5 ++++
4 files changed, 58 insertions(+), 41 deletions(-)
--
2.48.1
next reply other threads:[~2025-03-07 0:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 0:29 Boris Burkov [this message]
2025-03-07 0:29 ` [PATCH 1/5] btrfs: fix bg refcount race in btrfs_create_pending_block_groups Boris Burkov
2025-03-07 6:51 ` Qu Wenruo
2025-03-07 14:13 ` Filipe Manana
2025-03-07 21:32 ` Boris Burkov
2025-03-10 12:41 ` Filipe Manana
2025-03-10 19:28 ` Boris Burkov
2025-03-07 0:29 ` [PATCH 2/5] btrfs: fix bg->bg_list list_del refcount races Boris Burkov
2025-03-07 6:52 ` Qu Wenruo
2025-03-07 14:24 ` Filipe Manana
2025-03-07 21:37 ` Boris Burkov
2025-03-10 12:47 ` Filipe Manana
2025-03-07 0:29 ` [PATCH 3/5] btrfs: make discard_workfn block_group ref explicit Boris Burkov
2025-03-07 14:33 ` Filipe Manana
2025-03-07 0:29 ` [PATCH 4/5] btrfs: explicitly ref count block_group on new_bgs list Boris Burkov
2025-03-07 14:37 ` Filipe Manana
2025-03-07 21:40 ` Boris Burkov
2025-03-07 22:32 ` Boris Burkov
2025-03-10 12:52 ` Filipe Manana
2025-03-07 0:29 ` [PATCH 5/5] btrfs: codify pattern for adding block_group to bg_list Boris Burkov
2025-03-07 14:45 ` Filipe Manana
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=cover.1741306938.git.boris@bur.io \
--to=boris@bur.io \
--cc=kernel-team@fb.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox