bcache: fix available bucket accounting in bucket allocation
PATCH 1/1 bcache: fix available bucket accounting in bucket allocation
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.
--- drivers/md/bcache/alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/bcache/alloc.c +2 -1
@@ -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 ) { ca->set->avail_nbuckets--;bch_update_bucket_in_use (ca->set, &ca->set->gc_stats); }
Signature · 1 line
2.56.0.398.g882cbad275-goog
Quoted 31 lines · Robert Pang
In
bch_bucket_alloc(), a cache set'savail_nbucketsis 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 onceCUTOFF_CACHE_ADDis reached, persisting until the next garbage collection cycle.Fix this by ensuring
avail_nbucketsis only decremented when the allocated bucket is already marked and not in theGC_MARK_RECLAIMABLEstate.Signed-off-by Robert Pang <[email protected]>--- drivers/md/bcache/alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/md/bcache/alloc.c +2
-2@@ -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 ) { ca->set->avail_nbuckets--;bch_update_bucket_in_use (ca->set, &ca->set->gc_stats); } --
Quoted 2 lines
2.56.0.398.g882cbad275-goog
Hi all,
Here is some more context on this fix. This issue was observed during the investigation of [1]. We believe this is a latent issue exposed by longer garbage collection durations following commit 009073806fbc ("bcache: reduce gc latency by processing less nodes and sleep less time") to reduce front IO tail latency during GC.
Best regards,
Robert Pang