sched/cache: Avoid publishing partial LLC utilization
Subsystems (2)
PATCH v3 1/1 sched/cache: Avoid publishing partial LLC utilization
update_sg_lb_stats() sums utilization over the CPUs in both sched_group_span(group) and env->cpus, but takes capacity from group->sgc->capacity for the whole group. record_sg_llc_stats() publishes both.
Rejecting an all-affinity-pinned source runqueue removes that CPU from env->cpus and retries group selection. The retry can publish the partial utilization with the full capacity.
can_migrate_llc() then treats a busy preferred LLC as having spare capacity. More tasks can aggregate into it, migrations out can be blocked, and two busy LLCs may not fall back to generic balancing. This increases CPU contention and task latency. Found by inspection.
Skip publication on affinity retries using LBF_ALL_PINNED, retaining the first-pass snapshots and avoiding repeated cpumask checks. On the first pass, publish either shared LLC statistic only when env->cpus covers the whole group. Load balancing still uses the affinity-filtered statistics.
The same window exists during CPU hotplug. env->cpus drops a CPU at set_cpu_active(false), but the group span and sgc->capacity still include it until cpuset_cpu_inactive() rebuilds the domains. Keeping the previous snapshot avoids the mismatched publish. After the rebuild, the next periodic balance records both statistics again.
---
v2: https://lore.kernel.org/r/[email protected]/
v1: https://lore.kernel.org/r/[email protected]/
Changes since v2:
- Clarify that LBF_ALL_PINNED identifies affinity redos here and that retaining the recent first-pass snapshot avoids publishing partial utilization against full capacity, as suggested by Chen Yu.
- Add Cc: [email protected] # 7.2.x, as suggested by Tim.
- Add Reviewed-by tags from Tim Chen and Chen Yu.
- No functional changes.
Changes since v1:
- Skip publication on affinity retries using LBF_ALL_PINNED, retaining first-pass snapshots and avoiding repeated cpumask checks, as suggested by Prateek and Tim. Keep cpumask_subset() for partial group coverage during CPU hotplug on the first pass.
- Update the comment and commit message to explain the retry behavior.
- Add Fixes and Suggested-by tags.
kernel/sched/fair.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/sched/fair.c +10 -0
@@ -12111,6 +12111,16 @@ static void record_sg_llc_stats(struct lb_env *env,if (env->sd->child !=rcu_dereference_all (per_cpu (sd_llc, env->dst_cpu)))return ; +/* +* Here, LBF_ALL_PINNED is set only on affinity redos. Keep the recent +* first-pass snapshot, since env->cpus may now be incomplete. +* Hotplug can also leave env->cpus incomplete on the first pass; +* do not publish partial utilization against the full group capacity. +*/ +if ((env->flags &LBF_ALL_PINNED ) || + !cpumask_subset (sched_group_span (group), env->cpus)) +return ; +/* * At this point we know this group spans a LLC domain. * Record the statistic of this group in its corresponding
base-commit: 2f2f7eeef8b0a1a9b9ca998231419873ccae8d4e --
2.25.1