All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle
@ 2021-06-03 14:00 Odin Ugedal
  2021-06-03 19:20 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Odin Ugedal @ 2021-06-03 14:00 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira
  Cc: cgroups, linux-kernel, Odin Ugedal

This fixes an issue where fairness is decreased since cfs_rq's can
end up not being decayed properly. For two sibling control groups with
the same priority, this can often lead to a load ratio of 99/1 (!!).

This happen because when a cfs_rq is throttled, all the descendant cfs_rq's
will be removed from the leaf list. When they initial cfs_rq is
unthrottled, it will currently only re add descendant cfs_rq's if they
have one or more entities enqueued. This is not a perfect heuristic.

Instead, we insert all cfs_rq's that contain one or more enqueued
entities, or it its load is not completely decayed.

Can often lead to situations like this for equally weighted control
groups:

$ ps u -C stress
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       10009 88.8  0.0   3676   100 pts/1    R+   11:04   0:13 stress --cpu 1
root       10023  3.0  0.0   3676   104 pts/1    R+   11:04   0:00 stress --cpu 1

Fixes: 31bc6aeaab1d ("sched/fair: Optimize update_blocked_averages()")
Signed-off-by: Odin Ugedal <odin@uged.al>
---
Original thread: https://lore.kernel.org/lkml/20210518125202.78658-3-odin@uged.al/
Changes since v1:
 - Replaced cfs_rq field with using tg_load_avg_contrib
 - Went from 3 to 1 patches; one is merged and one is replaced
   by a new patchset.
Changes since v2:
 - Use !cfs_rq_is_decayed() instead of tg_load_avg_contrib
 - Moved cfs_rq_is_decayed to above its new use

 kernel/sched/fair.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 794c2cb945f8..cdf6ac1a6b12 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -396,6 +396,23 @@ static inline void assert_list_leaf_cfs_rq(struct rq *rq)
 	list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list,	\
 				 leaf_cfs_rq_list)
 
+static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq)
+{
+	if (cfs_rq->load.weight)
+		return false;
+
+	if (cfs_rq->avg.load_sum)
+		return false;
+
+	if (cfs_rq->avg.util_sum)
+		return false;
+
+	if (cfs_rq->avg.runnable_sum)
+		return false;
+
+	return true;
+}
+
 /* Do the two (enqueued) entities belong to the same group ? */
 static inline struct cfs_rq *
 is_same_group(struct sched_entity *se, struct sched_entity *pse)
@@ -4719,8 +4736,8 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 		cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
 					     cfs_rq->throttled_clock_task;
 
-		/* Add cfs_rq with already running entity in the list */
-		if (cfs_rq->nr_running >= 1)
+		/* Add cfs_rq with load or one or more already running entities to the list */
+		if (!cfs_rq_is_decayed(cfs_rq) || cfs_rq->nr_running)
 			list_add_leaf_cfs_rq(cfs_rq);
 	}
 
@@ -7895,23 +7912,6 @@ static bool __update_blocked_others(struct rq *rq, bool *done)
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
 
-static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq)
-{
-	if (cfs_rq->load.weight)
-		return false;
-
-	if (cfs_rq->avg.load_sum)
-		return false;
-
-	if (cfs_rq->avg.util_sum)
-		return false;
-
-	if (cfs_rq->avg.runnable_sum)
-		return false;
-
-	return true;
-}
-
 static bool __update_blocked_fair(struct rq *rq, bool *done)
 {
 	struct cfs_rq *cfs_rq, *pos;
-- 
2.31.1


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

* Re: [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle
  2021-06-03 14:00 [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle Odin Ugedal
@ 2021-06-03 19:20 ` kernel test robot
  2021-06-03 21:11 ` kernel test robot
  2021-06-03 21:54 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-06-03 19:20 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2892 bytes --]

Hi Odin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on tip/master linux/master linus/master v5.13-rc4 next-20210603]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Odin-Ugedal/sched-fair-Correctly-insert-cfs_rq-s-to-list-on-unthrottle/20210603-220448
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 858f9e11be8855ed62cb97e58174515da595c76b
config: i386-randconfig-r036-20210603 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/00f0e270f61d4f8a192ee519dda403d4656c910c
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Odin-Ugedal/sched-fair-Correctly-insert-cfs_rq-s-to-list-on-unthrottle/20210603-220448
        git checkout 00f0e270f61d4f8a192ee519dda403d4656c910c
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   kernel/sched/fair.c: In function 'cfs_rq_is_decayed':
>> kernel/sched/fair.c:392:12: error: 'struct cfs_rq' has no member named 'avg'
     392 |  if (cfs_rq->avg.load_sum)
         |            ^~
   kernel/sched/fair.c:395:12: error: 'struct cfs_rq' has no member named 'avg'
     395 |  if (cfs_rq->avg.util_sum)
         |            ^~
   kernel/sched/fair.c:398:12: error: 'struct cfs_rq' has no member named 'avg'
     398 |  if (cfs_rq->avg.runnable_sum)
         |            ^~
   kernel/sched/fair.c: At top level:
   kernel/sched/fair.c:608:5: warning: no previous prototype for 'sched_update_scaling' [-Wmissing-prototypes]
     608 | int sched_update_scaling(void)
         |     ^~~~~~~~~~~~~~~~~~~~


vim +392 kernel/sched/fair.c

   381	
   382	/* Iterate thr' all leaf cfs_rq's on a runqueue */
   383	#define for_each_leaf_cfs_rq_safe(rq, cfs_rq, pos)			\
   384		list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list,	\
   385					 leaf_cfs_rq_list)
   386	
   387	static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq)
   388	{
   389		if (cfs_rq->load.weight)
   390			return false;
   391	
 > 392		if (cfs_rq->avg.load_sum)
   393			return false;
   394	
   395		if (cfs_rq->avg.util_sum)
   396			return false;
   397	
   398		if (cfs_rq->avg.runnable_sum)
   399			return false;
   400	
   401		return true;
   402	}
   403	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 31174 bytes --]

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

