All of lore.kernel.org
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: linux-bcache@vger.kernel.org
Cc: linux-block@vger.kernel.org, Coly Li <colyli@suse.de>
Subject: [RFC PATCH v2 16/16] bcache: introduce spinlock_t flush_write_lock in struct journal
Date: Sat, 20 Apr 2019 00:05:09 +0800	[thread overview]
Message-ID: <20190419160509.66298-17-colyli@suse.de> (raw)
In-Reply-To: <20190419160509.66298-1-colyli@suse.de>

In btree_flush_write(), iterating all cached btree nodes and adding them
into ordered heap c->flush_btree takes quite long time. In order to
protect ordered heap c->flush_btree, spin lock c->journal.lock is held
for all the iteration and heap ordering. When journal space is fully
occupied, btree_flush_write() might be called frequently, if the cached
btree node iteration takes too much time, kenrel will complain that
normal journal kworkers are blocked too long. Of cause write performance
drops at this moment.

This patch introduces a new spin lock member in struct journal, named
flush_write_lock. This lock is only used in btree_flush_write() and
protect the ordered heap c->flush_btree during all the cached btree node
iteration. Then there won't be lock contention on c->journal.lock.

After this fix, when journal space is fully occupied, it is very rare to
observe the journal kworker blocking timeout warning.

Signed-off-by: Coly Li <colyli@suse.de>
---
 drivers/md/bcache/journal.c | 5 +++--
 drivers/md/bcache/journal.h | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index 8536e76fcac9..6e38470f6924 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -519,7 +519,7 @@ static void btree_flush_write(struct cache_set *c)
 	atomic_long_inc(&c->flush_write);
 
 retry:
-	spin_lock(&c->journal.lock);
+	spin_lock(&c->journal.flush_write_lock);
 	if (heap_empty(&c->flush_btree)) {
 		for_each_cached_btree(b, c, i)
 			if (btree_current_write(b)->journal) {
@@ -540,7 +540,7 @@ static void btree_flush_write(struct cache_set *c)
 
 	b = NULL;
 	heap_pop(&c->flush_btree, b, journal_min_cmp);
-	spin_unlock(&c->journal.lock);
+	spin_unlock(&c->journal.flush_write_lock);
 
 	if (b) {
 		mutex_lock(&b->write_lock);
@@ -1099,6 +1099,7 @@ int bch_journal_alloc(struct cache_set *c)
 	struct journal *j = &c->journal;
 
 	spin_lock_init(&j->lock);
+	spin_lock_init(&j->flush_write_lock);
 	INIT_DELAYED_WORK(&j->work, journal_write_work);
 
 	c->journal_delay_ms = 100;
diff --git a/drivers/md/bcache/journal.h b/drivers/md/bcache/journal.h
index a8be14c6f6d9..d8ad99f6191b 100644
--- a/drivers/md/bcache/journal.h
+++ b/drivers/md/bcache/journal.h
@@ -103,6 +103,7 @@ struct journal_write {
 /* Embedded in struct cache_set */
 struct journal {
 	spinlock_t		lock;
+	spinlock_t		flush_write_lock;
 	/* used when waiting because the journal was full */
 	struct closure_waitlist	wait;
 	struct closure		io;
-- 
2.16.4


  parent reply	other threads:[~2019-04-19 18:24 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-19 16:04 [RFC PATCH v2 00/16] bcache: fix journal no-space deadlock Coly Li
2019-04-19 16:04 ` [RFC PATCH v2 01/16] bcache: move definition of 'int ret' out of macro read_bucket() Coly Li
2019-04-21 17:47   ` Chaitanya Kulkarni
2019-04-22 15:11     ` Coly Li
2019-04-23  6:50   ` Hannes Reinecke
2019-04-19 16:04 ` [RFC PATCH v2 02/16] bcache: never set 0 to KEY_PTRS of jouranl key in journal_reclaim() Coly Li
2019-04-23  6:50   ` Hannes Reinecke
2019-04-19 16:04 ` [RFC PATCH v2 03/16] bcache: reload jouranl key information during journal replay Coly Li
2019-04-23  6:54   ` Hannes Reinecke
2019-04-23  6:56     ` Coly Li
2019-04-19 16:04 ` [RFC PATCH v2 04/16] bcache: fix journal deadlock during jouranl replay Coly Li
2019-04-23  6:59   ` Hannes Reinecke
2019-04-23  7:07     ` Coly Li
2019-04-19 16:04 ` [RFC PATCH v2 05/16] bcache: reserve space for journal_meta() in run time Coly Li
2019-04-23  7:00   ` Hannes Reinecke
2019-04-19 16:04 ` [RFC PATCH v2 06/16] bcache: add failure check to run_cache_set() for journal replay Coly Li
2019-04-23  7:02   ` Hannes Reinecke
2019-04-23  7:09     ` Coly Li
2019-04-24 16:06     ` Coly Li
2019-04-19 16:05 ` [RFC PATCH v2 07/16] bcache: add comments for kobj release callback routine Coly Li
2019-04-21 17:52   ` Chaitanya Kulkarni
2019-04-23  7:03   ` Hannes Reinecke
2019-04-19 16:05 ` [RFC PATCH v2 08/16] bcache: return error immediately in bch_journal_replay() Coly Li
2019-04-23  7:04   ` Hannes Reinecke
2019-04-19 16:05 ` [RFC PATCH v2 09/16] bcache: add error check for calling register_bdev() Coly Li
2019-04-21 18:00   ` Chaitanya Kulkarni
2019-04-23  7:04   ` Hannes Reinecke
2019-04-19 16:05 ` [RFC PATCH v2 10/16] bcache: Add comments for blkdev_put() in registration code path Coly Li
2019-04-21 17:50   ` Chaitanya Kulkarni
2019-04-23  7:05   ` Hannes Reinecke
2019-04-19 16:05 ` [RFC PATCH v2 11/16] bcache: add comments for closure_fn to be called in closure_queue() Coly Li
2019-04-21 17:43   ` Chaitanya Kulkarni
2019-04-23  7:05   ` Hannes Reinecke
2019-04-19 16:05 ` [RFC PATCH v2 12/16] bcache: add pendings_cleanup to stop pending bcache device Coly Li
2019-04-23  7:08   ` Hannes Reinecke
2019-04-23  7:15     ` Coly Li
2019-04-19 16:05 ` [RFC PATCH v2 13/16] bcache: fix fifo index swapping condition in btree_flush_write() Coly Li
     [not found]   ` <20190419231642.90AB82171F@mail.kernel.org>
2019-04-20 13:20     ` Coly Li
2019-04-23  7:09   ` Hannes Reinecke
2019-04-23  7:16     ` Coly Li
2019-04-19 16:05 ` [RFC PATCH v2 14/16] bcache: try to flush btree nodes as many as possible Coly Li
2019-04-23  7:10   ` Hannes Reinecke
2019-04-19 16:05 ` [RFC PATCH v2 15/16] bcache: improve bcache_reboot() Coly Li
2019-04-23  7:13   ` Hannes Reinecke
2019-04-23  7:18     ` Coly Li
2019-04-19 16:05 ` Coly Li [this message]
2019-04-23  7:14   ` [RFC PATCH v2 16/16] bcache: introduce spinlock_t flush_write_lock in struct journal Hannes Reinecke

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=20190419160509.66298-17-colyli@suse.de \
    --to=colyli@suse.de \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.