mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] blk-cgroup: skip rstat flush for cgroups without blkgs
@ 2026-09-17 16:10 Usama Arif
  2026-09-17 16:31 ` Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: Usama Arif @ 2026-09-17 16:10 UTC (permalink / raw)
  To: axboe, cgroups, josef, linux-block, linux-kernel, tj
  Cc: hannes, mkoutny, shakeel.butt, riel, Usama Arif

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.

This is not rare: 340 of 969 io.stat files were empty on a 316-CPU host.
In a 16-vCPU lockdep-enabled guest, the median
open/read/close time over 35 batches of 20,000 reads changed as follows:

                         before     after
  empty io.stat          49.1 us   41.0 us
  populated io.stat      49.9 us   50.2 us

This is a 16.6% reduction for empty reads. Populated reads were unchanged
within measurement noise.

Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
 block/blk-cgroup.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 2b5c29434e426..0d7a451473b04 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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)
-- 
2.53.0-Meta


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] blk-cgroup: skip rstat flush for cgroups without blkgs
  2026-09-17 16:10 [PATCH] blk-cgroup: skip rstat flush for cgroups without blkgs Usama Arif
@ 2026-09-17 16:31 ` Tejun Heo
  2026-09-17 17:41   ` Usama Arif
  0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2026-09-17 16:31 UTC (permalink / raw)
  To: Usama Arif
  Cc: axboe, cgroups, josef, linux-block, linux-kernel, hannes,
	mkoutny, shakeel.butt, riel

On Thu, Sep 17, 2026 at 09:10:20AM -0700, Usama Arif wrote:
> 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.
> 
> This is not rare: 340 of 969 io.stat files were empty on a 316-CPU host.
> In a 16-vCPU lockdep-enabled guest, the median

Can you please test on a kernel w/ lockdep disabled? It doesn't make much
sense to compare performance numbers with lockdep enabled.

> open/read/close time over 35 batches of 20,000 reads changed as follows:
> 
>                          before     after
>   empty io.stat          49.1 us   41.0 us
>   populated io.stat      49.9 us   50.2 us
> 
> This is a 16.6% reduction for empty reads. Populated reads were unchanged
> within measurement noise.
> 
> Signed-off-by: Usama Arif <usama.arif@linux.dev>

That said, I don't see any downsides:

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] blk-cgroup: skip rstat flush for cgroups without blkgs
  2026-09-17 16:31 ` Tejun Heo
@ 2026-09-17 17:41   ` Usama Arif
  0 siblings, 0 replies; 3+ messages in thread
From: Usama Arif @ 2026-09-17 17:41 UTC (permalink / raw)
  To: Tejun Heo
  Cc: axboe, cgroups, josef, linux-block, linux-kernel, hannes,
	mkoutny, shakeel.butt, riel



On 17/09/2026 17:31, Tejun Heo wrote:
> On Thu, Sep 17, 2026 at 09:10:20AM -0700, Usama Arif wrote:
>> 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.
>>
>> This is not rare: 340 of 969 io.stat files were empty on a 316-CPU host.
>> In a 16-vCPU lockdep-enabled guest, the median
> 
> Can you please test on a kernel w/ lockdep disabled? It doesn't make much
> sense to compare performance numbers with lockdep enabled.
> 

The updated numbers without lockdep are:

                             before    after
      empty io.stat           7.02 us   5.47 us
      populated io.stat       7.84 us   7.83 us

    The median paired reduction for empty reads was 22.1% (20.0-22.4% across
    pairs). System CPU time per read fell by 22.8%. Populated reads showed no
    consiste



>> open/read/close time over 35 batches of 20,000 reads changed as follows:
>>
>>                          before     after
>>   empty io.stat          49.1 us   41.0 us
>>   populated io.stat      49.9 us   50.2 us
>>
>> This is a 16.6% reduction for empty reads. Populated reads were unchanged
>> within measurement noise.
>>
>> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> 
> That said, I don't see any downsides:
> 
> Acked-by: Tejun Heo <tj@kernel.org>
> 
> Thanks.
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-17 17:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 16:10 [PATCH] blk-cgroup: skip rstat flush for cgroups without blkgs Usama Arif
2026-09-17 16:31 ` Tejun Heo
2026-09-17 17:41   ` Usama Arif

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®