我有兴趣尝试覆盖 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