Akemi

Tuned系统调优服务

2025/04/25

Tuned 是 Linux 系统中的一个动态调优服务,能够根据系统负载和应用场景自动调整内核参数、硬件配置(如 CPU、磁盘、网络)和电源管理策略,以优化性能或节能。

也可以通过自定义调优配置文件的规则来满足需求

功能 描述
预定义调优策略 提供多种预设配置文件(Profiles),如 throughput-performance(高吞吐)、powersave(节能)。
动态适应负载 根据实时负载(如 CPU 使用率、磁盘 I/O)自动切换策略(需启用 dynamic tuning 模式)。
自定义调优规则 允许用户创建或修改配置文件,针对特定硬件或应用(如数据库、虚拟化)优化。
统一管理接口 通过 tuned-adm 命令行工具轻松切换和管理配置。

静态调优与动态调优

静态调优

固定参数值的调优

  • 修改系统配置文件(如 /etc/sysctl.conf
  • 调整硬件模式(如 cpupower 设置)
  • 选择预定义调优策略(如 Tuned 的 throughput-performance 配置集)

动态调优

通过监控系统指标(如 CPU 使用率、内存压力、磁盘 I/O),动态调整参数

比如:

  • 高负载时提升 CPU 频率、禁用节能模式。
  • 低负载时降低 CPU 电压、启用磁盘休眠。

典型实现

Tuned 的 dynamic_tuning 模式。

内核特性(如 ondemand CPU 调速器)。

第三方工具(如 PowerTOP 自动优化电源策略)。

tuned配置文件

Tuned 的配置文件即为预定义的优化策略,每个配置文件对应一种特定的优化“模式”,有默认的模式,也可以自定义新模式

配置文件 = 模式

  • 系统默认配置文件位置/usr/lib/tuned/
  • 用户自定义配置文件位置/etc/tuned/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 部署tuned服务
yum -y install tuned
apt -y install tuned
systemctl enable tuned.service --now

# 查看当前模式
tuned-adm active
Current active profile: virtual-guest

# 激活配置
tuned-adm profile <模式名称>

# 查看可用模式
tuned-adm list
Available profiles:
- accelerator-performance - Throughput performance based tuning with disabled higher latency STOP states
- aws - Optimize for aws ec2 instances
- balanced - General non-specialized tuned profile
- balanced-battery - Balanced profile biased towards power savings changes for battery
- desktop - Optimize for the desktop use-case
- hpc-compute - Optimize for HPC compute workloads
- intel-sst - Configure for Intel Speed Select Base Frequency
- latency-performance - Optimize for deterministic performance at the cost of increased power consumption
- network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance
- network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks
- optimize-serial-console - Optimize for serial console use.
- powersave - Optimize for low power consumption
- throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads
- virtual-guest - Optimize for running inside a virtual guest
- virtual-host - Optimize for running KVM guests
Current active profile: virtual-guest

# 配置文件
ls /usr/lib/tuned/
accelerator-performance desktop latency-performance powersave virtual-host
aws functions network-latency recommend.d
balanced hpc-compute network-throughput throughput-performance
balanced-battery intel-sst optimize-serial-console virtual-guest

配置文件解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
cat /usr/lib/tuned/virtual-guest/tuned.conf
[main]
summary=Optimize for running inside a virtual guest # 备注/描述
include=throughput-performance # 表示继承自 throughput-performance 模式

[sysctl] # 内核可调项
vm.dirty_ratio = 30 # 内存中“脏页”最大占比
vm.swappiness = 30 # 控制系统使用交换分区的倾向程度

除此之外还有
[cpu] # 调整 CPU 相关设置(如调节器、频率、节能模式)
governor=performance
energy_perf_bias=performance

[script] # 在 Tuned 配置激活或停用时运行自定义脚本
script=/usr/local/bin/custom_optimize.sh

[variables] # 定义变量供其他配置块引用
MY_DEVICES=sda, sdb

[disk] # 优化磁盘 I/O 行为(调度器、APM、缓存策略)
devices=${MY_DEVICES}
scheduler=mq-deadline
readahead=4096

[service] # 管理系统服务: 启用/禁用
service.firewalld=start,enable # 启动并启用服务
service.firewalld=stop,disable # 停止并禁用服务

[bootloader] # 修改内核启动参数
cmdline=mitigations=off isolcpus=1-4

CATALOG
  1. 1. 静态调优与动态调优
    1. 1.1. 静态调优
    2. 1.2. 动态调优
  2. 2. tuned配置文件
    1. 2.1. 配置文件解析