Skip to contentSkip to conversation

sched/fair: Mitigate the impact of retrieving tg->load_avg

RFC New Vinicius Costa Gomes 2 participants 2 messages Jul 14, 2025 – Jul 15, 2025 Scheduler

lore
Share & tools
lore
#0 lore raw

RFC 1/1 sched/fair: Mitigate the impact of retrieving tg->load_avg

Reduce the impact of update_cfs_group()/update_load_avg() by reducing the frequency that tg->load_avg is retrieved.

This is "the other side" of commit 1528c661c24b ("sched/fair:
Ratelimit update to tg->load_avg"), which reduced the frequency of the "store" side, now it's reducing the frequency of the "load" side.

Sending as a RFC because I want to point out that there is still contention when updating/loading the load_avg of a group, I do not believe that this particular piece of code is the solution.

On a series[1] with a similar objective (and independent), it was pointed out that perhaps the effort was best spent on something like this:

https://lore.kernel.org/all/[email protected]/

Would that be the way to go?

Just to make it a bit more fancy, some perf numbers, running:

$ ./schbench -r 60

* current master:
- 68.38% 0.05% schbench schbench [.] worker_thread
- 68.37% worker_thread
- 56.70% asm_sysvec_apic_timer_interrupt
- 56.10% sysvec_apic_timer_interrupt
- 54.32% __sysvec_apic_timer_interrupt
- 54.11% hrtimer_interrupt
- 49.99% __hrtimer_run_queues
- 48.08% tick_nohz_handler
- 47.02% update_process_times
- 39.41% sched_tick
- 27.31% task_tick_fair 12.88% update_cfs_group
- 9.61% update_load_avg 3.52% __update_load_avg_cfs_rq 0.72% __update_load_avg_se

* patched kernel:
- 66.27% 0.05% schbench schbench [.] worker_thread
- 66.26% worker_thread
- 52.47% asm_sysvec_apic_timer_interrupt
- 51.87% sysvec_apic_timer_interrupt
- 50.19% __sysvec_apic_timer_interrupt
- 49.97% hrtimer_interrupt
- 45.06% __hrtimer_run_queues
- 42.77% tick_nohz_handler
- 41.64% update_process_times
- 33.32% sched_tick
- 19.33% task_tick_fair
- 7.72% update_load_avg 4.24% __update_load_avg_cfs_rq 0.80% __update_load_avg_se 6.63% update_cfs_group

I can see some improvements in schbench, but seem to be in the noise.

[1] https://lore.kernel.org/all/[email protected]/

---
 kernel/sched/fair.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/sched/fair.c +9 -0
index 7a14da5396fb..c23c6e45f49d 100644
@@ -3980,6 +3980,7 @@ static void update_cfs_group(struct sched_entity *se)
 {
 	struct cfs_rq *gcfs_rq = group_cfs_rq(se);
 	long shares;
+	u64 now;
 
 	/*
 	 * When a group becomes empty, preserve its weight. This matters for
@@ -3991,6 +3992,14 @@ static void update_cfs_group(struct sched_entity *se)
 	if (throttled_hierarchy(gcfs_rq))
 		return;
 
+	/*
+	 * For migration heavy workloads, access to tg->load_avg can be
+	 * unbound. Limit the update rate to at most once per ms.
+	 */
+	now = sched_clock_cpu(cpu_of(rq_of(gcfs_rq)));
+	if (now - gcfs_rq->last_update_tg_load_avg < NSEC_PER_MSEC)
+		return;
+
 #ifndef CONFIG_SMP
 	shares = READ_ONCE(gcfs_rq->tg->shares);
 #else
Signature · 1 line
2.50.1
#1 lore raw
kernel test robot noticed the following build errors:

Hi Vinicius,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on v6.16-rc6]
[also build test ERROR on linus/master]
[cannot apply to tip/sched/core next-20250714]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vinicius-Costa-Gomes/sched-fair-Mitigate-the-impact-of-retrieving-tg-load_avg/20250715-073036
base:   v6.16-rc6
patch link:    https://lore.kernel.org/r/20250714232915.523679-1-vinicius.gomes%40intel.com
patch subject: [RFC] sched/fair: Mitigate the impact of retrieving tg->load_avg
config: loongarch-randconfig-001-20250715 (https://download.01.org/0day-ci/archive/20250715/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 16534d19bf50bde879a83f0ae62875e2c5120e64)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250715/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> kernel/sched/fair.c:4000:21: error: no member named 'last_update_tg_load_avg' in 'struct cfs_rq'
    4000 |         if (now - gcfs_rq->last_update_tg_load_avg < NSEC_PER_MSEC)
         |                   ~~~~~~~  ^

1 error generated.

vim +4000 kernel/sched/fair.c

3974
3975 /*
3976 * Recomputes the group entity based on the current state of its group
3977 * runqueue.
3978 */
3979 static void update_cfs_group(struct sched_entity *se)
3980 {
3981 struct cfs_rq *gcfs_rq = group_cfs_rq(se);
3982 long shares;
3983 u64 now;
3984
3985 /*
3986 * When a group becomes empty, preserve its weight. This matters for
3987 * DELAY_DEQUEUE.
3988 */
3989 if (!gcfs_rq || !gcfs_rq->load.weight)
3990 return;
3991
3992 if (throttled_hierarchy(gcfs_rq))
3993 return;
3994
3995 /*
3996 * For migration heavy workloads, access to tg->load_avg can be
3997 * unbound. Limit the update rate to at most once per ms.
3998 */
3999 now = sched_clock_cpu(cpu_of(rq_of(gcfs_rq)));

> 4000		if (now - gcfs_rq->last_update_tg_load_avg < NSEC_PER_MSEC)

4001 return;
4002

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki