Linux bcache driver list
 help / color / mirror / Atom feed
From: Mauricio Faria de Oliveira <mfo@canonical.com>
To: kent.overstreet@gmail.com
Cc: linux-bcache@vger.kernel.org, mfo@canonical.com, nkshirsagar@gmail.com
Subject: Re: bcache-register hang after reboot
Date: Mon, 13 Dec 2021 19:04:55 -0300	[thread overview]
Message-ID: <20211213220455.1633987-1-mfo@canonical.com> (raw)
In-Reply-To: <YY/+YDSjdZPma3oT@moria.home.lan>

Hey Kent and Coly,

It turns out that, at least for the disk image that reproduces the issue,
the closure from bch_btree_set_root() to bch_journal_meta() doesn't make
a difference; the stall is in bch_journal() -> journal_wait_for_write().

So the previous suggestion to skip bch_journal_meta() altogether works,
to get things going.. of course, checking for journal replay/full case.

What do you think of this patch?

It simply checks the conditions in run_cache_set() for bch_journal_replay().
(it starts w/ unlikely(!CACHE_SET_RUNNING) to quickly get to the usual case,
and apparently has an extra strict check for !gc_thread, just in case. 
And it is journal_full() only, as the !journal_full() case in journal_wait_
for_write() seems to be handled via another function per the comment.)

This works w/ the disk image here.

Thanks!
Mauricio

diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 72abe5cf4b12..bedeffc3ae28 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -2477,9 +2477,6 @@ int bch_btree_insert(struct cache_set *c, struct keylist *keys,
 void bch_btree_set_root(struct btree *b)
 {
 	unsigned int i;
-	struct closure cl;
-
-	closure_init_stack(&cl);
 
 	trace_bcache_btree_set_root(b);
 
@@ -2494,8 +2491,18 @@ void bch_btree_set_root(struct btree *b)
 
 	b->c->root = b;
 
-	bch_journal_meta(b->c, &cl);
-	closure_sync(&cl);
+	/* Don't journal during replay if journal is full (prevents deadlock) */
+	if (unlikely(!test_bit(CACHE_SET_RUNNING, &b->c->flags)) &&
+	    CACHE_SYNC(&b->c->cache->sb) && b->c->gc_thread == NULL &&
+	    journal_full(&b->c->journal)) {
+		pr_info("Not journaling new root (replay with full journal)\n");
+	} else {
+		struct closure cl;
+
+		closure_init_stack(&cl);
+		bch_journal_meta(b->c, &cl);
+		closure_sync(&cl);
+	}
 }
 
 /* Map across nodes or keys */

  reply	other threads:[~2021-12-13 22:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10  5:44 bcache-register hang after reboot Nikhil Kshirsagar
2021-11-10 20:13 ` Kent Overstreet
2021-11-11 20:54   ` Mauricio Oliveira
2021-11-13 18:05     ` Kent Overstreet
2021-12-13 22:04       ` Mauricio Faria de Oliveira [this message]
2021-12-13 22:22         ` Mauricio Faria de Oliveira
2021-12-14 16:06         ` Coly Li
2021-12-14 16:43           ` Mauricio Faria de Oliveira
2021-11-12  5:45   ` Coly Li
2021-11-13 18:12     ` Kent Overstreet

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=20211213220455.1633987-1-mfo@canonical.com \
    --to=mfo@canonical.com \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=nkshirsagar@gmail.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