From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309801; b=bWvAWOGybfBjiU8Tn1OCZtoDcloZHjhWYo54DAGkFpjBNQiSfFHJ4JDlroqG+NBJgtPQ +0dP/YRJy4RFAYpLenDO607iWh4EPgFFuendqj0Y/S6Q7YPFEMHkT3bFR2uwtfOA+u3GJ mGiXbRpTURQvLjeDq2JhwTVvAna1yQNnHA9zHtHYh9xcU4lfCoaD2RudWPdLif448og8S m6kAPrT3nhdMMZtTUUg2yxjwm+NyNvp5prUVcQWkHYv9nEcyUXgAm5w81XK62Ahl+8aXV wobRdZlD5ysenf+TX+8E8r7xlEBI4TxbY1Q7GRfV5fsJH5otVVM4/poZwY5FYL4Whfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309801; h=DMARC-Filter:DKIM-Signature:Mime-Version:References: X-Lms-Return-Path:To:Date:Message-Id:Content-Type:In-Reply-To:Cc: Received:Content-Disposition:From:Subject:X-Original-From: Content-Transfer-Encoding; bh=0NrVvtL+KEyNjegytJS9pxOjxu4S2OKiBr/CisU3c4I=; b=3d9G0i3Kxzv0G7JGH7EK2oin96GWGrEGhvn/fbRUTBiKGUO70JKse/B7makz8PdSgOet p+UqA0zC9Gk3c37ksCtsdppTydvUzIfh3uGOD82HBTO+8KI+NIIgKV6RucKAgj2qN3wVj PQou3k7yHYfVfDu6J6VeDbsqLi5m7kHqGBUkCi8ohnVBuWgCk0iH4RLGCKXdVKGgmw3xa 5T+l/HCOoCenG52W/Zg6Y0buzLUgCiV4eejVhviBEvfHXKErTX2crO2NFJztMRMYPKBsn aPxtmSIuAomCdpvR2DZbowADpmtxvCrWQPVU/PdfJDuHNqAKjeB7V76KQ4+iX4Foirw== 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=M+w1NLrS; arc=none smtp.remote-ip=209.127.231.55 Received: from va-2-55.ptr.blmpb.com (va-2-55.ptr.blmpb.com [209.127.231.55]) (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 7F965606A33E for ; Thu, 3 Dec 2026 14:56:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F965606A33E 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, unprotected) 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=M+w1NLrS DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=fygo-io.20200929.dkim.larksuite.com; t=1796309790; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=0NrVvtL+KEyNjegytJS9pxOjxu4S2OKiBr/CisU3c4I=; b=M+w1NLrSf9OC4keYDanudKGw4U7KAmj6QJk55TbyjR7NuJcLJRbqZygLkkHq/QALZOg/Km aowQkCJzf+Cr3Yw4+l+zhbtUy1dRsE9Apiw8XOy87g4nlmRThvRB8fdCdzE2ANDzypp27n 8aO6sL/m3qQtYepj9FZHcmE9idP2GveuehG4ygtNno6QvQM3fNqxLaOtHaN0LuAv7RwmT2 nEYIwV60WwVyusj436vTCArcAEWgQvmOtMFtUO2nLLR1FpEtPx5MPFELreAHvx39sB6KN5 iRztTnzaJVJ3UV1jfTgvLw1Okoo0nGr0U4DpYeuuHSKCp5yQUAQpGW7TqEdABw== X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261103070122.1208383-1-robertpang@google.com> X-Lms-Return-Path: To: "Robert Pang" Date: Thu, 3 Dec 2026 22:56:26 +0800 Message-Id: Content-Type: text/plain; charset=UTF-8 In-Reply-To: <20261103070122.1208383-1-robertpang@google.com> Cc: , , , , Received: from studio.local ([120.245.64.92]) by smtp.larksuite.com with ESMTPS; Thu, 03 Dec 2026 14:56:28 +0000 Content-Disposition: inline From: "Coly Li" Subject: Re: [PATCH] bcache: allow more bucket reclaims during garbage collection X-Original-From: Coly Li Content-Transfer-Encoding: 7bit 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 > --- > 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