From: Alex Lyakas <alex.btrfs@zadarastorage.com>
To: Josef Bacik <jbacik@fb.com>, zab@redhat.com
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH] Btrfs: fix deadlock with nested trans handles
Date: Sat, 3 May 2014 23:04:12 +0300 [thread overview]
Message-ID: <CAOcd+r1Mkjo-wEAKJsRiLUdn53w0qnOyMaLWVchSekffG1q+=A@mail.gmail.com> (raw)
In-Reply-To: <1394150467-5990-1-git-send-email-jbacik@fb.com>
Hi Josef,
this problem could not happen when find_free_extent() was receiving a
transaction handle (which was changed in "Btrfs: avoid starting a
transaction in the write path"), correct? Because it would have used
the passed transaction handle to do the chunk allocation, and thus
would not need to do join_transaction/end_transaction leading to
recursive run_delayed_refs call.
Alex.
On Fri, Mar 7, 2014 at 3:01 AM, Josef Bacik <jbacik@fb.com> wrote:
> Zach found this deadlock that would happen like this
>
> btrfs_end_transaction <- reduce trans->use_count to 0
> btrfs_run_delayed_refs
> btrfs_cow_block
> find_free_extent
> btrfs_start_transaction <- increase trans->use_count to 1
> allocate chunk
> btrfs_end_transaction <- decrease trans->use_count to 0
> btrfs_run_delayed_refs
> lock tree block we are cowing above ^^
>
> We need to only decrease trans->use_count if it is above 1, otherwise leave it
> alone. This will make nested trans be the only ones who decrease their added
> ref, and will let us get rid of the trans->use_count++ hack if we have to commit
> the transaction. Thanks,
>
> cc: stable@vger.kernel.org
> Reported-by: Zach Brown <zab@redhat.com>
> Signed-off-by: Josef Bacik <jbacik@fb.com>
> ---
> fs/btrfs/transaction.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index 34cd831..b05bf58 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -683,7 +683,8 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
> int lock = (trans->type != TRANS_JOIN_NOLOCK);
> int err = 0;
>
> - if (--trans->use_count) {
> + if (trans->use_count > 1) {
> + trans->use_count--;
> trans->block_rsv = trans->orig_rsv;
> return 0;
> }
> @@ -731,17 +732,10 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
> }
>
> if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) {
> - if (throttle) {
> - /*
> - * We may race with somebody else here so end up having
> - * to call end_transaction on ourselves again, so inc
> - * our use_count.
> - */
> - trans->use_count++;
> + if (throttle)
> return btrfs_commit_transaction(trans, root);
> - } else {
> + else
> wake_up_process(info->transaction_kthread);
> - }
> }
>
> if (trans->type & __TRANS_FREEZABLE)
> --
> 1.8.3.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2014-05-03 20:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-07 0:01 [PATCH] Btrfs: fix deadlock with nested trans handles Josef Bacik
2014-03-07 0:25 ` Zach Brown
2014-03-12 12:56 ` Rich Freeman
2014-03-12 15:24 ` Josef Bacik
2014-03-12 16:34 ` Rich Freeman
2014-03-14 22:40 ` Rich Freeman
2014-03-15 11:51 ` Duncan
2014-03-21 2:13 ` Rich Freeman
2014-03-21 5:44 ` Duncan
2014-03-17 14:34 ` Josef Bacik
2014-05-03 20:04 ` Alex Lyakas [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='CAOcd+r1Mkjo-wEAKJsRiLUdn53w0qnOyMaLWVchSekffG1q+=A@mail.gmail.com' \
--to=alex.btrfs@zadarastorage.com \
--cc=jbacik@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=zab@redhat.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).