已采纳
回答正文
回复
讨论正文
该问题的正文、回答与讨论。
【背景】 12 节点集群(K8s 1.28.9,containerd 1.7.13,内核 5.15.0-91,cgroup v2),跑两类实时采集业务,各自一个 Pod、一个 RT 线程:
【现象】
cpu.max=200000 100000(= 2 核上限)。但 A 线程 busy-loop 时(一段 8ms 的纯计算段),观察 cpu.stat 里 nr_throttled / throttled_usec 没有增长,/proc/<pid>/schedstat 显示 A 线程在这 8ms 内拿到了全部 16ms 的核时间(2 核 × 8ms),说明 cpu.max 对这个 RT 线程完全没生效。rt_throttled 计数发现是节点级 kernel.sched_rt_runtime_us(默认 950000)打满后 A 被 throttle——也就是说两个本不共享核的 RT 容器,被全局 RT 带宽限流"连坐"了。kernel.sched_rt_runtime_us 调到 -1(不限)后 A 的 P99 恢复,但 B 的 busy 段会持续占满核 4-5,导致节点上另一个普通 CFS 的日志 Pod 出现 200ms 级卡顿。【已尝试】
cpu.max → 对 RT 线程无效(见上面现象 1)kernel.sched_rt_runtime_us=-1 → A 恢复,但 B 反过来压 CFSusleep(1000) 让出 → 抖动从 45ms 降到 12ms,但引入的 sleep 时间本身又成了新的抖动源sched_rt_period_us 默认 1000(即 RT 每 1ms 周期最多用 950μs),改成 10000/9500 后 A 的 8ms busy 段被切成 8 片,每片之间让出,P99 回到 7ms,但 B 的 10ms 采集段被切成 10 片,P99 反而从 15ms 升到 22ms【期望得到的答案】
cpu.max(CFS bandwidth)是否对所有非 CFS 任务都不生效?内核里 RT 带宽是 sched_rt_runtime_us / sched_rt_period_us(全局)还是 cgroup 的 cpu.max?cpu.max 是否对 RT 无效、是否有 cgroup 级的 rt_runtime 字段?)sched_rt_period_us + 在业务侧让出,还是用 isolcpus + nohz_full 把 RT 核从 CFS 调度器里摘出来?SCHED_FIFO + SCHED_RESET_ON_FORK + 容器 entrypoint 三层叠加后,业务线程实际 prio 被 reset 掉的坑?怎么验证容器内 RT 线程的真实 prio 没被 runtime 重置?【参考】
希望有人给过生产环境的实测数据(schedstat / rt_throttled 计数 + 具体参数值),比纯理论推导更有用。