[PATCH v2] blk-throttle: add opt-in eager activation for cgroup v1 stats
From: Zhe Liu
Date: Fri Nov 20 2026 - 06:14:09 EST
Commit a3166c51702b ("blk-throttle: delay initialization until
configuration") deferred throttle policy activation until an I/O limit is
configured. However, cgroup v1 accounting still lives in the throttle
policy and is performed after the activation check in blk_should_throtl().
Without an activated throttle policy, v1 statistics such as
blkio.throttle.io_service_bytes remain zero even while I/O is issued.
This forces cgroup v1 users to configure the throttle policy just
to obtain I/O statistics, even when no throttling is needed.
Add a read-only boot parameter, blk_throttle.eager_init, to activate
the throttle policy at disk initialization, regardless of the current
cgroup hierarchy. This allows cgroup v1 users to collect I/O statistics
without configuring throttle limits. Keep lazy activation as the
default to retain its memory and CPU savings.
Tested on next-20261119 in an x86-64 QEMU guest with
lockdep enabled. With no throttle limits configured, a 1 MiB O_DIRECT
write to /dev/ram0 produced these blkio.throttle.io_service_bytes
results:
Baseline: 0 bytes
Patched, default: 0 bytes
Patched, eager_init=1: 1048576 bytes
Fixes: a3166c51702b ("blk-throttle: delay initialization until configuration")
Signed-off-by: Zhe Liu <liuzhe1@xxxxxxxxxx>
---
Changes in v2:
Replace the v1 accounting rework with a boot parameter that activates
the existing throttle policy at disk allocation.
Document the parameter and its effect on cgroup v1 statistics.
.../admin-guide/cgroup-v1/blkio-controller.rst | 11 +++++++++++
Documentation/admin-guide/kernel-parameters.txt | 11 +++++++++++
block/blk-cgroup.c | 7 ++++++-
block/blk-throttle.c | 11 +++++++++++
block/blk-throttle.h | 2 ++
5 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/cgroup-v1/blkio-controller.rst b/Documentation/admin-guide/cgroup-v1/blkio-controller.rst
index dabb80cdd25a..6a9e4239e0fd 100644
--- a/Documentation/admin-guide/cgroup-v1/blkio-controller.rst
+++ b/Documentation/admin-guide/cgroup-v1/blkio-controller.rst
@@ -49,6 +49,17 @@ Run dd to read a file and see if rate is throttled to 1MB/s or not::
Limits for writes can be put using blkio.throttle.write_bps_device file.
+I/O statistics without throttling
+---------------------------------
+
+By default, ``blkio.throttle.io_service_bytes``,
+``blkio.throttle.io_serviced`` and their recursive variants start counting
+I/O for a disk on the first write to a throttle limit file for that disk.
+
+To collect these statistics without setting upper I/O rate limits, add
+``blk_throttle.eager_init=1`` to the kernel command line. This activates
+the throttling policy as each disk is created.
+
Hierarchical Cgroups
====================
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 1e8317483844..47749c67671a 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -646,6 +646,17 @@ Kernel parameters
embedded devices based on command line input.
See Documentation/block/cmdline-partition.rst
+ blk_throttle.eager_init=
+ [KNL] Format: <bool>
+ Requires CONFIG_BLK_DEV_THROTTLING=y.
+ Enable cgroup v1 throttle statistics without setting
+ upper I/O rate limits.
+ Activate blk-throttle when each disk is created.
+ Eager initialization uses additional memory for each disk.
+ The parameter is read-only at runtime.
+ Default: off (initialize on the first throttle limit
+ write).
+
boot_delay= [KNL,EARLY]
Milliseconds to delay each printk during boot.
Only works if CONFIG_BOOT_PRINTK_DELAY is enabled,
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 5b7a32293dc6..cf243a3ac32f 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1490,6 +1490,7 @@ int blkcg_init_disk(struct gendisk *disk)
struct request_queue *q = disk->queue;
struct blkcg_gq *new_blkg, *blkg;
bool preloaded;
+ int ret;
/*
* If the queue is shared across disk rebind (e.g., SCSI), the
@@ -1521,7 +1522,11 @@ int blkcg_init_disk(struct gendisk *disk)
if (preloaded)
radix_tree_preload_end();
- return 0;
+ ret = blk_throtl_init_disk(disk);
+ if (ret)
+ blkg_destroy_all(disk);
+
+ return ret;
err_unlock:
spin_unlock_irq(&q->queue_lock);
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index c5e26551956a..527937aa552c 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -26,6 +26,10 @@
/* A workqueue to queue throttle related work */
static struct workqueue_struct *kthrotld_workqueue;
+static bool eager_init;
+module_param(eager_init, bool, 0444);
+MODULE_PARM_DESC(eager_init, "Initialize blk-throttle eagerly for each disk");
+
#define rb_entry_tg(node) rb_entry((node), struct throtl_grp, rb_node)
struct throtl_data
@@ -1349,6 +1353,13 @@ static int blk_throtl_init(struct gendisk *disk)
return ret;
}
+int blk_throtl_init_disk(struct gendisk *disk)
+{
+ if (!eager_init)
+ return 0;
+
+ return blk_throtl_init(disk);
+}
static ssize_t tg_set_conf(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off, bool is_u64)
diff --git a/block/blk-throttle.h b/block/blk-throttle.h
index 1b5775771e07..4e275794138b 100644
--- a/block/blk-throttle.h
+++ b/block/blk-throttle.h
@@ -144,10 +144,12 @@ static inline struct throtl_grp *blkg_to_tg(struct blkcg_gq *blkg)
* Internal throttling interface
*/
#ifndef CONFIG_BLK_DEV_THROTTLING
+static inline int blk_throtl_init_disk(struct gendisk *disk) { return 0; }
static inline void blk_throtl_exit(struct gendisk *disk) { }
static inline bool blk_throtl_bio(struct bio *bio) { return false; }
static inline void blk_throtl_cancel_bios(struct gendisk *disk) { }
#else /* CONFIG_BLK_DEV_THROTTLING */
+int blk_throtl_init_disk(struct gendisk *disk);
void blk_throtl_exit(struct gendisk *disk);
bool __blk_throtl_bio(struct bio *bio);
void blk_throtl_cancel_bios(struct gendisk *disk);
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
--
2.25.1