[PATCH v2 3/3] sched/fair: Rename sgc->imbalance to sgc->pinned_imb

From: Jemmy Wong

Date: Fri Oct 02 2026 - 11:50:59 EST


sgc->imbalance does not describe a load skew either. It is set only
when a child domain failed to balance because some tasks were pinned by
cpus_ptr, and the parent then classifies the group as group_pinned_imb
so that it can force a migration.

The unqualified name is easily confused with env->imbalance, the amount
of load still to move, and with imbalance_pct. And after the previous
rename, sg_imbalanced() returns group_pinned_imb, so the helper and the
group type no longer agree.

Rename the field to pinned_imb and its reader to sg_pinned_imb().

No functional change.

Signed-off-by: Jemmy Wong <jemmywong512@xxxxxxxxx>
---
kernel/sched/fair.c | 24 ++++++++++++------------
kernel/sched/sched.h | 6 +++++-
2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 49de871ee7ab..0f773e1af9f5 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -11832,7 +11832,7 @@ static inline bool check_misfit_status(struct rq *rq)
}

/*
- * Group imbalance indicates (and tries to solve) the problem where balancing
+ * sgc->pinned_imb indicates (and tries to solve) the problem where balancing
* groups is inadequate due to ->cpus_ptr constraints.
*
* Imagine a situation of two groups of 4 CPUs each and 4 tasks each with a
@@ -11860,9 +11860,9 @@ static inline bool check_misfit_status(struct rq *rq)
* subtle and fragile situation.
*/

-static inline int sg_imbalanced(struct sched_group *group)
+static inline int sg_pinned_imb(struct sched_group *group)
{
- return group->sgc->imbalance;
+ return group->sgc->pinned_imb;
}

/*
@@ -11937,7 +11937,7 @@ group_type group_classify(unsigned int imbalance_pct,
if (sgs->group_llc_balance)
return group_llc_balance;

- if (sg_imbalanced(group))
+ if (sg_pinned_imb(group))
return group_pinned_imb;

if (sgs->group_asym_packing)
@@ -13870,10 +13870,10 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
* We failed to reach balance because of affinity.
*/
if (sd_parent) {
- int *group_imbalance = &sd_parent->groups->sgc->imbalance;
+ int *pinned_imb = &sd_parent->groups->sgc->pinned_imb;

if ((env.flags & LBF_SOME_PINNED) && env.imbalance > 0)
- *group_imbalance = 1;
+ *pinned_imb = 1;
}

/* All tasks on this runqueue were pinned by CPU affinity */
@@ -13973,21 +13973,21 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
out_balanced:
/*
* We reach balance although we may have faced some affinity
- * constraints. Clear the imbalance flag only if other tasks got
+ * constraints. Clear the pinned flag only if other tasks got
* a chance to move and fix the imbalance.
*/
if (sd_parent && !(env.flags & LBF_ALL_PINNED)) {
- int *group_imbalance = &sd_parent->groups->sgc->imbalance;
+ int *pinned_imb = &sd_parent->groups->sgc->pinned_imb;

- if (*group_imbalance)
- *group_imbalance = 0;
+ if (*pinned_imb)
+ *pinned_imb = 0;
}

out_all_pinned:
/*
* We reach balance because all tasks are pinned at this level so
- * we can't migrate them. Let the imbalance flag set so parent level
- * can try to migrate them.
+ * we can't migrate them. Let the pinned flag stay set so the parent
+ * level can try to migrate them.
*/
schedstat_inc(sd->lb_balanced[idle]);

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index e656c7059bf8..14ce0f6e6027 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2257,7 +2257,11 @@ struct sched_group_capacity {
unsigned long min_capacity; /* Min per-CPU capacity in group */
unsigned long max_capacity; /* Max per-CPU capacity in group */
unsigned long next_update;
- int imbalance; /* XXX unrelated to capacity but shared group state */
+ /*
+ * Set when a child domain cannot balance pinned tasks.
+ * XXX unrelated to capacity, but it is shared group state.
+ */
+ int pinned_imb;

int id;

--
2.54.0 (Apple Git-157)