blk-cgroup: skip rstat flush for cgroups without blkgs
Subsystems (3)
PATCH v2 1/1 blk-cgroup: skip rstat flush for cgroups without blkgs
Non-root io.stat reads flush the blkcg rstat subtree before walking ->blkg_list. This takes the subsystem rstat lock and checks for pending updates on every possible CPU, even when there is no per-device state to print.
Blkg creation is hierarchical. A descendant blkg implies an ancestor blkg on the same device, so an empty ->blkg_list means the subtree cannot contribute any output. Return early in that case.
A concurrent first blkg may be deferred to the next read. This is consistent with the existing non-atomic flush and list walk. i
This is not rare: 340 of 969 io.stat files were empty on a 316-CPU host. In a 16-vCPU guest, the median open/read/close time over 35 batches of 20,000 reads changed as follows:
before after empty io.stat 7.02 us 5.47 us populated io.stat 7.84 us 7.83 us
This is a ~22% reduction for empty reads. Populated reads were unchanged.
---
v1 -> v2:
- Updated commit message with perf numbers with lockdep disabled (Tejun)
--- block/blk-cgroup.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
block/blk-cgroup.c +9 -2
@@ -1189,10 +1189,17 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)struct blkcg *blkcg =css_to_blkcg (seq_css (sf));struct blkcg_gq *blkg; -if (!seq_css (sf)->parent) +if (!seq_css (sf)->parent) {blkcg_fill_root_iostats (); -else + }else { +/* +* Descendant blkgs imply ancestor blkgs, so an empty +* ->blkg_list has no stats to report. +*/ +if (hlist_empty (&blkcg->blkg_list)) +return 0 ;css_rstat_flush (&blkcg->css); + }guard (spinlock_irq)(&blkcg->lock);hlist_for_each_entry (blkg, &blkcg->blkg_list, blkcg_node)
Signature · 1 line
2.53.0-Meta
Applied to cgroup/for-7.4 with the stray "i" line in the description removed.
Thanks.
--
tejun
Dear patch submitter,
Blktests CI has tested the following submission:
Status: FAILURE Name: [v2] blk-cgroup: skip rstat flush for cgroups without blkgs Patchwork: https://patchwork.kernel.org/series/1170402/&state=* Run record: https://github.com/linux-blktests/linux-block/actions/runs/37647078673
Failed test cases: block/034
Quoted 10 lines · On Oct 08, 2026 / 19:32, [email protected] wrote:
Dear patch submitter,
Blktests CI has tested the following submission:
Status: FAILURE Name: [v2] blk-cgroup: skip rstat flush for cgroups without blkgs Patchwork: https://patchwork.kernel.org/series/1170402/&state=* Run record: https://github.com/linux-blktests/linux-block/actions/runs/37647078673Failed test cases: block/034
Please ignore this failure report. The blktests test case block/034 failed in the automated CI test run for the patch titled. However, the test case has nothing to do with blk-cgroup. Sorry for the noise.