mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Usama Arif <usama.arif@linux.dev>
To: axboe@kernel.dk, cgroups@vger.kernel.org, josef@toxicpanda.com,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	tj@kernel.org
Cc: hannes@cmpxchg.org, mkoutny@suse.com, shakeel.butt@linux.dev,
	riel@surriel.com, Usama Arif <usama.arif@linux.dev>
Subject: [PATCH] blk-cgroup: skip rstat flush for cgroups without blkgs
Date: Thu, 17 Sep 2026 09:10:20 -0700	[thread overview]
Message-ID: <20260917161020.4139163-1-usama.arif@linux.dev> (raw)

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


             reply	other threads:[~2026-09-17 16:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 16:10 Usama Arif [this message]
2026-09-17 16:31 ` Tejun Heo
2026-09-17 17:41   ` Usama Arif

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260917161020.4139163-1-usama.arif@linux.dev \
    --to=usama.arif@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=riel@surriel.com \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®