Re: [RFC] sched/fair: avoid redundant updates for unchanged default slices
From: Chengfeng Lin
Date: Fri Oct 09 2026 - 12:09:46 EST
Hi,
The inline patch in my previous message lost its tab indentation when
sent. I have attached the original patch to preserve the formatting. It
passes git apply --check against v7.2.
The code and test results are unchanged. Sorry for the formatting issue.
Thanks,
Chengfeng
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -491,6 +491,39 @@ req_priv:
return 0;
}
+static bool fair_params_changed(struct task_struct *p,
+ const struct sched_attr *attr)
+{
+ if (attr->sched_nice != task_nice(p))
+ return true;
+
+ if (attr->sched_runtime == p->se.slice)
+ return false;
+
+ /* Preserve the existing path for PI-boosted and sched_ext tasks. */
+ if (p->sched_class != &fair_sched_class)
+ return true;
+
+#ifdef CONFIG_UCLAMP_TASK
+ /*
+ * Unchanged fair parameters can still require an implicit clamp reset,
+ * for example after a task was PI-boosted into the RT class.
+ */
+ if ((!p->uclamp_req[UCLAMP_MIN].user_defined &&
+ p->uclamp_req[UCLAMP_MIN].value != uclamp_none(UCLAMP_MIN)) ||
+ (!p->uclamp_req[UCLAMP_MAX].user_defined &&
+ p->uclamp_req[UCLAMP_MAX].value != uclamp_none(UCLAMP_MAX)))
+ return true;
+#endif
+
+ /*
+ * A zero runtime requests the default slice, whereas se.slice stores
+ * its actual duration. Keep the update if the mode or default changed.
+ */
+ return attr->sched_runtime || p->se.custom_slice ||
+ p->se.slice != READ_ONCE(sysctl_sched_base_slice);
+}
+
int __sched_setscheduler(struct task_struct *p,
const struct sched_attr *attr,
bool user, bool pi)
@@ -588,9 +621,7 @@ recheck:
* but store a possible modification of reset_on_fork.
*/
if (unlikely(policy == p->policy)) {
- if (fair_policy(policy) &&
- (attr->sched_nice != task_nice(p) ||
- (attr->sched_runtime != p->se.slice)))
+ if (fair_policy(policy) && fair_params_changed(p, attr))
goto change;
if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
goto change;