From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796310956; b=g7bnvCGoDAVVa7jR124tXw+CCPKQc4S/0SRbm6XRiZFqRSHm9227YbtFJJpOPg26Ujy/ tdteq2So4g5EMAtAFdj96m6T6Xq07P868cKYVgczrHF7XfXMWKaRP3n3afsXooS/mY+bD T3X66ULquCLw5f+4+miz0AqlRJQSoPVcYMKoV81oQNoKrV4ySZzrskApJ78OkmBzoyRfc 5VP0K6v/jjy91QCLvgqCVLs1SebWOety5a+48qZDBG2nHlVSxwKRzlFXJ6TQSriQaOhEF Lh2AnUWad/3/7uhXMUV7AXhGHbzw1RLSUXGG0ME9yK6UkLbnupmdpeWGcEKZtw9U2jg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796310956; h=DMARC-Filter:DKIM-Signature:Received:Content-Transfer-Encoding:To: X-Lms-Return-Path:Content-Type:References:Content-Disposition: In-Reply-To:From:Subject:Message-Id:Mime-Version:X-Original-From:Cc: Date; bh=dPkpli/P5lopw22zzlnn8RD3IwSmD6gHXebR9Nlzmzc=; b=CJ3Pw/NtW1IQeIfNtrn1DaL6vhcsoL59rOW13bRWtx8uOeYbQPS6X3thJlaIdyw/AQOP VFnmuJpgaB/JB4ENQs7G32KBnzvW3I+YxEt4Ht85ql+kAR8PCsKuwNgczYXAN+3Wr+LLI hr9Ju4yAkR9Tn32/Qme6lYLgEMO5yiGy8Oc9eepnjs6pmQH4GiA5VgYrdap+Zx3iphn/v qPb/2fo+3Q9om0wHs7MdxFXAFEp2d/JTWc4v4xoDVeLQuXttPq8bqhN9Ao/VCbU2vFWQX eKVFTkiUN1PwTp/FUwW80uRXoR4k0tXcbrbW7rZ2pPgEoy5RgUQF6ruqYoxlsOiSzHA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fygo.io; spf=pass smtp.mailfrom=fygo.io; dkim=pass header.d=fygo-io.20200929.dkim.larksuite.com header.i=@fygo-io.20200929.dkim.larksuite.com header.a=rsa-sha256 header.s=s1 header.b=H6EF5LVP; arc=none smtp.remote-ip=209.127.231.42 Received: from va-2-42.ptr.blmpb.com (va-2-42.ptr.blmpb.com [209.127.231.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17351606A682 for ; Thu, 3 Dec 2026 15:15:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 17351606A682 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fygo.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fygo.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fygo-io.20200929.dkim.larksuite.com header.i=@fygo-io.20200929.dkim.larksuite.com header.a=rsa-sha256 header.s=s1 header.b=H6EF5LVP DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=fygo-io.20200929.dkim.larksuite.com; t=1796310948; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=dPkpli/P5lopw22zzlnn8RD3IwSmD6gHXebR9Nlzmzc=; b=H6EF5LVPWEIXKW/qLADQ7RTvDPdLfZijcrlh43wsbMFmowVugZku3Zg9Z7c/ea8+ZggcrC NNWQdMaTCf8SiJ22ioBALg4MCVToOmkPQonFaAa6lANMhJd6IFZGBgWfl1A7b/2XRL68UN BrNCJtaqcuuhilK4dtiUzh4Fj3NCOFnRyeZ9ySgV4PXkas3TMS6A1L0sfPboIWT9SO1uvf 5TrBT89ywSC7e8larMjvtvlBUSYdbZ1+g6yXe/k+tT01FFgedOJfKnM3Fq3scIRAnhVqLu VISRYVt7XFSOPrshNse+A2qWA0AJwyTh/q2tSxjc9PPGJkyaxZ7QTLE+LHRraw== Received: from studio.local ([120.245.64.92]) by smtp.larksuite.com with ESMTPS; Thu, 03 Dec 2026 15:15:46 +0000 Content-Transfer-Encoding: 7bit To: "Robert Pang" X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 References: <20261103070407.1211071-1-robertpang@google.com> Content-Disposition: inline In-Reply-To: <20261103070407.1211071-1-robertpang@google.com> From: "Coly Li" Subject: Re: [PATCH] bcache: fix available bucket accounting in bucket allocation Message-Id: X-Mailing-List: linux-bcache@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Original-From: Coly Li Cc: , , Date: Thu, 3 Dec 2026 23:15:44 +0800 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 > --- > 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