Linux tuned 的 throughput-performance vs latency-performance profile 切换

1次阅读

确认当前生效的 tuned profile 应执行 tuned-adm active,而非依赖 /etc/tuned/active_profile 文件;若输出 “no current active profile.” 则 tuned 服务未运行,需先 systemctl start tuned。

Linux tuned 的 throughput-performance vs latency-performance profile 切换

怎么确认当前生效的 tuned profile

直接看 tuned-adm active 输出,它会明确告诉你当前是 throughput-performance 还是 latency-performance,或者别的 profile。别信 /etc/tuned/active_profile 文件——这文件可能没及时更新,尤其在手动 reload 或 service 重启后容易滞后。

常见错误是改了配置却没 reload,或者用 systemctl restart tuned 后没验证是否真生效。实操建议:

  • 执行 tuned-adm active 确认当前状态
  • 执行 tuned-adm list 看系统里有哪些 profile 可用(有些发行版默认不装 latency-performance
  • 如果输出是 No current active profile.,说明 tuned 服务根本没运行,先 systemctl start tuned

throughput-performance 和 latency-performance 的核心差异在哪

不是“快”和“稳”的模糊对比,而是 CPU 调度策略、中断处理粒度、电源管理行为的组合差异。关键点在于:latency-performance 会禁用 CPU 频率缩放(cpupower frequency-set -g performance)、关闭 C-states(尤其是 C1E/C6)、让 timer tick 更密集(timer_migration=0),而 throughput-performance 允许更深的 idle state、更激进的频率调节,适合吞吐密集型负载(如批量计算、数据库写入)。

典型场景:跑低延迟交易程序或实时音频处理时,latency-performance 能压住 irqbalance 并绑定中断到特定 CPU;但如果你跑的是 spark 或编译任务,反而可能因禁止降频导致散热压力大、整体完成时间变长。

切换 profile 时最常踩的坑

切完 profile 不等于所有参数立刻生效,tuned 的某些设置(比如内核参数 vm.swappinesskernel.sched_latency_ns)需要 reboot 才能落地,但多数 CPU / IRQ 相关项 reload 就生效。容易忽略的点:

  • tuned-adm profile latency-performance 后,检查 cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 是否全为 performance;如果不是,说明 profile 没真正应用(常见于 profile 缺失或 tuned 未加载模块)
  • latency-performance 默认会停用 irqbalance,但如果你手动启了它,冲突会导致中断分布混乱,延迟毛刺反而更严重
  • 某些云厂商镜像(如 AWS AL2、azure RHEL)默认删掉了 latency-performance profile,得手动从 tuned 包里解出模板再安装,否则 tuned-adm profile latency-performance 会报错 Profile latency-performance does not exist.

要不要在容器或 K8s 节点上用 latency-performance

要,但只在真正需要微秒级确定性的节点上用,比如部署 DPDK 应用、eBPF trace 工具或金融行情解析服务的物理节点。K8s worker 节点若混跑多种 workload,盲目开 latency-performance 会让其他 Pod 因 CPU 抢占加剧而抖动更明显。

实操注意:

  • 容器本身不继承 host 的 tuned profile,但 host 的 CPU 调度、中断绑定、C-state 控制直接影响容器内进程延迟
  • 不要在虚拟机里开 latency-performance——hypervisor 层的调度器和资源复用机制会让这些调优大部分失效,甚至引发 guest 内核 panic(尤其在旧版 kernel + QEMU 组合下)
  • 如果用了 systemd-cpucpusets 做绑核,确保 tuned 的 IRQ 绑定不跟它冲突(比如 tuned 把 irq 绑到 cpu4-7,而你把容器绑到 cpu0-3,那其实没问题;但如果都抢同一组 CPU,就会卡死)

profile 切换不是开关按钮,背后是几十个内核参数和设备驱动行为的联动。哪怕只是改一个 intel_idle.max_cstate=1,也得确认 BIOS 里没锁死 C-state——很多服务器默认开启 C-STATE ENHANCED,OS 层设置会被硬件无视。

text=ZqhQzanResources