Skip to content

Commit c37fce7

Browse files
committed
sched/fair: Fix value reported by hot tasks pulled in /proc/schedstat
JIRA: https://issues.redhat.com/browse/RHEL-24185 commit a430d99 Author: Peter Zijlstra <peterz@infradead.org> Date: Fri Dec 20 06:32:19 2024 +0000 sched/fair: Fix value reported by hot tasks pulled in /proc/schedstat In /proc/schedstat, lb_hot_gained reports the number hot tasks pulled during load balance. This value is incremented in can_migrate_task() if the task is migratable and hot. After incrementing the value, load balancer can still decide not to migrate this task leading to wrong accounting. Fix this by incrementing stats when hot tasks are detached. This issue only exists in detach_tasks() where we can decide to not migrate hot task even if it is migratable. However, in detach_one_task(), we migrate it unconditionally. [Swapnil: Handled the case where nr_failed_migrations_hot was not accounted properly and wrote commit log] Fixes: d319808 ("sched: Move up affinity check to mitigate useless redoing overhead") Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reported-by: "Gautham R. Shenoy" <gautham.shenoy@amd.com> Not-yet-signed-off-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20241220063224.17767-2-swapnil.sapkal@amd.com Signed-off-by: Phil Auld <pauld@redhat.com>
1 parent 91caaa2 commit c37fce7

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/linux/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ struct task_struct {
944944
unsigned sched_reset_on_fork:1;
945945
unsigned sched_contributes_to_load:1;
946946
unsigned sched_migrated:1;
947+
unsigned sched_task_hot:1;
947948

948949
/* Force alignment to the next boundary: */
949950
unsigned :0;

kernel/sched/fair.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9414,6 +9414,8 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
94149414
int tsk_cache_hot;
94159415

94169416
lockdep_assert_rq_held(env->src_rq);
9417+
if (p->sched_task_hot)
9418+
p->sched_task_hot = 0;
94179419

94189420
/*
94199421
* We do not migrate tasks that are:
@@ -9486,10 +9488,8 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
94869488

94879489
if (tsk_cache_hot <= 0 ||
94889490
env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
9489-
if (tsk_cache_hot == 1) {
9490-
schedstat_inc(env->sd->lb_hot_gained[env->idle]);
9491-
schedstat_inc(p->stats.nr_forced_migrations);
9492-
}
9491+
if (tsk_cache_hot == 1)
9492+
p->sched_task_hot = 1;
94939493
return 1;
94949494
}
94959495

@@ -9504,6 +9504,12 @@ static void detach_task(struct task_struct *p, struct lb_env *env)
95049504
{
95059505
lockdep_assert_rq_held(env->src_rq);
95069506

9507+
if (p->sched_task_hot) {
9508+
p->sched_task_hot = 0;
9509+
schedstat_inc(env->sd->lb_hot_gained[env->idle]);
9510+
schedstat_inc(p->stats.nr_forced_migrations);
9511+
}
9512+
95079513
deactivate_task(env->src_rq, p, DEQUEUE_NOCLOCK);
95089514
set_task_cpu(p, env->dst_cpu);
95099515
}
@@ -9664,6 +9670,9 @@ static int detach_tasks(struct lb_env *env)
96649670

96659671
continue;
96669672
next:
9673+
if (p->sched_task_hot)
9674+
schedstat_inc(p->stats.nr_failed_migrations_hot);
9675+
96679676
list_move(&p->se.group_node, tasks);
96689677
}
96699678

0 commit comments

Comments
 (0)