sched/fair: Search a task from the tail of the queue

As a first step this patch makes cfs_tasks list as MRU one.
It means, that when a next task is picked to run on physical
CPU it is moved to the front of the list.

Therefore, the cfs_tasks list is more or less sorted (except
woken tasks) starting from recently given CPU time tasks toward
tasks with max wait time in a run-queue, i.e. MRU list.

Second, as part of the load balance operation, this approach
starts detach_tasks()/detach_one_task() from the tail of the
queue instead of the head, giving some advantages:

 - tends to pick a task with highest wait time;

 - tasks located in the tail are less likely cache-hot,
   therefore the can_migrate_task() decision is higher.

hackbench illustrates slightly better performance. For example
doing 1000 samples and 40 groups on i5-3320M CPU, it shows below
figures:

 default: 0.657 avg
 patched: 0.646 avg

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Kirill Tkhai <tkhai@yandex.ru>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Mike Galbraith <umgwanakikbuti@gmail.com>
Cc: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Link: http://lkml.kernel.org/r/20170913102430.8985-2-urezki@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Change-Id: Id44ee1af4d88a01db1994e642518b7e3cc58f937
Signed-off-by: Danny Lin <danny@kdrag0n.dev>
Signed-off-by: Alexander Winkowski <dereference23@outlook.com>
fourteen
Uladzislau Rezki 7 years ago committed by Jenna
parent 31092698e6
commit cc534d3c52
  1. 26
      kernel/sched/fair.c

@ -8865,12 +8865,7 @@ again:
set_next_entity(cfs_rq, se); set_next_entity(cfs_rq, se);
} }
if (hrtick_enabled(rq)) goto done;
hrtick_start_fair(rq, p);
update_misfit_status(p, rq);
return p;
simple: simple:
#endif #endif
@ -8884,6 +8879,16 @@ simple:
p = task_of(se); p = task_of(se);
done: __maybe_unused
#ifdef CONFIG_SMP
/*
* Move the next running task to the front of
* the list, so our cfs_tasks list becomes MRU
* one.
*/
list_move(&p->se.group_node, &rq->cfs_tasks);
#endif
if (hrtick_enabled(rq)) if (hrtick_enabled(rq))
hrtick_start_fair(rq, p); hrtick_start_fair(rq, p);
@ -9389,11 +9394,12 @@ static void detach_task(struct task_struct *p, struct lb_env *env)
*/ */
static struct task_struct *detach_one_task(struct lb_env *env) static struct task_struct *detach_one_task(struct lb_env *env)
{ {
struct task_struct *p, *n; struct task_struct *p;
lockdep_assert_held(&env->src_rq->lock); lockdep_assert_held(&env->src_rq->lock);
list_for_each_entry_safe(p, n, &env->src_rq->cfs_tasks, se.group_node) { list_for_each_entry_reverse(p,
&env->src_rq->cfs_tasks, se.group_node) {
if (!can_migrate_task(p, env)) if (!can_migrate_task(p, env))
continue; continue;
@ -9447,7 +9453,7 @@ redo:
if (env->idle != CPU_NOT_IDLE && env->src_rq->nr_running <= 1) if (env->idle != CPU_NOT_IDLE && env->src_rq->nr_running <= 1)
break; break;
p = list_first_entry(tasks, struct task_struct, se.group_node); p = list_last_entry(tasks, struct task_struct, se.group_node);
env->loop++; env->loop++;
/* We've more or less seen every task there is, call it quits */ /* We've more or less seen every task there is, call it quits */
@ -9520,7 +9526,7 @@ next:
env->src_grp_type, p->pid, load, task_util(p), env->src_grp_type, p->pid, load, task_util(p),
cpumask_bits(&p->cpus_allowed)[0]); cpumask_bits(&p->cpus_allowed)[0]);
#endif #endif
list_move_tail(&p->se.group_node, tasks); list_move(&p->se.group_node, tasks);
} }
if (env->flags & (LBF_IGNORE_BIG_TASKS | if (env->flags & (LBF_IGNORE_BIG_TASKS |

Loading…
Cancel
Save