mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/fair: remove redundant se initialization in unthrottle_cfs_rq
@ 2025-11-08  7:38 Linwei Wang
  2025-11-11  7:40 ` Aaron Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Linwei Wang @ 2025-11-08  7:38 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	linux-kernel, 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.

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched/fair: remove redundant se initialization in unthrottle_cfs_rq
  2025-11-08  7:38 [PATCH] sched/fair: remove redundant se initialization in unthrottle_cfs_rq Linwei Wang
@ 2025-11-11  7:40 ` Aaron Lu
  2025-11-12 14:21   ` Linwei Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron Lu @ 2025-11-11  7:40 UTC (permalink / raw)
  To: Linwei Wang
  Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid, linux-kernel

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched/fair: remove redundant se initialization in unthrottle_cfs_rq
  2025-11-11  7:40 ` Aaron Lu
@ 2025-11-12 14:21   ` Linwei Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Linwei Wang @ 2025-11-12 14:21 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Linwei Wang, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Valentin Schneider, linux-kernel

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-12 14:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-08  7:38 [PATCH] sched/fair: remove redundant se initialization in unthrottle_cfs_rq Linwei Wang
2025-11-11  7:40 ` Aaron Lu
2025-11-12 14:21   ` Linwei Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®