lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANubcdUT+PoGs3j=0ZN5jsntU-hNGHRFQoucKJZvYGXxFC75ng@mail.gmail.com>
Date: Wed, 21 Jan 2026 19:55:01 +0800
From: Stephen Zhang <starzhangzsd@...il.com>
To: Coly Li <colyli@...as.com>
Cc: Jens Axboe <axboe@...nel.dk>, Kent Overstreet <kent.overstreet@...ux.dev>, 
	Sasha Levin <sashal@...nel.org>, Christoph Hellwig <hch@...radead.org>, linux-bcache@...r.kernel.org, 
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>, zhangshida <zhangshida@...inos.cn>
Subject: Re: Fwd: [PATCH v2] bcache: use bio cloning for detached device requests

Coly Li <colyli@...as.com> 于2026年1月21日周三 09:34写道:
>
> 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.
>
> Thanks in advance.
>
> Coly Li

Hi Jens, Coly,

Regarding the discussion on the bio_detached pool size: while 4 is
sufficient to guarantee forward progress, some high-load environments
may prefer a larger reserve to minimize allocation latency under
extreme memory pressure.

To provide a middle ground, I propose adding a generic bioset_resize()
interface to the block layer and exposing it through a new bcache
sysfs attribute 'detached_pool_size'.

This allows us to keep the default value conservative (e.g., 4) to
avoid unnecessary memory overhead, while giving users the flexibility
to tune the emergency reserves based on their specific hardware and
workload requirements.

The patch is attached below. Does this look like a reasonable
compromise?

Thanks,
Shida
------------
>From 511d7404ce482d4ae8faf5911cf3e11bb791369e Mon Sep 17 00:00:00 2001
From: Shida Zhang <zhangshida@...inos.cn>
Date: Wed, 21 Jan 2026 19:32:06 +0800
Subject: [PATCH] block/bcache: introduce bioset_resize() and use it in bcache

Subsystems using bio_sets currently have their reserve pool sizes fixed at
initialization. In some scenarios, such as high-load storage environments or
memory-constrained systems, it is beneficial to adjust these emergency
reserves dynamically without tearing down the entire bioset.

Introduce bioset_resize() to allow the resizing of the bio_pool, bvec_pool,
within an existing bio_set.

Additionally, update bcache to expose this functionality. A new sysfs
attribute 'detached_pool_size' is added to bcache devices, allowing users
to tune the emergency reserve for detached bios based on production
workloads.

Signed-off-by: Shida Zhang <zhangshida@...inos.cn>
---
 block/bio.c               | 30 ++++++++++++++++++++++++++++++
 drivers/md/bcache/sysfs.c | 34 ++++++++++++++++++++++++++++++++++
 include/linux/bio.h       |  1 +
 3 files changed, 65 insertions(+)

diff --git a/block/bio.c b/block/bio.c
index e726c0e280a..8c80325e616 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1857,6 +1857,36 @@ int bioset_init(struct bio_set *bs,
 }
 EXPORT_SYMBOL(bioset_init);

+/**
+ * bioset_resize - resize a bio_set's reserve pools
+ * @bs: bio_set to resize
+ * @pool_size: new number of elements in the reserve pool
+ *
+ * Description:
+ *    Resizes the pre-allocated elements in a bio_set. This allows a subsystem
+ *    to increase or decrease its emergency reserves dynamically.
+ *
+ * Return:
+ *    0 on success, -ENOMEM on failure.
+ */
+int bioset_resize(struct bio_set *bs, unsigned int pool_size)
+{
+ int ret;
+
+ ret = mempool_resize(&bs->bio_pool, pool_size);
+ if (ret)
+ return ret;
+
+ if (bs->bvec_pool.pool_data) {
+ ret = mempool_resize(&bs->bvec_pool, pool_size);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(bioset_resize);
+
 static int __init init_bio(void)
 {
  int i;
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index 72f38e5b6f5..de63c04dafe 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -16,6 +16,7 @@
 #include <linux/blkdev.h>
 #include <linux/sort.h>
 #include <linux/sched/clock.h>
+#include <linux/bio.h>

 extern bool bcache_is_reboot;

@@ -150,6 +151,8 @@ rw_attribute(copy_gc_enabled);
 rw_attribute(idle_max_writeback_rate);
 rw_attribute(gc_after_writeback);
 rw_attribute(size);
+rw_attribute(detached_pool_size);
+

 static ssize_t bch_snprint_string_list(char *buf,
         size_t size,
@@ -167,6 +170,30 @@ static ssize_t bch_snprint_string_list(char *buf,
  return out - buf;
 }

+SHOW(bch_detached_pool_size)
+{
+ struct bcache_device *d = container_of(kobj, struct bcache_device, kobj);
+
+ return scnprintf(buf, PAGE_SIZE, "%u\n", d->bio_detached.bio_pool.min_nr);
+}
+
+STORE(bch_detached_pool_size)
+{
+ struct bcache_device *d = container_of(kobj, struct bcache_device, kobj);
+ unsigned int v;
+ int ret;
+
+ /* Bcache STORE macro uses 'size', not 'count' */
+ if (kstrtouint(buf, 10, &v) || v < 1)
+ return -EINVAL;
+
+ ret = bioset_resize(&d->bio_detached, v);
+ if (ret)
+ return ret;
+
+ return size;
+}
+
 SHOW(__bch_cached_dev)
 {
  struct cached_dev *dc = container_of(kobj, struct cached_dev,
@@ -282,6 +309,9 @@ SHOW(__bch_cached_dev)
  return strlen(buf);
  }

+ if (attr == &sysfs_detached_pool_size)
+ return bch_detached_pool_size_show(kobj, attr, buf);
+
 #undef var
  return 0;
 }
@@ -450,6 +480,9 @@ STORE(__cached_dev)
  if (attr == &sysfs_stop)
  bcache_device_stop(&dc->disk);

+ if (attr == &sysfs_detached_pool_size)
+ return bch_detached_pool_size_store(kobj, attr, buf, size);
+
  return size;
 }

@@ -540,6 +573,7 @@ static struct attribute *bch_cached_dev_attrs[] = {
 #endif
  &sysfs_backing_dev_name,
  &sysfs_backing_dev_uuid,
+ &sysfs_detached_pool_size,
  NULL
 };
 ATTRIBUTE_GROUPS(bch_cached_dev);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index c75a9b3672a..2d8a657000c 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -354,6 +354,7 @@ enum {
 extern int bioset_init(struct bio_set *, unsigned int, unsigned int,
int flags);
 extern void bioset_exit(struct bio_set *);
 extern int biovec_init_pool(mempool_t *pool, int pool_entries);
+int bioset_resize(struct bio_set *bs, unsigned int pool_size);

 struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,
       blk_opf_t opf, gfp_t gfp_mask,
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