Skip to content

Commit

Permalink
blk-iocost: Don't let merges push vtime into the future
Browse files Browse the repository at this point in the history
Merges have the same problem that forced-bios had which is fixed by
the previous patch.  The cost of a merge is calculated at the time of
issue and force-advances vtime into the future.  Until global vtime
catches up, how the cgroup's hweight changes in the meantime doesn't
matter and it often leads to situations where the cost is calculated
at one hweight and paid at a very different one.  See the previous
patch for more details.

Fix it by never advancing vtime into the future for merges.  If budget
is available, vtime is advanced.  Otherwise, the cost is charged as
debt.

This brings merge cost handling in line with issue cost handling in
ioc_rqos_throttle().

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
htejun authored and axboe committed Sep 10, 2019
1 parent 36a5248 commit e1518f6
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions block/blk-iocost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1784,28 +1784,39 @@ static void ioc_rqos_merge(struct rq_qos *rqos, struct request *rq,
struct bio *bio)
{
struct ioc_gq *iocg = blkg_to_iocg(bio->bi_blkg);
struct ioc *ioc = iocg->ioc;
sector_t bio_end = bio_end_sector(bio);
struct ioc_now now;
u32 hw_inuse;
u64 abs_cost, cost;

/* add iff the existing request has cost assigned */
if (!rq->bio || !rq->bio->bi_iocost_cost)
/* bypass if disabled or for root cgroup */
if (!ioc->enabled || !iocg->level)
return;

abs_cost = calc_vtime_cost(bio, iocg, true);
if (!abs_cost)
return;

ioc_now(ioc, &now);
current_hweight(iocg, NULL, &hw_inuse);
cost = abs_cost_to_cost(abs_cost, hw_inuse);

/* update cursor if backmerging into the request at the cursor */
if (blk_rq_pos(rq) < bio_end &&
blk_rq_pos(rq) + blk_rq_sectors(rq) == iocg->cursor)
iocg->cursor = bio_end;

current_hweight(iocg, NULL, &hw_inuse);
cost = div64_u64(abs_cost * HWEIGHT_WHOLE, hw_inuse);
bio->bi_iocost_cost = cost;

atomic64_add(cost, &iocg->vtime);
/*
* Charge if there's enough vtime budget and the existing request
* has cost assigned. Otherwise, account it as debt. See debt
* handling in ioc_rqos_throttle() for details.
*/
if (rq->bio && rq->bio->bi_iocost_cost &&
time_before_eq64(atomic64_read(&iocg->vtime) + cost, now.vnow))
iocg_commit_bio(iocg, bio, cost);
else
atomic64_add(abs_cost, &iocg->abs_vdebt);
}

static void ioc_rqos_done_bio(struct rq_qos *rqos, struct bio *bio)
Expand Down

0 comments on commit e1518f6

Please sign in to comment.