Skip to content

Commit ea0ea2b

Browse files
shligitaxboe
authored andcommitted
blk-throttle: cap discard request size
discard request usually is very big and easily use all bandwidth budget of a cgroup. discard request size doesn't really mean the size of data written, so it doesn't make sense to account it into bandwidth budget. Jens pointed out treating the size 0 doesn't make sense too, because discard request does have cost. But it's not easy to find the actual cost. This patch simply makes the size one sector. Signed-off-by: Shaohua Li <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6470812 commit ea0ea2b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

block/blk-throttle.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ static unsigned int tg_iops_limit(struct throtl_grp *tg, int rw)
382382
} \
383383
} while (0)
384384

385+
static inline unsigned int throtl_bio_data_size(struct bio *bio)
386+
{
387+
/* assume it's one sector */
388+
if (unlikely(bio_op(bio) == REQ_OP_DISCARD))
389+
return 512;
390+
return bio->bi_iter.bi_size;
391+
}
392+
385393
static void throtl_qnode_init(struct throtl_qnode *qn, struct throtl_grp *tg)
386394
{
387395
INIT_LIST_HEAD(&qn->node);
@@ -934,6 +942,7 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
934942
bool rw = bio_data_dir(bio);
935943
u64 bytes_allowed, extra_bytes, tmp;
936944
unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
945+
unsigned int bio_size = throtl_bio_data_size(bio);
937946

938947
jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
939948

@@ -947,14 +956,14 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
947956
do_div(tmp, HZ);
948957
bytes_allowed = tmp;
949958

950-
if (tg->bytes_disp[rw] + bio->bi_iter.bi_size <= bytes_allowed) {
959+
if (tg->bytes_disp[rw] + bio_size <= bytes_allowed) {
951960
if (wait)
952961
*wait = 0;
953962
return true;
954963
}
955964

956965
/* Calc approx time to dispatch */
957-
extra_bytes = tg->bytes_disp[rw] + bio->bi_iter.bi_size - bytes_allowed;
966+
extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed;
958967
jiffy_wait = div64_u64(extra_bytes * HZ, tg_bps_limit(tg, rw));
959968

960969
if (!jiffy_wait)
@@ -1034,11 +1043,12 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio,
10341043
static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
10351044
{
10361045
bool rw = bio_data_dir(bio);
1046+
unsigned int bio_size = throtl_bio_data_size(bio);
10371047

10381048
/* Charge the bio to the group */
1039-
tg->bytes_disp[rw] += bio->bi_iter.bi_size;
1049+
tg->bytes_disp[rw] += bio_size;
10401050
tg->io_disp[rw]++;
1041-
tg->last_bytes_disp[rw] += bio->bi_iter.bi_size;
1051+
tg->last_bytes_disp[rw] += bio_size;
10421052
tg->last_io_disp[rw]++;
10431053

10441054
/*

0 commit comments

Comments
 (0)