From: Chris Mason <clm@meta.com>
To: <fdmanana@kernel.org>
Cc: <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 6/7] btrfs: remove max_mirrors argument from write_all_supers()
Date: Sun, 8 Feb 2026 07:49:51 -0800 [thread overview]
Message-ID: <20260208155148.3637328-1-clm@meta.com> (raw)
In-Reply-To: <a7a8b95c9c2f5d5c6a481aea277194fa615b8390.1770212626.git.fdmanana@suse.com>
fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> There's no need to pass max_mirrors to write_all_supers() since from the
> given transaction handle we can infer if we are in a transaction commit
> or fsync context, so we can determine how many mirrors we need to use.
>
> So remove the max_mirror argument from write_all_supers() and stop
> adjusting it in the callees write_dev_supers() and wait_dev_supers(),
> simplifying them besides the parameter list for write_all_supers().
Hi everyone,
I'm running the btrfs for-next branch, along with the encryption patch set
through my AI review prompts:
https://github.com/masoncl/review-prompts
I'm working on some btrfs specific instructions, but hopefully these reviews
are already useful. I've kept the headers to make it easier to double check
that I'm actually replying to the right email, but please let me know if any
parts of this are incorrect:
commit a30345d606f40c870c69fb77195b3516a6dd6504
Author: Filipe Manana <fdmanana@suse.com>
btrfs: remove max_mirrors argument from write_all_supers()
This commit removes the max_mirrors parameter from write_all_supers()
and determines the mirror count from the transaction handle's in_fsync
flag, claiming this simplifies the code while maintaining correctness.
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 19f7927a000d9..cf4ab067be72c 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
[ ... ]
> @@ -4018,13 +4011,14 @@ int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags)
> return min_tolerated;
> }
>
> -int write_all_supers(struct btrfs_trans_handle *trans, int max_mirrors)
> +int write_all_supers(struct btrfs_trans_handle *trans)
> {
> struct btrfs_fs_info *fs_info = trans->fs_info;
> struct list_head *head;
> struct btrfs_device *dev;
> struct btrfs_super_block *sb;
> struct btrfs_dev_item *dev_item;
> + int max_mirrors;
> int ret;
> int do_barriers;
> int max_errors;
> @@ -4033,13 +4027,13 @@ int write_all_supers(struct btrfs_trans_handle *trans, int max_mirrors)
>
> do_barriers = !btrfs_test_opt(fs_info, NOBARRIER);
>
> - /*
> - * max_mirrors == 0 indicates we're from commit_transaction,
> - * not from fsync where the tree roots in fs_info have not
> - * been consistent on disk.
> - */
> - if (max_mirrors == 0)
> + if (trans->in_fsync) {
> + max_mirrors = 1;
> + } else {
> + /* We are called from transaction commit. */
> + max_mirrors = BTRFS_SUPER_MIRROR_MAX;
> backup_super_roots(fs_info);
> + }
Can this logic handle the case where btrfs_sync_file() falls through to
btrfs_commit_transaction()? Looking at fs/btrfs/file.c, when a full_sync
encounters a log sync failure or BTRFS_LOG_FORCE_COMMIT, the code flow is:
btrfs_sync_file()
trans->in_fsync = true; /* Set at file.c:1728 */
...
btrfs_sync_log() /* May fail or return BTRFS_LOG_FORCE_COMMIT */
...
btrfs_commit_transaction(trans) /* Fallthrough at file.c:1787-1816 */
write_all_supers(trans)
if (trans->in_fsync) /* Still true here */
max_mirrors = 1; /* But we're in transaction commit */
The OLD code always passed max_mirrors=0 from btrfs_commit_transaction()
(transaction.c:2560), ensuring full superblock redundancy with
BTRFS_SUPER_MIRROR_MAX=3 and calling backup_super_roots() regardless of
how the transaction commit was triggered.
The NEW code uses trans->in_fsync which remains true during the
fsync-to-commit fallthrough path. This causes write_all_supers() to set
max_mirrors=1 and skip backup_super_roots(), reducing superblock
redundancy from 3 copies to 1 and skipping tree root backups during these
commits.
Is the commit message claim that "from the given transaction handle we can
infer if we are in a transaction commit or fsync context" accurate for
this case?
next prev parent reply other threads:[~2026-02-08 15:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-04 15:51 [PATCH 0/7] btrfs: minor tweaks and cleanups to the super block writing path fdmanana
2026-02-04 15:51 ` [PATCH 1/7] btrfs: change unaligned root messages to error level in btrfs_validate_super() fdmanana
2026-02-04 15:51 ` [PATCH 2/7] btrfs: mark all error and warning checks as unlikely " fdmanana
2026-02-05 12:04 ` David Sterba
2026-02-04 15:52 ` [PATCH 3/7] btrfs: pass transaction handle to write_all_supers() fdmanana
2026-02-04 15:52 ` [PATCH 4/7] btrfs: abort transaction on error in write_all_supers() fdmanana
2026-02-04 15:52 ` [PATCH 5/7] btrfs: tag error branches as unlikely during super block writes fdmanana
2026-02-04 15:52 ` [PATCH 6/7] btrfs: remove max_mirrors argument from write_all_supers() fdmanana
2026-02-08 15:49 ` Chris Mason [this message]
2026-02-08 18:24 ` Filipe Manana
2026-02-04 15:52 ` [PATCH 7/7] btrfs: set written super flag once in write_all_supers() fdmanana
2026-02-05 12:04 ` [PATCH 0/7] btrfs: minor tweaks and cleanups to the super block writing path David Sterba
2026-02-05 21:12 ` 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=20260208155148.3637328-1-clm@meta.com \
--to=clm@meta.com \
--cc=fdmanana@kernel.org \
--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