Skip to content

Commit dc620dd

Browse files
committed
sched/fair: Fix value reported by hot tasks pulled in /proc/schedstat
JIRA: https://issues.redhat.com/browse/RHEL-23495 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 5150d3a commit dc620dd

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
@@ -911,6 +911,7 @@ struct task_struct {
911911
unsigned sched_reset_on_fork:1;
912912
unsigned sched_contributes_to_load:1;
913913
unsigned sched_migrated:1;
914+
unsigned sched_task_hot:1;
914915

915916
/* Force alignment to the next boundary: */
916917
unsigned :0;

kernel/sched/fair.c

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

89068906
lockdep_assert_rq_held(env->src_rq);
8907+
if (p->sched_task_hot)
8908+
p->sched_task_hot = 0;
89078909

89088910
/*
89098911
* We do not migrate tasks that are:
@@ -8976,10 +8978,8 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
89768978

89778979
if (tsk_cache_hot <= 0 ||
89788980
env->sd->nr_balance_failed > env->sd->cache_nice_tries) {
8979-
if (tsk_cache_hot == 1) {
8980-
schedstat_inc(env->sd->lb_hot_gained[env->idle]);
8981-
schedstat_inc(p->stats.nr_forced_migrations);
8982-
}
8981+
if (tsk_cache_hot == 1)
8982+
p->sched_task_hot = 1;
89838983
return 1;
89848984
}
89858985

@@ -8994,6 +8994,12 @@ static void detach_task(struct task_struct *p, struct lb_env *env)
89948994
{
89958995
lockdep_assert_rq_held(env->src_rq);
89968996

8997+
if (p->sched_task_hot) {
8998+
p->sched_task_hot = 0;
8999+
schedstat_inc(env->sd->lb_hot_gained[env->idle]);
9000+
schedstat_inc(p->stats.nr_forced_migrations);
9001+
}
9002+
89979003
deactivate_task(env->src_rq, p, DEQUEUE_NOCLOCK);
89989004
set_task_cpu(p, env->dst_cpu);
89999005
}
@@ -9154,6 +9160,9 @@ static int detach_tasks(struct lb_env *env)
91549160

91559161
continue;
91569162
next:
9163+
if (p->sched_task_hot)
9164+
schedstat_inc(p->stats.nr_failed_migrations_hot);
9165+
91579166
list_move(&p->se.group_node, tasks);
91589167
}
91599168

0 commit comments

Comments
 (0)