From: Qu Wenruo <wqu@suse.com>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
linux-btrfs@vger.kernel.org
Cc: Filipe Manana <fdmanana@suse.com>,
Naohiro Aota <naohiro.aota@wdc.com>,
Damien Le Moal <dlemoal@kernel.org>
Subject: Re: [PATCH 2/5] btrfs: zoned: drop stale dirty btree buffers at close_ctree()
Date: Fri, 17 Jul 2026 08:19:38 +0930 [thread overview]
Message-ID: <062d26d5-c340-4e3b-bf56-a38d1f98a546@suse.com> (raw)
In-Reply-To: <20260716115656.1319295-3-johannes.thumshirn@wdc.com>
在 2026/7/16 21:26, Johannes Thumshirn 写道:
> On a zoned filesystem btrfs_clear_buffer_dirty() keeps a freed-but-dirty
> tree block dirty (EXTENT_BUFFER_ZONED_ZEROOUT) so its zero-out keeps the
> zone write pointer moving. A block left ahead of the block group's
> meta_write_pointer (e.g. a tree-log block freed before being written) can
> never be written by btree_writepages() and survives to unmount.
>
> close_ctree() stops the endio workqueues before the final iput() of the
> btree inode but frees the block groups only afterwards. Once the block
> group is gone btrfs_check_meta_write_pointer() no longer defers the buffer,
> so the iput() submits it for writeback; its completion can no longer be
> queued on the destroyed endio_meta_workers and umount hangs on writeback
> that never finishes.
Can we just trigger a btree inode write back for zoned cases?
That sounds much simpler and less hacky.
Thanks,
Qu
>
> btrfs_free_block_groups() has to stay after btrfs_stop_all_workers()
> (see also commit 5cdd7db6c5c9), so instead drop the dirty state of such
> stale buffers in invalidate_and_check_btree_folios(), which still runs
> while the workqueues are alive.
>
> Assisted-by: LLM (debugging, commit message)
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> fs/btrfs/disk-io.c | 4 ++++
> fs/btrfs/extent_io.c | 12 ++++++++++++
> fs/btrfs/extent_io.h | 1 +
> 3 files changed, 17 insertions(+)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index acff40469589..b66525701b33 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -3317,6 +3317,10 @@ static void invalidate_and_check_btree_folios(struct btrfs_fs_info *fs_info)
> if (test_bit(EXTENT_BUFFER_READING, &eb->bflags))
> wait_on_bit_io(&eb->bflags, EXTENT_BUFFER_READING,
> TASK_UNINTERRUPTIBLE);
> +
> + if (btrfs_is_zoned(fs_info) &&
> + test_bit(EXTENT_BUFFER_DIRTY, &eb->bflags))
> + btrfs_clear_stale_buffer_dirty(eb);
> /*
> * The refs threshold is 2, one held by us at the beginning
> * of the loop, one for the ownership in the buffer tree.
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 4dd8fc5ad247..480d4ec8ca7f 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -3841,6 +3841,18 @@ void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
> __btrfs_clear_buffer_dirty(eb);
> }
>
> +/*
> + * Drop the dirty state of a stale, already-freed metadata buffer, bypassing
> + * the zoned EXTENT_BUFFER_ZONED_ZEROOUT deferral of btrfs_clear_buffer_dirty().
> + */
> +void btrfs_clear_stale_buffer_dirty(struct extent_buffer *eb)
> +{
> + btrfs_tree_lock(eb);
> + clear_bit(EXTENT_BUFFER_ZONED_ZEROOUT, &eb->bflags);
> + __btrfs_clear_buffer_dirty(eb);
> + btrfs_tree_unlock(eb);
> +}
> +
> void set_extent_buffer_dirty(struct extent_buffer *eb)
> {
> bool was_dirty;
> diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
> index 869925337699..290d6cff6ddb 100644
> --- a/fs/btrfs/extent_io.h
> +++ b/fs/btrfs/extent_io.h
> @@ -393,6 +393,7 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
> u32 bits_to_clear, unsigned long page_ops);
> void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
> struct extent_buffer *buf);
> +void btrfs_clear_stale_buffer_dirty(struct extent_buffer *eb);
>
> static inline void btrfs_clear_folio_dirty_tag(struct folio *folio)
> {
next prev parent reply other threads:[~2026-07-16 22:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 11:56 [PATCH 0/5] btrfs: zoned: fix two deadlocks when runing fstests Johannes Thumshirn
2026-07-16 11:56 ` [PATCH 1/5] btrfs: factor out dirty-clearing part of btrfs_clear_buffer_dirty Johannes Thumshirn
2026-07-16 22:31 ` Qu Wenruo
2026-07-16 11:56 ` [PATCH 2/5] btrfs: zoned: drop stale dirty btree buffers at close_ctree() Johannes Thumshirn
2026-07-16 22:49 ` Qu Wenruo [this message]
2026-07-17 6:56 ` Johannes Thumshirn
2026-07-17 14:17 ` Johannes Thumshirn
2026-07-17 22:45 ` Qu Wenruo
2026-07-16 11:56 ` [PATCH 3/5] btrfs: walk waited ordered extents in place Johannes Thumshirn
2026-07-16 11:56 ` [PATCH 4/5] btrfs: walk waited ordered roots " Johannes Thumshirn
2026-07-16 11:56 ` [PATCH 5/5] btrfs: zoned: avoid ordered_operations_mutex when finishing a zone Johannes Thumshirn
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=062d26d5-c340-4e3b-bf56-a38d1f98a546@suse.com \
--to=wqu@suse.com \
--cc=dlemoal@kernel.org \
--cc=fdmanana@suse.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.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