32.7. 在引导过程中更改服务优先级
使用 systemd 服务时,可以在引导过程中为启动的服务设置实时优先级。单元配置指令 用于在引导过程中更改服务的优先级。
引导过程优先级更改通过使用 service 部分中的以下指令进行:
CPUSchedulingPolicy=-
设置已执行进程的 CPU 调度策略。它被用于设置
other,fifo, 和rr策略。 CPUSchedulingPriority=-
设置已执行进程的 CPU 调度优先级。可用的优先级范围取决于所选的 CPU 调度策略。对于实时调度策略,可以使用
1(最低优先级)和99(最高优先级)之间的整数。
下面的步骤描述了如何使用 mcelog 服务在引导过程中更改服务的优先级。
先决条件
安装 TuneD 软件包:
# yum install tuned启用并启动 TuneD 服务:
# systemctl enable --now tuned
流程
查看正在运行的线程的调度优先级:
# tuna --show_threads thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 1 OTHER 0 0xff 3181 292 systemd 2 OTHER 0 0xff 254 0 kthreadd 3 OTHER 0 0xff 2 0 rcu_gp 4 OTHER 0 0xff 2 0 rcu_par_gp 6 OTHER 0 0 9 0 kworker/0:0H-kblockd 7 OTHER 0 0xff 1301 1 kworker/u16:0-events_unbound 8 OTHER 0 0xff 2 0 mm_percpu_wq 9 OTHER 0 0 266 0 ksoftirqd/0 [...]创建附加
mcelog服务配置文件,并在该文件中插入策略名称和优先级:# cat << EOF > /etc/systemd/system/mcelog.service.d/priority.conf [Service] CPUSchedulingPolicy=fifo CPUSchedulingPriority=20 EOF重新载入
systemd脚本配置:# systemctl daemon-reload重启
mcelog服务:# systemctl restart mcelog
验证
显示
systemd问题设置的mcelog优先级:# tuna -t mcelog -P thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 826 FIFO 20 0,1,2,3 13 0 mcelog