Skip to content

Commit 2a0f61e

Browse files
committed
blk-throttle: set REQ_THROTTLED from throtl_charge_bio() and gate stats update with it
With proper hierarchy support, a bio can be dispatched multiple times until it reaches the top-level service_queue and we don't want to update dispatch stats at each step. They are local stats and will be kept local. If recursive stats are necessary, they should be implemented separately and definitely not by updating counters recursively on each dispatch. This patch moves REQ_THROTTLED setting to throtl_charge_bio() and gate stats update with it so that dispatch stats are updated only on the first time the bio is charged to a throtl_grp, which will always be the throtl_grp the bio was originally queued to. This means that REQ_THROTTLED would be set even for bios which don't get throttled. As we don't want bios to leave blk-throtl with the flag set, move REQ_THROTLLED clearing to the end of blk_throtl_bio() and clear if the bio is being issued directly. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Vivek Goyal <vgoyal@redhat.com>
1 parent fda6f27 commit 2a0f61e

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,22 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
757757
tg->bytes_disp[rw] += bio->bi_size;
758758
tg->io_disp[rw]++;
759759

760-
throtl_update_dispatch_stats(tg_to_blkg(tg), bio->bi_size, bio->bi_rw);
760+
/*
761+
* REQ_THROTTLED is used to prevent the same bio to be throttled
762+
* more than once as a throttled bio will go through blk-throtl the
763+
* second time when it eventually gets issued. Set it when a bio
764+
* is being charged to a tg.
765+
*
766+
* Dispatch stats aren't recursive and each @bio should only be
767+
* accounted by the @tg it was originally associated with. Let's
768+
* update the stats when setting REQ_THROTTLED for the first time
769+
* which is guaranteed to be for the @bio's original tg.
770+
*/
771+
if (!(bio->bi_rw & REQ_THROTTLED)) {
772+
bio->bi_rw |= REQ_THROTTLED;
773+
throtl_update_dispatch_stats(tg_to_blkg(tg), bio->bi_size,
774+
bio->bi_rw);
775+
}
761776
}
762777

763778
static void throtl_add_bio_tg(struct bio *bio, struct throtl_grp *tg)
@@ -821,7 +836,6 @@ static void tg_dispatch_one_bio(struct throtl_grp *tg, bool rw)
821836

822837
throtl_charge_bio(tg, bio);
823838
bio_list_add(&sq->parent_sq->bio_lists[rw], bio);
824-
bio->bi_rw |= REQ_THROTTLED;
825839

826840
throtl_trim_slice(tg, rw);
827841
}
@@ -1128,10 +1142,9 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
11281142
struct blkcg *blkcg;
11291143
bool throttled = false;
11301144

1131-
if (bio->bi_rw & REQ_THROTTLED) {
1132-
bio->bi_rw &= ~REQ_THROTTLED;
1145+
/* see throtl_charge_bio() */
1146+
if (bio->bi_rw & REQ_THROTTLED)
11331147
goto out;
1134-
}
11351148

11361149
/*
11371150
* A throtl_grp pointer retrieved under rcu can be used to access
@@ -1205,6 +1218,13 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
12051218
out_unlock_rcu:
12061219
rcu_read_unlock();
12071220
out:
1221+
/*
1222+
* As multiple blk-throtls may stack in the same issue path, we
1223+
* don't want bios to leave with the flag set. Clear the flag if
1224+
* being issued.
1225+
*/
1226+
if (!throttled)
1227+
bio->bi_rw &= ~REQ_THROTTLED;
12081228
return throttled;
12091229
}
12101230

0 commit comments

Comments
 (0)