Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH v4 0/2] btrfs: fix and detect dirty/held ebs at unmount time
@ 2026-04-30  1:07 Qu Wenruo
  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  1:07 ` [PATCH v4 2/2] btrfs: warn about extent buffer that can not be released Qu Wenruo
  0 siblings, 2 replies; 6+ messages in thread
From: Qu Wenruo @ 2026-04-30  1:07 UTC (permalink / raw)
  To: linux-btrfs

[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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-30 21:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30  1:07 [PATCH v4 0/2] btrfs: fix and detect dirty/held ebs at unmount time Qu Wenruo
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox