linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: kernel-team@fb.com, linux-btrfs@vger.kernel.org
Subject: [PATCH 7/8] btrfs: don't call btrfs_start_delalloc_roots in flushoncommit
Date: Thu, 19 Oct 2017 14:16:01 -0400	[thread overview]
Message-ID: <1508436962-6851-8-git-send-email-josef@toxicpanda.com> (raw)
In-Reply-To: <1508436962-6851-1-git-send-email-josef@toxicpanda.com>

We're holding the sb_start_intwrite lock at this point, and doing async
filemap_flush of the inodes will result in a deadlock if we freeze the
fs during this operation.  This is because we could do a
btrfs_join_transaction() in the thread we are waiting on which would
block at sb_start_intwrite, and thus deadlock.  Using
writeback_inodes_sb() side steps the problem by not introducing all of
these extra locking dependencies.

Signed-off-by: Josef Bacik <jbacik@fb.com>
---
 fs/btrfs/transaction.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 68c3e1c04bca..5a8c2649af2f 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1916,8 +1916,17 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
 
 static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
 {
+	/*
+	 * We use writeback_inodes_sb here because if we used
+	 * btrfs_start_delalloc_roots we would deadlock with fs freeze.
+	 * Currently are holding the fs freeze lock, if we do an async flush
+	 * we'll do btrfs_join_transaction() and deadlock because we need to
+	 * wait for the fs freeze lock.  Using the direct flushing we benefit
+	 * from already being in a transaction and our join_transaction doesn't
+	 * have to re-take the fs freeze lock.
+	 */
 	if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
-		return btrfs_start_delalloc_roots(fs_info, 1, -1);
+		writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
 	return 0;
 }
 
-- 
2.7.5


  parent reply	other threads:[~2017-10-19 18:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-19 18:15 [PATCH 0/8] Remaining queue Josef Bacik
2017-10-19 18:15 ` [PATCH 1/8] Btrfs: rework outstanding_extents Josef Bacik
2017-10-19 18:15 ` [PATCH 2/8] btrfs: add tracepoints for outstanding extents mods Josef Bacik
2017-10-19 18:15 ` [PATCH 3/8] btrfs: make the delalloc block rsv per inode Josef Bacik
2017-10-19 18:15 ` [PATCH 4/8] btrfs: switch args for comp_*_refs Josef Bacik
2017-10-19 18:15 ` [PATCH 5/8] btrfs: add a comp_refs() helper Josef Bacik
2017-10-19 18:16 ` [PATCH 6/8] btrfs: track refs in a rb_tree instead of a list Josef Bacik
2017-10-19 18:16 ` Josef Bacik [this message]
2017-10-19 18:16 ` [PATCH 8/8] btrfs: move btrfs_truncate_block out of trans handle Josef Bacik
2017-10-20 15:35 ` [PATCH 0/8] Remaining queue David Sterba
  -- strict thread matches above, loose matches on Subject: below --
2017-12-13  8:59 [PATCH 7/8] btrfs: don't call btrfs_start_delalloc_roots in flushoncommit Lu Fengqi

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=1508436962-6851-8-git-send-email-josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --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;
as well as URLs for NNTP newsgroup(s).