Linux block layer
 help / color / mirror / Atom feed
From: John Garry <john.g.garry@oracle.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: tj@kernel.org, axboe@kernel.dk, josef@toxicpanda.com,
	shli@fb.com, linux-block@vger.kernel.org,
	cgroups@vger.kernel.org
Subject: Re: [PATCH] blk-throttle: Fix W=1 build issue in tg_prfill_limit()
Date: Tue, 26 Mar 2024 08:46:24 +0000	[thread overview]
Message-ID: <a4d8b56e-1814-4834-9d25-ef61ff6f1248@oracle.com> (raw)
In-Reply-To: <ZgJzNvN4nQqKnhk5@infradead.org>

On 26/03/2024 07:03, Christoph Hellwig wrote:
> On Mon, Mar 25, 2024 at 12:19:05PM +0000, John Garry wrote:
>> For when using gcc 8 and above, the following warnings can be seen when
>> compiling blk-throttle.c with W=1:
> 
> Why is this function even using these local buffers vs a sequence
> of separate seq_printf calls that would get rid of these pointless
> on-stack buffers?

Currently a combo of snprintf and seq_printf is used, a strategy which 
seems to go as far back as 2ee867dcfa2ea (2015), when it was a much 
simpler print. All the other code in this area only uses seq_printf, so 
it seems that the author(s) prefer this way here.

Here's how the current code could look (using only seq_printf):

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;

	if (off == LIMIT_LOW) {
		bps_dft = 0;
		iops_dft = 0;
	} else {
		bps_dft = U64_MAX;
		iops_dft = UINT_MAX;
	}

	if (tg->bps_conf[READ][off] == bps_dft &&
	    tg->bps_conf[WRITE][off] == bps_dft &&
	    tg->iops_conf[READ][off] == iops_dft &&
	    tg->iops_conf[WRITE][off] == iops_dft &&
	    (off != LIMIT_LOW ||
	     (tg->idletime_threshold_conf == DFL_IDLE_THRESHOLD &&
	      tg->latency_target_conf == DFL_LATENCY_TARGET)))
		return 0;

	seq_printf(sf, "%s rbps=", dname);
	if (tg->bps_conf[READ][off] == U64_MAX)
		seq_printf(sf, "max");
	else
		seq_printf(sf, "%llu", tg->bps_conf[READ][off]);

	if (tg->bps_conf[WRITE][off] == U64_MAX)
		seq_printf(sf, " wbps=max ");
	else
		seq_printf(sf, " wbps=%llu ", tg->bps_conf[WRITE][off]);

	if (tg->iops_conf[READ][off] == UINT_MAX)
		seq_printf(sf, " riops=max");
	else
		seq_printf(sf, " riops=%u", tg->iops_conf[READ][off]);

	if (tg->iops_conf[WRITE][off] == UINT_MAX)
		seq_printf(sf, " wiops=max");
	else
		seq_printf(sf, " wiops=%u", tg->iops_conf[WRITE][off]);

	if (off == LIMIT_LOW) {
		if (tg->idletime_threshold_conf == ULONG_MAX)
			seq_printf(sf, " idle=max");
		else
			seq_printf(sf, " idle=%lu", tg->idletime_threshold_conf);

		if (tg->latency_target_conf == ULONG_MAX)
			seq_printf(sf, " latency=max");
		else
			seq_printf(sf, " latency=%lu", tg->latency_target_conf);
	}

	return 0;
}

better?

Thanks,
John

  reply	other threads:[~2024-03-26  8:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 12:19 [PATCH] blk-throttle: Fix W=1 build issue in tg_prfill_limit() John Garry
2024-03-26  7:03 ` Christoph Hellwig
2024-03-26  8:46   ` John Garry [this message]
2024-03-26 14:49     ` Christoph Hellwig
2024-03-26 14:57       ` John Garry

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=a4d8b56e-1814-4834-9d25-ef61ff6f1248@oracle.com \
    --to=john.g.garry@oracle.com \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=hch@infradead.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=shli@fb.com \
    --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