mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 07:00:52 +07:00
blk-throttle: Avoid calculating bps/iops limitation repeatedly
The tg_may_dispatch() will call tg_with_in_bps_limit() and tg_with_in_iops_limit() to check if we can dispatch a bio or not, which will calculate bps/iops limitation multiple times. But tg_may_dispatch() is always called under queue lock, which means the bps/iops limitation will not change in tg_may_dispatch(). So we can calculate the bps/iops limitation only once, and pass them to tg_with_in_bps_limit() and tg_with_in_iops_limit() to avoid calculating bps/iops limitation repeatedly. Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
e675df2adc
commit
4599ea49d4
@ -894,7 +894,7 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
|
static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
|
||||||
unsigned long *wait)
|
u32 iops_limit, unsigned long *wait)
|
||||||
{
|
{
|
||||||
bool rw = bio_data_dir(bio);
|
bool rw = bio_data_dir(bio);
|
||||||
unsigned int io_allowed;
|
unsigned int io_allowed;
|
||||||
@ -913,7 +913,7 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
|
|||||||
* have been trimmed.
|
* have been trimmed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tmp = (u64)tg_iops_limit(tg, rw) * jiffy_elapsed_rnd;
|
tmp = (u64)iops_limit * jiffy_elapsed_rnd;
|
||||||
do_div(tmp, HZ);
|
do_div(tmp, HZ);
|
||||||
|
|
||||||
if (tmp > UINT_MAX)
|
if (tmp > UINT_MAX)
|
||||||
@ -936,7 +936,7 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
|
static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
|
||||||
unsigned long *wait)
|
u64 bps_limit, unsigned long *wait)
|
||||||
{
|
{
|
||||||
bool rw = bio_data_dir(bio);
|
bool rw = bio_data_dir(bio);
|
||||||
u64 bytes_allowed, extra_bytes, tmp;
|
u64 bytes_allowed, extra_bytes, tmp;
|
||||||
@ -951,7 +951,7 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
|
|||||||
|
|
||||||
jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
|
jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
|
||||||
|
|
||||||
tmp = tg_bps_limit(tg, rw) * jiffy_elapsed_rnd;
|
tmp = bps_limit * jiffy_elapsed_rnd;
|
||||||
do_div(tmp, HZ);
|
do_div(tmp, HZ);
|
||||||
bytes_allowed = tmp;
|
bytes_allowed = tmp;
|
||||||
|
|
||||||
@ -963,7 +963,7 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,
|
|||||||
|
|
||||||
/* Calc approx time to dispatch */
|
/* Calc approx time to dispatch */
|
||||||
extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed;
|
extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed;
|
||||||
jiffy_wait = div64_u64(extra_bytes * HZ, tg_bps_limit(tg, rw));
|
jiffy_wait = div64_u64(extra_bytes * HZ, bps_limit);
|
||||||
|
|
||||||
if (!jiffy_wait)
|
if (!jiffy_wait)
|
||||||
jiffy_wait = 1;
|
jiffy_wait = 1;
|
||||||
@ -987,6 +987,8 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio,
|
|||||||
{
|
{
|
||||||
bool rw = bio_data_dir(bio);
|
bool rw = bio_data_dir(bio);
|
||||||
unsigned long bps_wait = 0, iops_wait = 0, max_wait = 0;
|
unsigned long bps_wait = 0, iops_wait = 0, max_wait = 0;
|
||||||
|
u64 bps_limit = tg_bps_limit(tg, rw);
|
||||||
|
u32 iops_limit = tg_iops_limit(tg, rw);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Currently whole state machine of group depends on first bio
|
* Currently whole state machine of group depends on first bio
|
||||||
@ -998,8 +1000,7 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio,
|
|||||||
bio != throtl_peek_queued(&tg->service_queue.queued[rw]));
|
bio != throtl_peek_queued(&tg->service_queue.queued[rw]));
|
||||||
|
|
||||||
/* If tg->bps = -1, then BW is unlimited */
|
/* If tg->bps = -1, then BW is unlimited */
|
||||||
if (tg_bps_limit(tg, rw) == U64_MAX &&
|
if (bps_limit == U64_MAX && iops_limit == UINT_MAX) {
|
||||||
tg_iops_limit(tg, rw) == UINT_MAX) {
|
|
||||||
if (wait)
|
if (wait)
|
||||||
*wait = 0;
|
*wait = 0;
|
||||||
return true;
|
return true;
|
||||||
@ -1021,8 +1022,8 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio,
|
|||||||
jiffies + tg->td->throtl_slice);
|
jiffies + tg->td->throtl_slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tg_with_in_bps_limit(tg, bio, &bps_wait) &&
|
if (tg_with_in_bps_limit(tg, bio, bps_limit, &bps_wait) &&
|
||||||
tg_with_in_iops_limit(tg, bio, &iops_wait)) {
|
tg_with_in_iops_limit(tg, bio, iops_limit, &iops_wait)) {
|
||||||
if (wait)
|
if (wait)
|
||||||
*wait = 0;
|
*wait = 0;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user