From: Boris Burkov <boris@bur.io>
To: Nikolay Borisov <nborisov@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: Annotate unlocked accesses to transaction state
Date: Tue, 13 Apr 2021 14:57:41 -0700 [thread overview]
Message-ID: <YHYT1TUka52Wya8C@zen> (raw)
In-Reply-To: <20201124144413.3168075-1-nborisov@suse.com>
On Tue, Nov 24, 2020 at 04:44:13PM +0200, Nikolay Borisov wrote:
> btrfs_transaction::state is protected by btrfs_fs_info::trans_lock and
> all accesses to this variable should be synchornized by it. However,
> there are 2 exceptions, namely checking if currently running transaction
> has entered its commit phase in start_transaction and in
> btrfs_should_end_transaction.
>
> Annotate those 2, unlocked accesses with READ_ONCE respectively. Also
> remove the full memory barrier in start_transaction as it provides no
> ordering guarantees due to being unpaired. All other accsess to
> transaction state happen under trans_lock being held.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/transaction.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index df5687a92798..e5a5c3604a9b 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -695,8 +695,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
> h->can_flush_pending_bgs = true;
> INIT_LIST_HEAD(&h->new_bgs);
>
> - smp_mb();
> - if (cur_trans->state >= TRANS_STATE_COMMIT_START &&
> + if (READ_ONCE(cur_trans->state) >= TRANS_STATE_COMMIT_START &&
> may_wait_transaction(fs_info, type)) {
> current->journal_info = h;
> btrfs_commit_transaction(h);
> @@ -912,7 +911,7 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)
> {
> struct btrfs_transaction *cur_trans = trans->transaction;
>
> - if (cur_trans->state >= TRANS_STATE_COMMIT_START ||
> + if (READ_ONCE(cur_trans->state) >= TRANS_STATE_COMMIT_START ||
> test_bit(BTRFS_DELAYED_REFS_FLUSHING,
> &cur_trans->delayed_refs.flags))
> return 1;
> --
> 2.25.1
>
I think some parts of this have already gone in and the conditional has
been lightly refactored, so this patch no longer applies to
kdave/misc-next.
Assuming this is a change for adherence to best practices rather than a
fix for a specific issue (in which case it would be nice to have the
issue described in the message), the patch looks good to me otherwise.
prev parent reply other threads:[~2021-04-13 21:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-24 14:44 [PATCH] btrfs: Annotate unlocked accesses to transaction state Nikolay Borisov
2021-04-13 21:57 ` Boris Burkov [this message]
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=YHYT1TUka52Wya8C@zen \
--to=boris@bur.io \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.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;
as well as URLs for NNTP newsgroup(s).