kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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.
Signed-off-by: Linwei Wang <wanix1988@gmail.com>
---
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 25970dbbb279..67cbb809b9a8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -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
--
2.39.5
Hi Linwei,
On Sat, Nov 08, 2025 at 03:38:29PM +0800, Linwei Wang wrote:
> 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.
© 2016 - 2025 Red Hat, Inc.