The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Coly Li" <colyli@fygo.io>
To: "Robert Pang" <robertpang@google.com>
Cc: <kent.overstreet@linux.dev>, <linux-bcache@vger.kernel.org>,
	 <linux-kernel@vger.kernel.org>, <dongsheng.yang@easystack.cn>,
	 <mingzhe.zou@easystack.cn>
Subject: Re: [PATCH] bcache: allow more bucket reclaims during garbage collection
Date: Thu, 3 Dec 2026 22:56:26 +0800	[thread overview]
Message-ID: <axFp0eAJM6Z04MEn@studio.local> (raw)
In-Reply-To: <20261103070122.1208383-1-robertpang@google.com>

Hi Robert,

I started reviewing this patch 2 days ago, finally I have a conclusion
on this patch.

I would NACK this patch. Let me explain.

Commit a14a68b76954 ("bcache: allow allocator to invalidate bucket
in gc") gives the bucket with zero b->pin value a chance to be re-
used before the gc thread finishes, it is fine.

But this patch changes the 1 bit reclaimable_in_gc flag to a 8 bits
value, it means before the gc thread finishes the whole run, this bucket
has chance to be reused for multiple times.

In the worst case, if I/O load is high and most of buckets are occupied,
only a few buckets can be invalidated and reused where btree_gc_start()
calls bch_can_invalidate_bucket(), then this small group of buckets will
be repeatedly reused much more frequently than other buckets on SSD.

When this senario occurs, the patched code will introduce a regression
on wear leveling. The unpatched code works fine without such potential
regression.

IMHO the root cause is current gc is too slow. I am thinking of work
on a parallel gc by multiple kthreads. It is necessary for larger and
larger SSD capacity nowadays. Let me try to improve this after finish my
current bcache size online extension stuffs.

Thanks.

Coly Li

On Mon, Nov 02, 2026 at 11:01:22PM +0800, Robert Pang wrote:
> In patch a14a68b76954 ("bcache: allow allocator to invalidate bucket in gc"),
> reclaimable buckets are added to the free list for the bucket allocator
> at the start of a GC cycle.
> 
> However, once these buckets are allocated, they are no longer marked as
> reclaimable until the GC cycle finishes. Under heavy loads and frequent cache
> updates, all reclaimable buckets can be exhausted before the GC ends, causing
> the allocator to wait and stalling incoming I/O.
> 
> Address this by allowing reclaimable buckets to be reclaimed during GC up to
> the number of generations left before BUCKET_GC_GEN_MAX.
> 
> Signed-off-by: Robert Pang <robertpang@google.com>
> ---
>  drivers/md/bcache/alloc.c  | 3 ++-
>  drivers/md/bcache/bcache.h | 2 +-
>  drivers/md/bcache/btree.c  | 5 +++--
>  3 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
> index 3ec240ec685d..959d753e7cf6 100644
> --- a/drivers/md/bcache/alloc.c
> +++ b/drivers/md/bcache/alloc.c
> @@ -141,7 +141,8 @@ void __bch_invalidate_one_bucket(struct cache *ca, struct bucket *b)
>  	bch_inc_gen(ca, b);
>  	b->prio = INITIAL_PRIO;
>  	atomic_inc(&b->pin);
> -	b->reclaimable_in_gc = 0;
> +	if (b->reclaimable_in_gc)
> +		b->reclaimable_in_gc--;
>  }
>  
>  static void bch_invalidate_one_bucket(struct cache *ca, struct bucket *b)
> diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
> index ec9ff9715081..daae5ac5ffbc 100644
> --- a/drivers/md/bcache/bcache.h
> +++ b/drivers/md/bcache/bcache.h
> @@ -200,7 +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;
> +	uint8_t		reclaimable_in_gc; /* no. of times reclaimable in GC */
>  };
>  
>  /*
> diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
> index 27a129d47d0a..fc167868c814 100644
> --- a/drivers/md/bcache/btree.c
> +++ b/drivers/md/bcache/btree.c
> @@ -1742,9 +1742,10 @@ static void btree_gc_start(struct cache_set *c)
>  
>  	ca = c->cache;
>  	for_each_bucket(b, ca) {
> -		b->last_gc = b->gen;
>  		if (bch_can_invalidate_bucket(ca, b))
> -			b->reclaimable_in_gc = 1;
> +			b->reclaimable_in_gc =
> +				BUCKET_GC_GEN_MAX - bucket_gc_gen(b);
> +		b->last_gc = b->gen;
>  		if (!atomic_read(&b->pin)) {
>  			SET_GC_MARK(b, 0);
>  			SET_GC_SECTORS_USED(b, 0);
> -- 
> 2.56.0.398.g882cbad275-goog

      parent reply	other threads:[~2026-12-03 14:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  7:01 [PATCH] bcache: allow more bucket reclaims during garbage collection Robert Pang
2026-11-03 21:57 ` Robert Pang
2026-12-03 14:56 ` Coly Li [this message]

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=axFp0eAJM6Z04MEn@studio.local \
    --to=colyli@fygo.io \
    --cc=dongsheng.yang@easystack.cn \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingzhe.zou@easystack.cn \
    --cc=robertpang@google.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