Skip to content

Commit 0ad4e3d

Browse files
srikardIngo Molnar
authored andcommitted
sched/numa: Modify migrate_swap() to accept additional parameters
There are checks in migrate_swap_stop() that check if the task/CPU combination is as per migrate_swap_arg before migrating. However atleast one of the two tasks to be swapped by migrate_swap() could have migrated to a completely different CPU before updating the migrate_swap_arg. The new CPU where the task is currently running could be a different node too. If the task has migrated, numa balancer might end up placing a task in a wrong node. Instead of achieving node consolidation, it may end up spreading the load across nodes. To avoid that pass the CPUs as additional parameters. While here, place migrate_swap under CONFIG_NUMA_BALANCING. Running SPECjbb2005 on a 4 node machine and comparing bops/JVM JVMS LAST_PATCH WITH_PATCH %CHANGE 16 25377.3 25226.6 -0.59 1 72287 73326 1.437 Signed-off-by: Srikar Dronamraju <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Rik van Riel <[email protected]> Acked-by: Mel Gorman <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 10864a9 commit 0ad4e3d

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

kernel/sched/core.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
11761176
__set_task_cpu(p, new_cpu);
11771177
}
11781178

1179+
#ifdef CONFIG_NUMA_BALANCING
11791180
static void __migrate_swap_task(struct task_struct *p, int cpu)
11801181
{
11811182
if (task_on_rq_queued(p)) {
@@ -1257,16 +1258,17 @@ static int migrate_swap_stop(void *data)
12571258
/*
12581259
* Cross migrate two tasks
12591260
*/
1260-
int migrate_swap(struct task_struct *cur, struct task_struct *p)
1261+
int migrate_swap(struct task_struct *cur, struct task_struct *p,
1262+
int target_cpu, int curr_cpu)
12611263
{
12621264
struct migration_swap_arg arg;
12631265
int ret = -EINVAL;
12641266

12651267
arg = (struct migration_swap_arg){
12661268
.src_task = cur,
1267-
.src_cpu = task_cpu(cur),
1269+
.src_cpu = curr_cpu,
12681270
.dst_task = p,
1269-
.dst_cpu = task_cpu(p),
1271+
.dst_cpu = target_cpu,
12701272
};
12711273

12721274
if (arg.src_cpu == arg.dst_cpu)
@@ -1291,6 +1293,7 @@ int migrate_swap(struct task_struct *cur, struct task_struct *p)
12911293
out:
12921294
return ret;
12931295
}
1296+
#endif /* CONFIG_NUMA_BALANCING */
12941297

12951298
/*
12961299
* wait_task_inactive - wait for a thread to unschedule.

kernel/sched/fair.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,8 @@ static int task_numa_migrate(struct task_struct *p)
18481848
return ret;
18491849
}
18501850

1851-
ret = migrate_swap(p, env.best_task);
1851+
ret = migrate_swap(p, env.best_task, env.best_cpu, env.src_cpu);
1852+
18521853
if (ret != 0)
18531854
trace_sched_stick_numa(p, env.src_cpu, task_cpu(env.best_task));
18541855
put_task_struct(env.best_task);

kernel/sched/sched.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,8 @@ enum numa_faults_stats {
10991099
};
11001100
extern void sched_setnuma(struct task_struct *p, int node);
11011101
extern int migrate_task_to(struct task_struct *p, int cpu);
1102-
extern int migrate_swap(struct task_struct *, struct task_struct *);
1102+
extern int migrate_swap(struct task_struct *p, struct task_struct *t,
1103+
int cpu, int scpu);
11031104
extern void init_numa_balancing(unsigned long clone_flags, struct task_struct *p);
11041105
#else
11051106
static inline void

0 commit comments

Comments
 (0)