From: Tao Cui <cui.tao@linux.dev>
To: axboe@kernel.dk, tj@kernel.org, josef@toxicpanda.com
Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, Tao Cui <cuitao@kylinos.cn>
Subject: [PATCH 2/2] blk-throttle: factor out limit field printing in tg_prfill_limit()
Date: Tue, 14 Jul 2026 18:30:28 +0800 [thread overview]
Message-ID: <20260714103028.1334831-3-cui.tao@linux.dev> (raw)
In-Reply-To: <20260714103028.1334831-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
The four rbps/wbps/riops/wiops blocks in tg_prfill_limit() are identical
apart from the key string and whether the limit is 64- or 32-bit. Factor
them into tg_prfill_limit_field() and drop the bps_dft / iops_dft alias
locals in favor of U64_MAX / UINT_MAX directly.
The io.max seq_file output is byte-for-byte unchanged.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
block/blk-throttle.c | 48 ++++++++++++++++++--------------------------
1 file changed, 19 insertions(+), 29 deletions(-)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index f37911abefdd..8f4563acbc16 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1489,47 +1489,37 @@ static struct cftype throtl_legacy_files[] = {
{ } /* terminate */
};
+static void tg_prfill_limit_field(struct seq_file *sf, const char *key,
+ u64 val, bool is_uint)
+{
+ u64 dflt = is_uint ? UINT_MAX : U64_MAX;
+
+ if (val == dflt)
+ seq_printf(sf, " %s=max", key);
+ else if (is_uint)
+ seq_printf(sf, " %s=%u", key, (unsigned int)val);
+ else
+ seq_printf(sf, " %s=%llu", key, val);
+}
+
static u64 tg_prfill_limit(struct seq_file *sf, struct blkg_policy_data *pd,
int off)
{
struct throtl_grp *tg = pd_to_tg(pd);
const char *dname = blkg_dev_name(pd->blkg);
- u64 bps_dft;
- unsigned int iops_dft;
if (!dname)
return 0;
- bps_dft = U64_MAX;
- iops_dft = UINT_MAX;
-
- if (tg->bps[READ] == bps_dft &&
- tg->bps[WRITE] == bps_dft &&
- tg->iops[READ] == iops_dft &&
- tg->iops[WRITE] == iops_dft)
+ if (tg->bps[READ] == U64_MAX && tg->bps[WRITE] == U64_MAX &&
+ tg->iops[READ] == UINT_MAX && tg->iops[WRITE] == UINT_MAX)
return 0;
seq_printf(sf, "%s", dname);
- if (tg->bps[READ] == U64_MAX)
- seq_printf(sf, " rbps=max");
- else
- seq_printf(sf, " rbps=%llu", tg->bps[READ]);
-
- if (tg->bps[WRITE] == U64_MAX)
- seq_printf(sf, " wbps=max");
- else
- seq_printf(sf, " wbps=%llu", tg->bps[WRITE]);
-
- if (tg->iops[READ] == UINT_MAX)
- seq_printf(sf, " riops=max");
- else
- seq_printf(sf, " riops=%u", tg->iops[READ]);
-
- if (tg->iops[WRITE] == UINT_MAX)
- seq_printf(sf, " wiops=max");
- else
- seq_printf(sf, " wiops=%u", tg->iops[WRITE]);
-
+ tg_prfill_limit_field(sf, "rbps", tg->bps[READ], false);
+ tg_prfill_limit_field(sf, "wbps", tg->bps[WRITE], false);
+ tg_prfill_limit_field(sf, "riops", tg->iops[READ], true);
+ tg_prfill_limit_field(sf, "wiops", tg->iops[WRITE], true);
seq_printf(sf, "\n");
return 0;
}
--
2.43.0
prev parent reply other threads:[~2026-07-14 10:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 10:30 [PATCH 0/2] blk-throttle: minor cleanups Tao Cui
2026-07-14 10:30 ` [PATCH 1/2] blk-throttle: avoid ilog2(0) in calculate_bytes_allowed() Tao Cui
2026-07-14 11:32 ` David Laight
2026-07-14 10:30 ` Tao Cui [this message]
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=20260714103028.1334831-3-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=cuitao@kylinos.cn \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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