* Re: [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle
  2021-06-03 14:00 [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle Odin Ugedal
  2021-06-03 19:20 ` kernel test robot
@ 2021-06-03 21:11 ` kernel test robot
  2021-06-03 21:54 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-06-03 21:11 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3367 bytes --]

Hi Odin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on tip/master linux/master linus/master v5.13-rc4 next-20210603]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Odin-Ugedal/sched-fair-Correctly-insert-cfs_rq-s-to-list-on-unthrottle/20210603-220448
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 858f9e11be8855ed62cb97e58174515da595c76b
config: x86_64-randconfig-a002-20210603 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project d8e0ae9a76a62bdc6117630d59bf9967ac9bb4ea)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/00f0e270f61d4f8a192ee519dda403d4656c910c
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Odin-Ugedal/sched-fair-Correctly-insert-cfs_rq-s-to-list-on-unthrottle/20210603-220448
        git checkout 00f0e270f61d4f8a192ee519dda403d4656c910c
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> kernel/sched/fair.c:392:14: error: no member named 'avg' in 'struct cfs_rq'
           if (cfs_rq->avg.load_sum)
               ~~~~~~  ^
   kernel/sched/fair.c:395:14: error: no member named 'avg' in 'struct cfs_rq'
           if (cfs_rq->avg.util_sum)
               ~~~~~~  ^
   kernel/sched/fair.c:398:14: error: no member named 'avg' in 'struct cfs_rq'
           if (cfs_rq->avg.runnable_sum)
               ~~~~~~  ^
   kernel/sched/fair.c:608:5: warning: no previous prototype for function 'sched_update_scaling' [-Wmissing-prototypes]
   int sched_update_scaling(void)
       ^
   kernel/sched/fair.c:608:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int sched_update_scaling(void)
   ^
   static 
   1 warning and 3 errors generated.


vim +392 kernel/sched/fair.c

   381	
   382	/* Iterate thr' all leaf cfs_rq's on a runqueue */
   383	#define for_each_leaf_cfs_rq_safe(rq, cfs_rq, pos)			\
   384		list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list,	\
   385					 leaf_cfs_rq_list)
   386	
   387	static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq)
   388	{
   389		if (cfs_rq->load.weight)
   390			return false;
   391	
 > 392		if (cfs_rq->avg.load_sum)
   393			return false;
   394	
   395		if (cfs_rq->avg.util_sum)
   396			return false;
   397	
   398		if (cfs_rq->avg.runnable_sum)
   399			return false;
   400	
   401		return true;
   402	}
   403	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 37140 bytes --]

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

* Re: [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle
  2021-06-03 14:00 [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle Odin Ugedal
  2021-06-03 19:20 ` kernel test robot
  2021-06-03 21:11 ` kernel test robot
@ 2021-06-03 21:54 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-06-03 21:54 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3004 bytes --]

Hi Odin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on tip/master linux/master linus/master v5.13-rc4 next-20210603]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Odin-Ugedal/sched-fair-Correctly-insert-cfs_rq-s-to-list-on-unthrottle/20210603-220448
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 858f9e11be8855ed62cb97e58174515da595c76b
config: x86_64-randconfig-r034-20210603 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project d8e0ae9a76a62bdc6117630d59bf9967ac9bb4ea)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/00f0e270f61d4f8a192ee519dda403d4656c910c
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Odin-Ugedal/sched-fair-Correctly-insert-cfs_rq-s-to-list-on-unthrottle/20210603-220448
        git checkout 00f0e270f61d4f8a192ee519dda403d4656c910c
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> kernel/sched/fair.c:392:14: error: no member named 'avg' in 'struct cfs_rq'
           if (cfs_rq->avg.load_sum)
               ~~~~~~  ^
   kernel/sched/fair.c:395:14: error: no member named 'avg' in 'struct cfs_rq'
           if (cfs_rq->avg.util_sum)
               ~~~~~~  ^
   kernel/sched/fair.c:398:14: error: no member named 'avg' in 'struct cfs_rq'
           if (cfs_rq->avg.runnable_sum)
               ~~~~~~  ^
   3 errors generated.


vim +392 kernel/sched/fair.c

   381	
   382	/* Iterate thr' all leaf cfs_rq's on a runqueue */
   383	#define for_each_leaf_cfs_rq_safe(rq, cfs_rq, pos)			\
   384		list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list,	\
   385					 leaf_cfs_rq_list)
   386	
   387	static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq)
   388	{
   389		if (cfs_rq->load.weight)
   390			return false;
   391	
 > 392		if (cfs_rq->avg.load_sum)
   393			return false;
   394	
   395		if (cfs_rq->avg.util_sum)
   396			return false;
   397	
   398		if (cfs_rq->avg.runnable_sum)
   399			return false;
   400	
   401		return true;
   402	}
   403	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 27680 bytes --]

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

end of thread, other threads:[~2021-06-03 21:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 14:00 [PATCH v3] sched/fair: Correctly insert cfs_rq's to list on unthrottle Odin Ugedal
2021-06-03 19:20 ` kernel test robot
2021-06-03 21:11 ` kernel test robot
2021-06-03 21:54 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.