![使用 systemd 单元文件覆盖,它可以有多个同名部分,如](https://linux22.com/image/164051/%E4%BD%BF%E7%94%A8%20systemd%20%E5%8D%95%E5%85%83%E6%96%87%E4%BB%B6%E8%A6%86%E7%9B%96%EF%BC%8C%E5%AE%83%E5%8F%AF%E4%BB%A5%E6%9C%89%E5%A4%9A%E4%B8%AA%E5%90%8C%E5%90%8D%E9%83%A8%E5%88%86%EF%BC%8C%E5%A6%82%20.png)
我有兴趣尝试覆盖 systemd 服务的 CPU 利用率。这样我就不会将机器锁定在我定期运行的某些占用大量 CPU 的进程上。
运行后systemctl edit containerd.service
我看到有两个[Service]
部分。
例如:
systemctl cat containerd.service
# /lib/systemd/system/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
Delegate=yes
KillMode=process
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/containerd.service.d/override.conf
# https://unix.stackexchange.com/questions/494843/how-to-limit-a-systemd-service-to-play-nice-with-the-cpu
# https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html
[Service]
CPUAccounting=True
CPUQuota=95%
MemoryAccounting=True
MemorySwapMax=0
当我查看具体值时
systemctl daemon-reload
systemctl show containerd.service | grep MemorySwap
MemorySwapMax=infinity
他们并没有表现出已经改变。我是否误解了这一切应该如何运作?
当我查看不同的值时,它确实显示为已更改。之前CPUAccounting=
是空的
systemctl show containerd.service | grep CPUAccountin
CPUAccounting=yes
更多信息
systemctl --version
systemd 237
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid
uname -a
Linux srv-acquisitions02 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux