v3
2026-10-29
调度器 LLC 粒度缓存感知聚合 · v3
调度拓扑新增LLC到NUMA映射与亲和序列,并计算缓存迁移增益以选择源节点。
原始补丁链接
子 Patch(17)
1/17
sched/topology: Add llc_to_node() to translate LLC ID to NUMA node
新增 LLC ID 到 NUMA 节点映射及 llc_to_node(),由持有该 LLC ID 的 possible CPU 推导,未分配 ID 返回 NUMA_NO_NODE,供构建亲和序列查询。
2/17
sched/topology: Build NUMA node affinity sequences
为每个 cache-preferred NUMA 节点预计算节点亲和序列:按 NUMA 距离排序,距离相同时用三角偏移而非节点 ID 破同分,供后续聚合使用。
3/17
sched/topology: Add an iterator for cached NUMA node affinity rows
新增 for_each_affi_node() 遍历缓存的节点亲和行,先本地再按距离和三角 tie rank;整行用 RCU 固定,表缺失时只访问本地节点。
4/17
sched/topology: Build triangular affinity orders for LLCs in a node
按节点内 LLC ID 建 rank,用三角偏移 i*(i+1)/2 mod M 生成排列及逆映射,并按 preferred LLC rank 循环移位,避免低 ID LLC 被系统性优先。
5/17
sched/topology: Walk LLCs in NUMA node
按节点分组存升序 LLC ID 并缓存 CPU span;新增按 ID/span 的迭代器(span 跳过空项),在 CPU 挂接/脱离 root domain 或释放 LLC ID 后刷新 RCU 映射。
6/17
sched/cache: Prioritize cache-preferred node selection over LLC selection
修改 task_cache_work():先按节点汇总占用决定 cache-preferred node,仅超过当前两倍才切换,再选节点内最忙 LLC,避免小波动重排整个 LLC 亲和序列。
7/17
sched/topology: Add per-sd scratch for cache-aware load balancing
在每 CPU 底层 sched domain 预分配 cache-aware 均衡所需的 LLC/node ID、亲和权重数组及临时 CPU mask,按 llc_max 和 cpumask_size 定大小,避免均衡路径分配内存。
8/17
sched/cache: Introduce helpers for task migration decisions
新增 get_node_stats() 聚合节点 util/capacity/LLC 数,扩展 fits_llc_capacity() 支持 <=/< 阈值;用节点和节点内 LLC 亲和序列判断迁移朝向并据 util 允许扩展。
9/17
sched/cache: Introduce rq affinity gain calculation
引入源 rq 对目标 CPU 的亲和增益计算:筛出会提升亲和性的 preferred LLC/cache-preferred node,再按权重累加源 rq 相应任务数;NUMA 域用原始距离差。
10/17
sched/cache: Pick the source rq/group with the highest affinity gain
当 llc_aggr_tolerance>1 时用亲和增益选源 group/rq,支持目标非 preferred LLC 但按序列更优的跨 LLC 聚合;tolerance=1 保留原 preferred LLC 计数指标以省开销。
11/17
sched/cache: Drop prefer_sibling restriction for llc_balance
group_llc_balance 不再要求 busiest group 子域 prefer_sibling,只要本地组有空闲容量就强制平衡,修复多级 NUMA 上 SD_PREFER_SIBLING 被清导致无法跨 socket 聚合。
12/17
sched/cache: Apply multi-LLC aggregation policy to task migration
将多 LLC 聚合策略扩展到两端都非 preferred LLC 的迁移:if_to_prefer() 判方向,can_migrate_llcs() 据方向与 LLC 负载决定是否阻止;active balance 也改用该检查。
13/17
sched/cache: Allow active balance to spread load from a full LLC
当源 LLC 超聚合阈值、目标可多容纳一 CPU 负载且源领先目标至少两 CPU 时,允许 migrate_task 不等 nr_balance_failed 阈值就触发 active balance,及时疏散满载 LLC。
14/17
sched/cache: Consider LLC load when selecting a single-task source rq
When a source sched group spans multiple LLCs and every eligible rq has at most one runnable task, migrate_task selects the first eligible rq. It cannot distinguish an LLC above the aggregation thresh
15/17
sched/cache: Include recently used preferred nodes in LLC scans
get_scan_cpumasks() includes the current task’s preferred NUMA node, but other tasks sharing the mm may prefer different nodes. This makes the LLC scan scope depend on which task performs the scan. R
16/17
sched/cache: Drop stale preferred LLC checks
With multi-LLC aggregation, an mm’s preferred LLC can be outside a task’s preferred NUMA node. Do not discard that LLC when calculating the task’s preference. Likewise, an LLC migration may select a
17/17
sched/debug: Show cache placement and preferred LLC in /proc/<pid>/sched
在 /proc//sched 输出 mm 选中 CPU 及其 LLC/NUMA 节点,以及任务 preferred LLC 和节点,便于诊断 cache-aware 调度与任务放置。