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>,
	stable@vger.kernel.org, Tang Junhui <tang.junhui.linux@gmail.com>
Subject: [PATCH 01/29] bcache: Revert "bcache: fix high CPU occupancy during journal"
Date: Fri, 14 Jun 2019 21:13:30 +0800	[thread overview]
Message-ID: <20190614131358.2771-2-colyli@suse.de> (raw)
In-Reply-To: <20190614131358.2771-1-colyli@suse.de>

This reverts commit c4dc2497d50d9c6fb16aa0d07b6a14f3b2adb1e0.

This patch enlarges a race between normal btree flush code path and
flush_btree_write(), which causes deadlock when journal space is
exhausted. Reverts this patch makes the race window from 128 btree
nodes to only 1 btree nodes.

Fixes: c4dc2497d50d ("bcache: fix high CPU occupancy during journal")
Signed-off-by: Coly Li <colyli@suse.de>
Cc: stable@vger.kernel.org
Cc: Tang Junhui <tang.junhui.linux@gmail.com>
---
 drivers/md/bcache/bcache.h  |  2 --
 drivers/md/bcache/journal.c | 47 +++++++++++++++------------------------------
 drivers/md/bcache/util.h    |  2 --
 3 files changed, 15 insertions(+), 36 deletions(-)

diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index fdf75352e16a..e30a983a68cd 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -726,8 +726,6 @@ struct cache_set {
 
 #define BUCKET_HASH_BITS	12
 	struct hlist_head	bucket_hash[1 << BUCKET_HASH_BITS];
-
-	DECLARE_HEAP(struct btree *, flush_btree);
 };
 
 struct bbio {
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index 12dae9348147..621ebf5c62a5 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -391,12 +391,6 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list)
 }
 
 /* Journalling */
