From 25f6e3e64a772230884aaa90c1258b592a107b56 Mon Sep 17 00:00:00 2001 From: Cruz Zhao Date: Thu, 20 May 2021 10:45:47 +0800 Subject: [PATCH 2919/2944] alinux: sched: Introduce sched_feat ID_LAST_HIGHCLASS_STAY fix #34923487 In the nginx(highclass) + ffmpeg(underclass) scenario, we found that the performence degrades after applying the patch which fix the bug that nr_high_running underflow, which means that when nr_high_running is wrong, the performence is better. Finally, we found that if we skip the first judgement "if (is_highclass_task(p) && src_rq->nr_high_running < 2)", the performence of nginx will increase by 10%. But this fix is not applicable to all scenarios, so we introduce a sched_feat: ID_HIGHCLASS_STAY. When ID_LAST_HIGHCLASS_STAY is on, the highclass task will perfer to stay instead of migrate. The default value of ID_LAST_HIGHCLASS_STAY is true. Here follows the performence of nginx before: 20 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.01ms 674.94us 15.25ms 46.13% Req/Sec 4.98k 1.49k 13.24k 66.75% Latency Distribution 50% 1.02ms 75% 1.66ms 90% 1.93ms 99% 2.16ms 11900305 requests in 2.00m, 9.43GB read Requests/sec: 99086.75 Transfer/sec: 80.41MB Here follows the performence of nginx after applying this patch: 20 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 0.92ms 505.90us 10.36ms 57.40% Req/Sec 5.50k 1.21k 12.24k 71.13% Latency Distribution 50% 0.91ms 75% 1.33ms 90% 1.55ms 99% 2.07ms 13135406 requests in 2.00m, 10.41GB read Requests/sec: 109371.06 Transfer/sec: 88.76MB Signed-off-by: Cruz Zhao Acked-by: Michael Wang --- kernel/sched/fair.c | 3 ++- kernel/sched/features.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 599d0f9..5f66a7f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -882,7 +882,8 @@ static inline bool is_idle_seeker_task(struct task_struct *p) id_can_migrate_task(struct task_struct *p, struct rq *src_rq, struct rq *dst_rq) { /* Do not migrate the last highclass, try someone else */ - if (is_highclass_task(p) && src_rq->nr_high_running < 2) + if (sched_feat(ID_LAST_HIGHCLASS_STAY) && is_highclass_task(p) + && src_rq->nr_high_running < 2) goto bad_dst; if (!is_expellee_task(p)) diff --git a/kernel/sched/features.h b/kernel/sched/features.h index 47a2d91..4c40fac 100644 --- a/kernel/sched/features.h +++ b/kernel/sched/features.h @@ -96,4 +96,5 @@ SCHED_FEAT(ID_RESCUE_EXPELLEE, true) SCHED_FEAT(ID_EXPELLEE_NEVER_HOT, false) SCHED_FEAT(ID_LOOSE_EXPEL, false) +SCHED_FEAT(ID_LAST_HIGHCLASS_STAY, true) #endif -- 1.8.3.1