Skip to contentSkip to conversation

blk-cgroup: don't update io stat for root cgroup

PATCH Applied Ming Lei 3 participants 3 messages Feb 2, 2023

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 blk-cgroup: don't update io stat for root cgroup

We source root cgroup stats from the system-wide stats, see blkcg_print_stat and blkcg_rstat_flush, so don't update io state for root cgroup.

Fixes blkg leak issue introduced in commit 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()") which starts to grab blkg's reference when adding iostat_cpu into percpu
blkcg list, but this state won't be consumed by blkcg_rstat_flush() where
the blkg reference is dropped.

Fixes 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()")
Cc Tejun Heo <[email protected]>
Cc Waiman Long <[email protected]>
---
 block/blk-cgroup.c | 4 ++++
 1 file changed, 4 insertions(+)
block/blk-cgroup.c +4 -0
index cb110fc51940..78f855c34746 100644
@@ -2034,6 +2034,10 @@ void blk_cgroup_bio_start(struct bio *bio)
 	struct blkg_iostat_set *bis;
 	unsigned long flags;
 
+	/* Root-level stats are sourced from system-wide IO stats */
+	if (!cgroup_parent(blkcg->css.cgroup))
+		return;
+
 	cpu = get_cpu();
 	bis = per_cpu_ptr(bio->bi_blkg->iostat_cpu, cpu);
 	flags = u64_stats_update_begin_irqsave(&bis->sync);
Signature · 1 line
2.31.1
maintainer Applied
#1 lore raw
Quoted 9 lines · Ming Lei

We source root cgroup stats from the system-wide stats, see blkcg_print_stat and blkcg_rstat_flush, so don't update io state for root cgroup.

Fixes blkg leak issue introduced in commit 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()") which starts to grab blkg's reference when adding iostat_cpu into percpu
blkcg list, but this state won't be consumed by blkcg_rstat_flush() where
the blkg reference is dropped.

[...]

Applied, thanks!

[1/1] blk-cgroup: don't update io stat for root cgroup

      commit: 0416f3be58c6b1ea066cd52e354b857693feb01e

Best regards,

Signature · 1 line
Jens Axboe
Acked-by on v1 1/1
#2 lore raw
In reply to Ming Lei
Quoted 23 lines · Ming Lei

We source root cgroup stats from the system-wide stats, see blkcg_print_stat and blkcg_rstat_flush, so don't update io state for root cgroup.

Fixes blkg leak issue introduced in commit 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()") which starts to grab blkg's reference when adding iostat_cpu into percpu
blkcg list, but this state won't be consumed by blkcg_rstat_flush() where
the blkg reference is dropped.

Fixes 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()")
Cc Tejun Heo <[email protected]>
Cc Waiman Long <[email protected]>
---
  block/blk-cgroup.c | 4 ++++
  1 file changed, 4 insertions(+)
block/blk-cgroup.c +0 -0
index cb110fc51940..78f855c34746 100644

block/blk-cgroup.c void blk_cgroup_bio_start(struct bio *bio) · line 2043

Quoted 10 lines
block/blk-cgroup.c +4 -0
@@ -2034,6 +2034,10 @@ void blk_cgroup_bio_start(struct bio *bio)
  	struct blkg_iostat_set *bis;
  	unsigned long flags;
 
+	/* Root-level stats are sourced from system-wide IO stats */
+	if (!cgroup_parent(blkcg->css.cgroup))
+		return;
+
  	cpu = get_cpu();
  	bis = per_cpu_ptr(bio->bi_blkg->iostat_cpu, cpu);
  	flags = u64_stats_update_begin_irqsave(&bis->sync);

Thanks for fixing this issue.

Cheers,
Longman