linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dongsheng Yang <dongsheng.yang@easystack.cn>
To: colyli@suse.de
Cc: linux-bcache@vger.kernel.org,
	Dongsheng Yang <dongsheng.yang@easystack.cn>
Subject: [PATCH] bcache: allow allocator to invalidate bucket in gc
Date: Thu, 10 Sep 2020 11:21:24 +0000	[thread overview]
Message-ID: <1599736884-5479-1-git-send-email-dongsheng.yang@easystack.cn> (raw)

Currently, if the gc is running, when the allocator found free_inc
is empty, allocator has to wait the gc finish. Before that, the
IO is blocked.

But actually, there would be some buckets is reclaimable before gc,
and gc will never mark this kind of bucket to be  unreclaimable.

So we can put these buckets into free_inc in gc running to avoid
IO blocking.

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
---
 drivers/md/bcache/alloc.c  | 10 ++++------
 drivers/md/bcache/bcache.h |  1 +
 drivers/md/bcache/btree.c  | 10 +++++++++-
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
index 52035a7..265fa05 100644
--- a/drivers/md/bcache/alloc.c
+++ b/drivers/md/bcache/alloc.c
@@ -130,12 +130,11 @@ static inline bool can_inc_bucket_gen(struct bucket *b)
 
 bool bch_can_invalidate_bucket(struct cache *ca, struct bucket *b)
 {
-	BUG_ON(!ca->set->gc_mark_valid);
-
-	return (!GC_MARK(b) ||
+	return ((b->reclaimable_in_gc || ca->set->gc_mark_valid) &&
+		((!GC_MARK(b) ||
 		GC_MARK(b) == GC_MARK_RECLAIMABLE) &&
 		!atomic_read(&b->pin) &&
-		can_inc_bucket_gen(b);
+		can_inc_bucket_gen(b)));
 }
 
 void __bch_invalidate_one_bucket(struct cache *ca, struct bucket *b)
@@ -353,8 +352,7 @@ static int bch_allocator_thread(void *arg)
 		 */
 
 retry_invalidate:
-		allocator_wait(ca, ca->set->gc_mark_valid &&
-			       !ca->invalidate_needs_gc);
+		allocator_wait(ca, !ca->invalidate_needs_gc);
 		invalidate_buckets(ca);
 
 		/*
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 4fd03d2..870f146 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -200,6 +200,7 @@ struct bucket {
 	uint8_t		gen;
 	uint8_t		last_gc; /* Most out of date gen in the btree */
 	uint16_t	gc_mark; /* Bitfield used by GC. See below for field */
+	uint16_t	reclaimable_in_gc:1;
 };
 
 /*
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 3d8bd06..d45a1dd 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -1702,18 +1702,21 @@ static void btree_gc_start(struct cache_set *c)
 
 	mutex_lock(&c->bucket_lock);
 
-	c->gc_mark_valid = 0;
 	c->gc_done = ZERO_KEY;
 
 	for_each_cache(ca, c, i)
 		for_each_bucket(b, ca) {
 			b->last_gc = b->gen;
+			if (bch_can_invalidate_bucket(ca, b))
+				b->reclaimable_in_gc = 1;
+
 			if (!atomic_read(&b->pin)) {
 				SET_GC_MARK(b, 0);
 				SET_GC_SECTORS_USED(b, 0);
 			}
 		}
 
+	c->gc_mark_valid = 0;
 	mutex_unlock(&c->bucket_lock);
 }
 
@@ -1729,6 +1732,11 @@ static void bch_btree_gc_finish(struct cache_set *c)
 	c->gc_mark_valid = 1;
 	c->need_gc	= 0;
 
+	for_each_cache(ca, c, i)
+		for_each_bucket(b, ca)
+			if (b->reclaimable_in_gc)
+				b->reclaimable_in_gc = 0;
+
 	for (i = 0; i < KEY_PTRS(&c->uuid_bucket); i++)
 		SET_GC_MARK(PTR_BUCKET(c, &c->uuid_bucket, i),
 			    GC_MARK_METADATA);
-- 
1.8.3.1


             reply	other threads:[~2020-09-10 12:14 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 11:21 Dongsheng Yang [this message]
2020-09-10 11:28 ` [PATCH v2] bcache: allow allocator to invalidate bucket in gc Dongsheng Yang
2020-09-18  9:53   ` Coly Li
2024-03-15 22:45     ` Robert Pang
2024-03-16  2:48       ` Coly Li
2024-03-17  5:41         ` Robert Pang
2024-03-17 13:59           ` Coly Li
2024-03-18  6:16             ` Robert Pang
2024-03-28 18:05               ` Robert Pang
2024-03-29 13:00                 ` Coly Li
2024-04-11  6:44                   ` Robert Pang
2024-05-03 18:23                     ` Coly Li
2024-05-03 18:28                       ` Coly Li
2024-05-04  2:04                         ` Robert Pang
2024-05-04  3:08                           ` Coly Li
2024-05-08  2:34                             ` Dongsheng Yang
2024-05-12  5:43                               ` Robert Pang
2024-05-12  9:41                                 ` Kernel error with 6.8.9 Pierre Juhen (IMAP)
2024-05-13  7:57                                   ` Coly Li
2024-05-17  0:34                                     ` Eric Wheeler
2024-05-17 15:57                                       ` Coly Li
2024-05-13  7:43                                 ` [PATCH v2] bcache: allow allocator to invalidate bucket in gc Coly Li
2024-05-14  5:15                                   ` Robert Pang
2024-05-14 23:39                                     ` Coly Li
2024-05-17  0:30                                       ` Eric Wheeler
2024-05-17 16:06                                         ` Coly Li
2024-05-17 21:47                                           ` Eric Wheeler
2024-05-24  7:14                                           ` Robert Pang
2024-05-27 18:14                                             ` Coly Li
2024-05-28  5:50                                               ` Robert Pang
2024-05-29 16:24                                                 ` Coly Li
2024-06-03  7:04                                                   ` Robert Pang

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=1599736884-5479-1-git-send-email-dongsheng.yang@easystack.cn \
    --to=dongsheng.yang@easystack.cn \
    --cc=colyli@suse.de \
    --cc=linux-bcache@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).