From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v4 0/2] btrfs: fix and detect dirty/held ebs at unmount time
Date: Thu, 30 Apr 2026 10:37:21 +0930 [thread overview]
Message-ID: <cover.1777510825.git.wqu@suse.com> (raw)
[CHANGELOG]
v4:
- Add the patch into the series which fixes the dirty ebs
- Remove the transid output
It's not really utilized for the particular bug, and can be added
later easily.
- Rename the detecting function to invalidate_and_check_btree_folios()
- Update the commit message in the 1st patch
The dirty ebs won't cause NULL pointer dereferences even all workers
are already stopped.
As in this particular case the fs is already in RO mode, thus all
metadata writeback will fail immediately without going through the
writeback path.
But still better to fix the bug other than relying on extra safety
nets.
v3:
- Revert the DEBUG_WANR_ON_ONCE() change
As there is only one user, a simple
WARN_ON_ONCE(IS_ENABLED(CONFIG_BTRFS_DEBUG)) is more than enough.
- Output the generation of the unreleased eb too
Since it's possible to have 2 transactions (one committing and reached
UNBLOCKED state, one new running), the generation output will help us
to know which transaction the unreleased eb belongs to.
- Also output the transid when a transaction is aborted
To co-operate with the above change for debugging.
v2:
- Add one extra ref before checking the eb
Although readahead has one extra ref, after the readahead finished the
extra ref will be dropped, and memory pressure can kick in to free the
extent buffer.
- Use rcu lock with xa_for_each() instead of xas lock and xas_for_each()
Since we're holding one extra eb ref to prevent eb from disappearing,
we no longer needs the more strict xas lock nor the extra xas
pause/unlock.
Although xa_for_each() is more time consuming, we're at the cold path
already, not a huge cost.
- Remove the temporarary void pointer
And pass eb pointer directly into xas_for_each().
- Introduce DEBUG_WARN_ON_ONCE() helper
To follow the existing DEBUG_WARN() helper.
- Fix a typo
- Also fix the checkpatch warning on the exist DEBUG_WARN()
There is a report about readahead triggering NULL pointer dereferences,
which inspired me to add a detection mechanism about any dirty/held ebs
during unmount.
It turns out that several error injection/shutdown test cases can
trigger the new detection mechanism, and after more debugging it shows
that we had a bug in the transaction abort path that doesn't properly
cleanup the dirty ebs.
The first patch fixes the bug first, then the second patch introduces
the new detection mechanism.
Qu Wenruo (2):
btrfs: only release the dirty pages io tree after successful writes
btrfs: warn about extent buffer that can not be released
fs/btrfs/disk-io.c | 55 ++++++++++++++++++++++++++++++++++++++++--
fs/btrfs/extent_io.c | 6 -----
fs/btrfs/extent_io.h | 6 +++++
fs/btrfs/transaction.c | 9 +++----
4 files changed, 63 insertions(+), 13 deletions(-)
--
2.54.0
next reply other threads:[~2026-04-30 1:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 1:07 Qu Wenruo [this message]
2026-04-30 1:07 ` [PATCH v4 1/2] btrfs: only release the dirty pages io tree after successful writes Qu Wenruo
2026-04-30 12:53 ` Filipe Manana
2026-04-30 1:07 ` [PATCH v4 2/2] btrfs: warn about extent buffer that can not be released Qu Wenruo
2026-04-30 12:48 ` Filipe Manana
2026-04-30 21:58 ` Qu Wenruo
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.1777510825.git.wqu@suse.com \
--to=wqu@suse.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