]> www.infradead.org Git - users/willy/pagecache.git/commit
sched/core: Reduce cost of sched_move_task when config autogroup
authorwuchi <wuchi.zero@gmail.com>
Tue, 21 Mar 2023 06:44:59 +0000 (14:44 +0800)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 22 Mar 2023 09:10:58 +0000 (10:10 +0100)
commiteff6c8ce8d4d7faef75f66614dd20bb50595d261
tree4175867d5b4ebac03b17b83df3649dfaed4b1d97
parent530bfad1d53d103f98cec66a3e491a36d397884d
sched/core: Reduce cost of sched_move_task when config autogroup

Some sched_move_task calls are useless because that
task_struct->sched_task_group maybe not changed (equals task_group
of cpu_cgroup) when system enable autogroup. So do some checks in
sched_move_task.

sched_move_task eg:
task A belongs to cpu_cgroup0 and autogroup0, it will always belong
to cpu_cgroup0 when do_exit. So there is no need to do {de|en}queue.
The call graph is as follow.

  do_exit
    sched_autogroup_exit_task
      sched_move_task
dequeue_task
  sched_change_group
    A.sched_task_group = sched_get_task_group (=cpu_cgroup0)
enqueue_task

Performance results:
===========================
1. env
        cpu: bogomips=4600.00
     kernel: 6.3.0-rc3
 cpu_cgroup: 6:cpu,cpuacct:/user.slice

2. cmds
do_exit script:

  for i in {0..10000}; do
      sleep 0 &
      done
  wait

Run the above script, then use the following bpftrace cmd to get
the cost of sched_move_task:

  bpftrace -e 'k:sched_move_task { @ts[tid] = nsecs; }
       kr:sched_move_task /@ts[tid]/
  { @ns += nsecs - @ts[tid]; delete(@ts[tid]); }'

3. cost time(ns):
  without patch: 43528033
  with    patch: 18541416
           diff:-24986617  -57.4%

As the result show, the patch will save 57.4% in the scenario.

Signed-off-by: wuchi <wuchi.zero@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230321064459.39421-1-wuchi.zero@gmail.com
kernel/sched/core.c