sched/fair: remove redundant se initialization in unthrottle_cfs_rq
PATCH 1/1 sched/fair: remove redundant se initialization in unthrottle_cfs_rq
In unthrottle_cfs_rq(), the variable 'se' is initialized at declaration (line 6024) but then immediately reassigned at line 6039 after an early return check. This redundant initialization is wasteful, especially when the function returns early at line 6037.
Remove the redundant initialization and only assign 'se' when it's actually needed, avoiding unnecessary memory access and improving code clarity.
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
@@ -6021,7 +6021,7 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq) {struct rq *rq =rq_of (cfs_rq);struct cfs_bandwidth *cfs_b =tg_cfs_bandwidth (cfs_rq->tg); -struct sched_entity *se = cfs_rq->tg->se[cpu_of (rq)]; +struct sched_entity *se;/* * It's possible we are called with !runtime_remaining due to things
Signature · 1 line
2.39.5
Hi Linwei,
Quoted 4 lines · Linwei Wang
In
unthrottle_cfs_rq(), the variable 'se' is initialized at declaration (line 6024) but then immediately reassigned at line 6039 after an early return check. This redundant initialization is wasteful, especially when the function returns early at line 6037.
This redundant initialization is addressed in commit 956dfda6a708 ("sched/fair: Prevent cfs_rq from being unthrottled with zero runtime_remaining").
Thanks.
Hi Aaron,
Your commit 956dfda6a708 removes the duplicate assignment after the early return, but still initializes 'se' at declaration:
struct sched_entity *se = cfs_rq->tg->se[cpu_of(rq)];
This initialization happens before the early return check at line 6036-6037, so when runtime_remaining <= 0 causes an early return, the array access is wasted.
My patch defers initialization until after the early return:
- struct sched_entity *se = cfs_rq->tg->se[cpu_of(rq)];
+ struct sched_entity *se;
...
+ se = cfs_rq->tg->se[cpu_of(rq)];
Your commit fixes the duplicate assignment; mine optimizes the early return path. They're independent optimizations.
Should I rebase on top of 956dfda6a708?
Thanks.