3.3. 使用 tuna 工具调优 CPU
tuna
工具命令可以针对单个 CPU 为目标。通过使用 tuna
工具,您可以执行以下操作:
隔离 CPU
- 在指定 CPU 上运行的所有任务都移至下一个可用 CPU。通过将 CPU 从所有线程的关联性掩码中删除来隔离 CPU ,使其不可用。
包括 CPU
- 允许任务在指定的 CPU 上运行。
恢复 CPU
- 将指定的 CPU 恢复到之前的配置。
先决条件
-
tuna
工具已安装。如需更多信息,请参阅 安装 tuna 工具。
流程
列出所有 CPU,并指定受命令影响的 CPU 的列表:
# ps ax | awk 'BEGIN { ORS="," }{ print $1 }' PID,1,2,3,4,5,6,8,10,11,12,13,14,15,16,17,19
在
tuna
界面中显示线程列表:# tuna show_threads -t 'thread_list from above cmd'
指定要受某一命令影响的 CPU 的列表:
# *tuna [command] --cpus cpu_list *
cpu_list 参数是一个用逗号分开的 CPU 号的列表,如
--cpus 0,2
。要将特定 CPU 添加到当前的 cpu_list 中,请使用例如
--cpus +0
。根据您的场景,执行以下操作之一:
要隔离一个 CPU,请输入:
# tuna isolate --cpus cpu_list
要包括一个 CPU,请输入:
# tuna include --cpus cpu_list
要使用具有四个或更多处理器的系统,请使所有
ssh
线程在 CPU 0 和 1 上运行,使所有http
线程在 CPU 2 和 3 上运行:# tuna move --cpus 0,1 -t ssh* # tuna move --cpus 2,3 -t http\*
验证
显示当前配置,并验证更改是否已应用:
# tuna show_threads -t ssh* pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 855 OTHER 0 0,1 23 15 sshd # tuna show_threads -t http\* pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 855 OTHER 0 2,3 23 15 http
其他资源
-
/proc/cpuinfo
文件 -
系统上
tuna (8)
手册页