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>
Subject: Re: [PATCH] bcache: fix available bucket accounting in bucket allocation
Date: Thu, 3 Dec 2026 23:15:44 +0800 [thread overview]
Message-ID: <axGGeIf7cRdA8eAT@studio.local> (raw)
In-Reply-To: <20261103070407.1211071-1-robertpang@google.com>
Hi Robert,
NACK this patch. Let me explain inline.
On Mon, Nov 02, 2026 at 11:04:06PM +0800, Robert Pang wrote:
> In bch_bucket_alloc(), a cache set's avail_nbuckets is decremented whenever a
> bucket is allocated, assuming that the bucket becomes unavailable once
> allocated. However, when a bucket is allocated but the GC mark is unset or
> reclaimable, it is available still. This false counter decrement leads to an
> inflated in-use measurement, which triggers cache bypasses once CUTOFF_CACHE_ADD
> is reached, persisting until the next garbage collection cycle.
>
> Fix this by ensuring avail_nbuckets is only decremented when the allocated
> bucket is already marked and not in the GC_MARK_RECLAIMABLE state.
>
> Signed-off-by: Robert Pang <robertpang@google.com>
> ---
> drivers/md/bcache/alloc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
> index 3ec240ec685d..2d0cb9b414ac 100644
> --- a/drivers/md/bcache/alloc.c
> +++ b/drivers/md/bcache/alloc.c
> @@ -446,7 +446,8 @@ long bch_bucket_alloc(struct cache *ca, unsigned int reserve, bool wait)
> b->prio = INITIAL_PRIO;
> }
>
> - if (ca->set->avail_nbuckets > 0) {
> + if (ca->set->avail_nbuckets > 0 &&
> + GC_MARK(b) && GC_MARK(b) != GC_MARK_RECLAIMABLE) {
An allocated bucket can still have GC_MARK(b) as GC_MARK_RECLAIMABLE.
Because current bcache code permits a bucket to be reused (if b->pin
is 0) before gc thread finishes whole garbage collection procedure.
In this case, the condition
'GC_MARK(b) && GC_MARK(b) != GC_MARK_RECLAIMABLE)'
will be false, so a bucket allocated but avail_nbuckets counter isn't
decreased.
> ca->set->avail_nbuckets--;
> bch_update_bucket_in_use(ca->set, &ca->set->gc_stats);
> }
Thanks.
Coly Li
prev parent reply other threads:[~2026-12-03 15:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 7:04 [PATCH] bcache: fix available bucket accounting in bucket allocation Robert Pang
2026-11-03 22:27 ` Robert Pang
2026-12-03 15:15 ` 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=axGGeIf7cRdA8eAT@studio.local \
--to=colyli@fygo.io \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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