27.7. 在引导过程中更改服务优先级
您可以使用 systemd 服务为在启动过程中启动的服务配置实时优先级。单元配置指令在启动过程中更改服务优先级。
您可以使用 service 部分中的不同指令来更改引导过程优先级。
-
CPUSchedulingPolicy=:设置正在运行的进程的 CPU 调度策略。它用于设置 other、fifo 和 rr 策略。 -
CPUSchedulingPriority=:设置正在运行的进程的 CPU 调度优先级。可用的优先级范围取决于所选的 CPU 调度策略。对于实时调度策略,可以使用 1(最低优先级)和 99(最高优先级)之间的整数。
您可以使用 mcelog 服务,在引导过程中更改服务的优先级。
先决条件
-
您已安装并启用了
tuned。如需更多信息,请参阅 安装和启用 TuneD。
流程
查看正在运行的线程的调度优先级:
# tuna --show_threadsthread 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 -Pthread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 826 FIFO 20 0,1,2,3 13 0 mcelog