-#define journal_max_cmp(l, r) \
-	(fifo_idx(&c->journal.pin, btree_current_write(l)->journal) < \
-	 fifo_idx(&(c)->journal.pin, btree_current_write(r)->journal))
-#define journal_min_cmp(l, r) \
-	(fifo_idx(&c->journal.pin, btree_current_write(l)->journal) > \
-	 fifo_idx(&(c)->journal.pin, btree_current_write(r)->journal))
 
 static void btree_flush_write(struct cache_set *c)
 {
@@ -404,35 +398,25 @@ static void btree_flush_write(struct cache_set *c)
 	 * Try to find the btree node with that references the oldest journal
 	 * entry, best is our current candidate and is locked if non NULL:
 	 */
-	struct btree *b;
-	int i;
+	struct btree *b, *best;
+	unsigned int i;
 
 	atomic_long_inc(&c->flush_write);
-
 retry:
-	spin_lock(&c->journal.lock);
-	if (heap_empty(&c->flush_btree)) {
-		for_each_cached_btree(b, c, i)
-			if (btree_current_write(b)->journal) {
-				if (!heap_full(&c->flush_btree))
-					heap_add(&c->flush_btree, b,
-						 journal_max_cmp);
-				else if (journal_max_cmp(b,
-					 heap_peek(&c->flush_btree))) {
-					c->flush_btree.data[0] = b;
-					heap_sift(&c->flush_btree, 0,
-						  journal_max_cmp);
-				}
+	best = NULL;
+
+	for_each_cached_btree(b, c, i)
+		if (btree_current_write(b)->journal) {
+			if (!best)
+				best = b;
+			else if (journal_pin_cmp(c,
+					btree_current_write(best)->journal,
+					btree_current_write(b)->journal)) {
+				best = b;
 			}
+		}
 
-		for (i = c->flush_btree.used / 2 - 1; i >= 0; --i)
-			heap_sift(&c->flush_btree, i, journal_min_cmp);
-	}
-
-	b = NULL;
-	heap_pop(&c->flush_btree, b, journal_min_cmp);
-	spin_unlock(&c->journal.lock);
-
+	b = best;
 	if (b) {
 		mutex_lock(&b->write_lock);
 		if (!btree_current_write(b)->journal) {
@@ -870,8 +854,7 @@ int bch_journal_alloc(struct cache_set *c)
 	j->w[0].c = c;
 	j->w[1].c = c;
 
-	if (!(init_heap(&c->flush_btree, 128, GFP_KERNEL)) ||
-	    !(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL)) ||
+	if (!(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL)) ||
 	    !(j->w[0].data = (void *) __get_free_pages(GFP_KERNEL, JSET_BITS)) ||
 	    !(j->w[1].data = (void *) __get_free_pages(GFP_KERNEL, JSET_BITS)))
 		return -ENOMEM;
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
index 1fbced94e4cc..c029f7443190 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -113,8 +113,6 @@ do {									\
 
 #define heap_full(h)	((h)->used == (h)->size)
 
-#define heap_empty(h)	((h)->used == 0)
-
 #define DECLARE_FIFO(type, name)					\
 	struct {							\
 		size_t front, back, size, mask;				\
-- 
2.16.4


  reply	other threads:[~2019-06-14 13:14 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 13:13 [PATCH 00/29] bcache candidate patches for Linux v5.3 Coly Li
2019-06-14 13:13 ` Coly Li [this message]
2019-06-14 13:13 ` [PATCH 02/29] bcache: Revert "bcache: free heap cache_set->flush_btree in bch_journal_free" Coly Li
2019-06-14 13:13 ` [PATCH 03/29] bcache: add code comments for journal_read_bucket() Coly Li
2019-06-14 13:13 ` [PATCH 04/29] bcache: set largest seq to ja->seq[bucket_index] in journal_read_bucket() Coly Li
2019-06-14 13:13 ` [PATCH 05/29] bcache: remove retry_flush_write from struct cache_set Coly Li
2019-06-14 13:13 ` [PATCH 06/29] bcache: fix race in btree_flush_write() Coly Li
2019-06-27  9:16   ` Yaowei Bai
2019-06-27 11:47     ` Coly Li
2019-06-27 12:45       ` Coly Li
2019-06-14 13:13 ` [PATCH 07/29] bcache: add reclaimed_journal_buckets to struct cache_set Coly Li
2019-06-14 13:13 ` [PATCH 08/29] bcache: fix return value error in bch_journal_read() Coly Li
2019-06-14 13:13 ` [PATCH 09/29] Revert "bcache: set CACHE_SET_IO_DISABLE in bch_cached_dev_error()" Coly Li
2019-06-14 13:13 ` [PATCH 10/29] bcache: avoid flushing btree node in cache_set_flush() if io disabled Coly Li
2019-06-14 13:13 ` [PATCH 11/29] bcache: ignore read-ahead request failure on backing device Coly Li
2019-06-14 13:13 ` [PATCH 12/29] bcache: add io error counting in write_bdev_super_endio() Coly Li
2019-06-14 13:13 ` [PATCH 13/29] bcache: remove "XXX:" comment line from run_cache_set() Coly Li
2019-06-14 13:13 ` [PATCH 14/29] bcache: remove unnecessary prefetch() in bset_search_tree() Coly Li
2019-06-14 13:13 ` [PATCH 15/29] bcache: use sysfs_match_string() instead of __sysfs_match_string() Coly Li
2019-06-14 13:13 ` [PATCH 16/29] bcache: add return value check to bch_cached_dev_run() Coly Li
2019-06-14 13:13 ` [PATCH 17/29] bcache: remove unncessary code in bch_btree_keys_init() Coly Li
2019-06-14 13:13 ` [PATCH 18/29] bcache: check CACHE_SET_IO_DISABLE in allocator code Coly Li
2019-06-14 13:13 ` [PATCH 19/29] bcache: check CACHE_SET_IO_DISABLE bit in bch_journal() Coly Li
2019-06-14 13:13 ` [PATCH 20/29] bcache: more detailed error message to bcache_device_link() Coly Li
2019-06-14 13:13 ` [PATCH 21/29] bcache: add more error message in bch_cached_dev_attach() Coly Li
2019-06-14 13:13 ` [PATCH 22/29] bcache: shrink btree node cache after bch_btree_check() Coly Li
2019-06-14 13:13 ` [PATCH 23/29] bcache: improve error message in bch_cached_dev_run() Coly Li
2019-06-14 13:13 ` [PATCH 24/29] bcache: make bset_search_tree() be more understandable Coly Li
2019-06-14 13:13 ` [PATCH 25/29] bcache: add pendings_cleanup to stop pending bcache device Coly Li
2019-06-14 13:13 ` [PATCH 26/29] bcache: avoid a deadlock in bcache_reboot() Coly Li
2019-06-14 13:13 ` [PATCH 27/29] bcache: acquire bch_register_lock later in cached_dev_detach_finish() Coly Li
2019-06-14 13:13 ` [PATCH 28/29] bcache: acquire bch_register_lock later in cached_dev_free() Coly Li
2019-06-14 13:13 ` [PATCH 29/29] bcache: fix potential deadlock in cached_def_free() Coly Li
2019-06-20  9:34 ` [PATCH 00/29] bcache candidate patches for Linux v5.3 Jens Axboe

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=20190614131358.2771-2-colyli@suse.de \
    --to=colyli@suse.de \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tang.junhui.linux@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 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.