[PATCH 1/3] blkcg: allow printing rwstat samples without policy data

From: Zhe Liu

Date: Tue Nov 10 2026 - 05:40:46 EST


The existing rwstat formatter takes a blkg_policy_data pointer, although
it only uses it to obtain the associated blkg. This unnecessarily ties
statistics formatting to a policy.

Introduce blkg_print_rwstat() to print rwstat samples directly from a
blkg, allowing cgroup v1 I/O statistics to be reported independently of
the throttle policy.

Keep __blkg_prfill_rwstat() as a wrapper for existing policy users,
including BFQ. The output format and total calculation remain unchanged.

Signed-off-by: Zhe Liu <liuzhe1@xxxxxxxxxx>
---
block/blk-cgroup-rwstat.c | 18 ++++++++++++------
block/blk-cgroup-rwstat.h | 2 ++
2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/block/blk-cgroup-rwstat.c b/block/blk-cgroup-rwstat.c
index 2e9bf081cce2..604d8414dec6 100644
--- a/block/blk-cgroup-rwstat.c
+++ b/block/blk-cgroup-rwstat.c
@@ -26,15 +26,15 @@ void blkg_rwstat_exit(struct blkg_rwstat *rwstat)
EXPORT_SYMBOL_GPL(blkg_rwstat_exit);

/**
- * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
+ * blkg_print_rwstat - print a blkg_rwstat sample
* @sf: seq_file to print to
- * @pd: policy private data of interest
+ * @blkg: block cgroup and queue association
* @rwstat: rwstat to print
*
- * Print @rwstat to @sf for the device assocaited with @pd.
+ * Print @rwstat to @sf for the device associated with @blkg.
*/
-u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
- const struct blkg_rwstat_sample *rwstat)
+u64 blkg_print_rwstat(struct seq_file *sf, struct blkcg_gq *blkg,
+ const struct blkg_rwstat_sample *rwstat)
{
static const char *rwstr[] = {
[BLKG_RWSTAT_READ] = "Read",
@@ -43,7 +43,7 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
[BLKG_RWSTAT_ASYNC] = "Async",
[BLKG_RWSTAT_DISCARD] = "Discard",
};
- const char *dname = blkg_dev_name(pd->blkg);
+ const char *dname = blkg_dev_name(blkg);
u64 v;
int i;

@@ -60,6 +60,12 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
seq_printf(sf, "%s Total %llu\n", dname, v);
return v;
}
+
+u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
+ const struct blkg_rwstat_sample *rwstat)
+{
+ return blkg_print_rwstat(sf, pd->blkg, rwstat);
+}
EXPORT_SYMBOL_GPL(__blkg_prfill_rwstat);

/**
diff --git a/block/blk-cgroup-rwstat.h b/block/blk-cgroup-rwstat.h
index 703a16fe1404..014ac2a73306 100644
--- a/block/blk-cgroup-rwstat.h
+++ b/block/blk-cgroup-rwstat.h
@@ -41,6 +41,8 @@ static inline u64 blkg_rwstat_read_counter(struct blkg_rwstat *rwstat,

int blkg_rwstat_init(struct blkg_rwstat *rwstat, gfp_t gfp);
void blkg_rwstat_exit(struct blkg_rwstat *rwstat);
+u64 blkg_print_rwstat(struct seq_file *sf, struct blkcg_gq *blkg,
+ const struct blkg_rwstat_sample *rwstat);
u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
const struct blkg_rwstat_sample *rwstat);
u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
--
2.25.1