mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] blk-throttle: fix repeat limit on bio with BIO_BPS_THROTTLED
@ 2024-04-19 12:07 zhoutaiyu
  2024-04-20  1:48 ` Yu Kuai
  0 siblings, 1 reply; 9+ messages in thread
From: zhoutaiyu @ 2024-04-19 12:07 UTC (permalink / raw)
  To: tj; +Cc: josef, axboe, cgroups, linux-block, linux-kernel

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-04-23  2:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19 12:07 [PATCH] blk-throttle: fix repeat limit on bio with BIO_BPS_THROTTLED zhoutaiyu
2024-04-20  1:48 ` 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       ` 周泰宇

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®