Re: Fwd: [PATCH v2] bcache: use bio cloning for detached device requests

Kent Overstreet <[email protected]> Wed, 21 Jan 2026 17:48:37 -0500
Newsgroups org.kernel.vger.linux-bcache,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Wed, Jan 21, 2026 at 09:34:01AM +0800, Coly Li wrote:
> On Tue, Jan 20, 2026 at 08:01:52AM +0800, Jens Axboe wrote:
> > On 1/20/26 7:46 AM, Coly Li wrote:
> > >> @@ -949,6 +950,11 @@ static int bcache_device_init(struct
> > >> bcache_device *d, unsigned int block_size,
> > >>                         BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
> > >>                 goto out_ida_remove;
> > >>
> > >> +       if (bioset_init(&d->bio_detach, 4,
> > > 					^^^^^-> I feel 4 might be a bit small
> > > here. bio_detached set is for normal IO when backing device is not
> > > attached to a cache device. I would suggest to set the pool size to
> > > 128 or 256.
> > 
> > Absolutely not, 4 is more than plenty. The pool elements are only ever
> > used if allocations fail, to guarantee forward progress. Setting aside
> > 128 or 256 for that case is utterly wasteful, you only need a couple. 4
> > is a good number, if anything it should be smaller (2).
> 
> Hi Jens,
> 
> Thanks for the information. Please correct me if I am wrong for the following
> text,
> - If the backing is a normal SSD raid0, the IOPS without attached cache device
> might be more than thousands. In this case, I assume 128 or 256 might be more
> tolerant.
> - I see what ‘4’ means, just not sure/comfortable when memory pressure is high.
> And reserving 128/256 will occupy around 0.5~1MB memory, I feel such extra
> memory is acceptable in bcache use case.
> 
> Don't get me wrong, I totally trust you. If '4' works well enough for high
> memory pressure condition for detached bcache device, it is cool.

I'd actually be in favor of raising it. mm isn't getting any better at
reclaim latency under load - I've been seeing regresisons in that area -
and considering that mm doesn't have its own reserves for allocations
critical for reclaim, code in reclaim paths probably should.

"How often it's used" on a well behaving system in a benchmark scenario
is not relevant, the relevant thing to look at would be allocation
latency in OOM scenarios.

time_stats that bcache/bcachefs have is quite useful here. We recently
saw btree node allocation buffers taking > 10 seconds to allocate, so
this is a real issue.

Memory for bios is a drop in the bucket compared to the btree node
cache, so the amount of memory is not something to overly sweat here.