[PATCH 2/2] block: adjust CFS request expire time

From: zhaoyang.huang
Date: Tue Feb 20 2024 - 01:17:15 EST


From: Zhaoyang Huang <zhaoyang.huang@xxxxxxxxxx>

According to current policy, CFS's may suffer involuntary IO-latency by
being preempted by RT/DL tasks or IRQ since they possess the privilege for
both of CPU and IO scheduler. This commit introduce an approximate and
light method to decrease these affection by adjusting the expire time
via the CFS's proportion among the whole cpu active time.
The average utilization of cpu's run queue could reflect the historical
active proportion of different types of task that can be proved valid for
this goal from belowing three perspective,

1. All types of sched class's load(util) are tracked and calculated in the
same way(using a geometric series which known as PELT)
2. Keep the legacy policy by NOT adjusting rq's position in fifo_list
but only make changes over expire_time.
3. The fixed expire time(hundreds of ms) is in the same range of cpu
avg_load's account series(the utilization will be decayed to 0.5 in 32ms)

TaskA
sched in
|
|
|
submit_bio
|
|
|
fifo_time = jiffies + expire
(insert_request)

TaskB
sched in
|
|
vfs_xxx
|
|preempted by RT,DL,IRQ
|\
| This period time is unfair to TaskB's IO request, should be adjust
|/
|
submit_bio
|
|
|
fifo_time = jiffies + expire * CFS_PROPORTION(rq)
(insert_request)

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@xxxxxxxxxx>
---
block/mq-deadline.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/block/mq-deadline.c b/block/mq-deadline.c
index f958e79277b8..1e538cb2783b 100644
--- a/block/mq-deadline.c
+++ b/block/mq-deadline.c
@@ -839,8 +839,15 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,

/*
* set expire time and add to fifo list
+ * The expire time is adjusted via calculating the proportion of
+ * CFS's activation among whole cpu time during last several
+ * dazen's ms.Whearas, this would NOT affect the rq's position in
+ * fifo_list but only take effect when this rq is checked for its
+ * expire time when at head.
*/
- rq->fifo_time = jiffies + dd->fifo_expire[data_dir];
+ rq->fifo_time = jiffies +
+ cfs_prop_by_util(current, dd->fifo_expire[data_dir]);
+
insert_before = &per_prio->fifo_list[data_dir];
#ifdef CONFIG_BLK_DEV_ZONED
/*
--
2.25.1