From: Ming Lei <ming.lei@redhat.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, Tejun Heo <tj@kernel.org>,
"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] block: throttle: don't add one extra jiffy mistakenly for bps limit
Date: Fri, 21 Feb 2025 16:59:22 +0800 [thread overview]
Message-ID: <Z7hAauGfBrwNBRkz@fedora> (raw)
In-Reply-To: <7a113162-a2c1-fad4-3395-7bc39d05b5c4@huaweicloud.com>
On Fri, Feb 21, 2025 at 02:29:30PM +0800, Yu Kuai wrote:
> Hi,
>
> 在 2025/02/21 12:18, Ming Lei 写道:
> > > - jiffy_wait = div64_u64(extra_bytes * HZ, bps_limit);
> > > -
> > > - if (!jiffy_wait)
> > > - jiffy_wait = 1;
> > > + jiffy_wait = div64_u64_rem(extra_bytes * HZ, bps_limit,
> > > &carryover_bytes);
> > > + tg->carryover_bytes[rw] -= div64_u64(carryover_bytes, HZ);
> > Can you explain a bit why `carryover_bytes/HZ` is subtracted instead of
> > carryover_bytes?
>
> For example, if bps_limit is 1000, extra_bytes is 9, then:
>
> jiffy_wait = (9 * 100) / 1000 = 0;
> carryover_bytes = (9 * 100) % 1000 = 900;
>
> Hence we need to divide it by HZ:
> tg->carryover_bytes = 0 - 900/100 = -9;
>
> -9 can be considered debt, and for the next IO, the bytes_allowed will
> consider the carryover_bytes.
Got it, it is just because the dividend is 'extra_bytes * HZ', so the remainder
need to be divided by HZ.
> >
> > Also tg_within_bps_limit() may return 0 now, which isn't expected.
>
> I think it's expected, this IO will now be dispatched directly instead
> of wait for one more jiffies, and debt will be paid if there are
> following IOs.
OK.
>
> And if the tg idle for a long time before dispatching the next IO,
> tg_trim_slice() should handle this case and avoid long slice end. This
> is not quite handy, perhaps it's better to add a helper like
> tg_in_debt() before throtl_start_new_slice() to hande this case.
>
> BTW, we must update the comment about carryover_bytes/ios, it's alredy
> used as debt.
Indeed, the approach is similar with the handling for
bio_issue_as_root_blkg().
Tested-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
next prev parent reply other threads:[~2025-02-21 8:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 11:17 [PATCH] block: throttle: don't add one extra jiffy mistakenly for bps limit Ming Lei
2025-02-20 13:38 ` Yu Kuai
2025-02-21 2:55 ` Ming Lei
2025-02-21 3:16 ` Ming Lei
2025-02-21 3:39 ` Yu Kuai
2025-02-21 4:18 ` Ming Lei
2025-02-21 6:29 ` Yu Kuai
2025-02-21 8:59 ` Ming Lei [this message]
2025-02-22 3:01 ` Yu Kuai
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=Z7hAauGfBrwNBRkz@fedora \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=tj@kernel.org \
--cc=yukuai1@huaweicloud.com \
--cc=yukuai3@huawei.com \
/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