Linux-Block Archive mirror
 help / color / mirror / Atom feed
From: zhoutaiyu <zhoutaiyu@kuaishou.com>
To: <tj@kernel.org>
Cc: <josef@toxicpanda.com>, <axboe@kernel.dk>,
	<cgroups@vger.kernel.org>, <linux-block@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] blk-throttle: fix repeat limit on bio with BIO_BPS_THROTTLED
Date: Fri, 19 Apr 2024 20:07:47 +0800	[thread overview]
Message-ID: <20240419120747.38031-1-zhoutaiyu@kuaishou.com> (raw)

Give a concrete example, a bio is throtted because of reaching bps
limit. It is then dispatched to request layer after a delay. In the
request layer, it is split and the split bio flagged with
BIO_BPS_THROTTLED will re-enter blkthrottle.
The bio with BIO_BPS_THROTTLED should not be throttled for its bytes
again. However, when the bps_limit and iops_limit are both set and
sq->queue is not empty, the bio will be throttled again even the tg is
still within iops limit.

Test scrips:
cgpath=/sys/fs/cgroup/blkio/test0
mkdir -p $cgpath
echo "8:0 10485760" > $cgpath/blkio.throttle.write_bps_device
echo "8:16 100000" > $cgpath/blkio.throttle.write_iops_device
for ((i=0;i<50;i++));do
  fio -rw=write -direct=1 -bs=4M -iodepth=8 -size=200M -numjobs=1 \
-time_based=1 -runtime=30  -name=testt_$i -filename=testf_$i > /dev/null &
  echo $! > $cgpath/tasks
done

The output of iostat:
Device:  ...  wMB/s  ...
sdb      ...  3.75  ...
sdb      ...  2.50  ...
sdb      ...  3.75  ...
sdb      ...  2.50  ...
sdb      ...  3.75  ...

In order to fix this problem, early throttled the bio only when
sq->queue is no empty and the bio is not flagged with BIO_BPS_THROTTLED.

Signed-off-by: zhoutaiyu <zhoutaiyu@kuaishou.com>
---
 block/blk-throttle.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index f4850a6..499c006 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -913,7 +913,8 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio,
 	 * queued.
 	 */
 	BUG_ON(tg->service_queue.nr_queued[rw] &&
-	       bio != throtl_peek_queued(&tg->service_queue.queued[rw]));
+	       bio != throtl_peek_queued(&tg->service_queue.queued[rw]) &&
+	       !bio_flagged(bio, BIO_BPS_THROTTLED));
 
 	/* If tg->bps = -1, then BW is unlimited */
 	if ((bps_limit == U64_MAX && iops_limit == UINT_MAX) ||
@@ -2201,7 +2202,7 @@ bool __blk_throtl_bio(struct bio *bio)
 		throtl_downgrade_check(tg);
 		throtl_upgrade_check(tg);
 		/* throtl is FIFO - if bios are already queued, should queue */
-		if (sq->nr_queued[rw])
+		if (sq->nr_queued[rw] && !bio_flagged(bio, BIO_BPS_THROTTLED))
 			break;
 
 		/* if above limits, break to queue */
-- 
1.8.3.1


             reply	other threads:[~2024-04-19 12:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 12:07 zhoutaiyu [this message]
2024-04-20  1:48 ` [PATCH] blk-throttle: fix repeat limit on bio with BIO_BPS_THROTTLED Yu Kuai
2024-04-22  3:33   ` 周泰宇
2024-04-22  3:47     ` Yu Kuai
2024-04-22 17:39       ` tj
2024-04-23  1:50         ` Yu Kuai
2024-04-23  2:29           ` 周泰宇
2024-04-22  9:42     ` Yu Kuai
2024-04-22 13:05       ` 周泰宇

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=20240419120747.38031-1-zhoutaiyu@kuaishou.com \
    --to=zhoutaiyu@kuaishou.com \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).