linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] sched: fix the nonsense shares when load of cfs_rq is too, small
@ 2020-03-03 14:17 王贇
  2020-03-03 19:52 ` Peter Zijlstra
  0 siblings, 1 reply; 21+ messages in thread
From: 王贇 @ 2020-03-03 14:17 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	open list:SCHEDULER

During our testing, we found a case that shares no longer
working correctly, the cgroup topology is like:

  /sys/fs/cgroup/cpu/A		(shares=102400)
  /sys/fs/cgroup/cpu/A/B	(shares=2)
  /sys/fs/cgroup/cpu/A/B/C	(shares=1024)

  /sys/fs/cgroup/cpu/D		(shares=1024)
  /sys/fs/cgroup/cpu/D/E	(shares=1024)
  /sys/fs/cgroup/cpu/D/E/F	(shares=1024)

The same benchmark is running in group C & F, no other tasks are
running, the benchmark is capable to consumed all the CPUs.

We suppose the group C will win more CPU resources since it could
enjoy all the shares of group A, but it's F who wins much more.

The reason is because we have group B with shares as 2, which make
the group A 'cfs_rq->load.weight' very small.

And in calc_group_shares() we calculate shares as:

  load = max(scale_load_down(cfs_rq->load.weight), cfs_rq->avg.load_avg);
  shares = (tg_shares * load) / tg_weight;

Since the 'cfs_rq->load.weight' is too small, the load become 0
in here, although 'tg_shares' is 102400, shares of the se which
stand for group A on root cfs_rq become 2.

While the se of D on root cfs_rq is far more bigger than 2, so it
wins the battle.

This patch add a check on the zero load and make it as MIN_SHARES
to fix the nonsense shares, after applied the group C wins as
expected.

Signed-off-by: Michael Wang <yun.wang@linux.alibaba.com>
---
 kernel/sched/fair.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 84594f8aeaf8..53d705f75fa4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3182,6 +3182,8 @@ static long calc_group_shares(struct cfs_rq *cfs_rq)
 	tg_shares = READ_ONCE(tg->shares);

 	load = max(scale_load_down(cfs_rq->load.weight), cfs_rq->avg.load_avg);
+	if (!load && cfs_rq->load.weight)
+		load = MIN_SHARES;

 	tg_weight = atomic_long_read(&tg->load_avg);

-- 
2.14.4.44.g2045bb6


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-03-10  8:15 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03 14:17 [RFC PATCH] sched: fix the nonsense shares when load of cfs_rq is too, small 王贇
2020-03-03 19:52 ` Peter Zijlstra
2020-03-04  1:19   ` 王贇
2020-03-04  8:47     ` Vincent Guittot
2020-03-04  9:43       ` Vincent Guittot
2020-03-05  1:23         ` 王贇
2020-03-04  9:52       ` Peter Zijlstra
2020-03-04 11:55         ` Vincent Guittot
2020-03-05  1:08         ` 王贇
2020-03-04  8:45   ` Vincent Guittot
2020-03-04 18:47   ` bsegall
2020-03-05  1:14     ` 王贇
2020-03-05  7:53       ` Vincent Guittot
2020-03-06  4:23         ` 王贇
2020-03-06  8:04           ` Vincent Guittot
2020-03-06  9:34             ` 王贇
2020-03-06 19:17       ` bsegall
2020-03-09 11:15         ` Vincent Guittot
2020-03-10  3:42           ` 王贇
2020-03-10  7:57             ` Vincent Guittot
2020-03-10  8:15               ` 王贇

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).