使用systemd的资源限制

时间:2019-01-04 12:14:22

标签: systemd cgroups

我使用 systemd 启动了一个进程,该进程进一步产生了10个子进程。 我在里面明确指定 /etc/systemd/system/myservice.service.d/10-limits.conf

[Service]
MemoryMax=40M
MemoryLimit=40M

希望这会将在此服务下启动的所有进程的累积使用限制为40M。

执行时 systemctl status myservice 我看到

● myservice.service - LSB: Start and stop myservice
   Loaded: loaded (/etc/rc.d/init.d/myservice; bad; vendor preset: disabled)
  Drop-In: /etc/systemd/system/myservice.service.d
           └─10-limits.conf
   Active: active (running) since Fri 2019-01-04 03:44:07 PST; 14min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18236 ExecStop=/etc/rc.d/init.d/myservice stop (code=exited, status=0/SUCCESS)
  Process: 18355 ExecStart=/etc/rc.d/init.d/myservice start (code=exited, status=0/SUCCESS)
   Memory: 99.9M (limit: 40.0M)
   CGroup: /system.slice/myservice.service
           ├─18382 one
           ├─18421 two
           ├─18422 three
           ├─18423 four
           └─18513 ten

Memory: 99.9M (limit: 40.0M)下,我看到40M正在反映,但是总内存消耗约为100M。

我可以看到〜100M来自/sys/fs/cgroup/memory/system.slice/myservice.service/memory.limit_in_bytes 其中有104857600

/sys/fs/cgroup/memory/system.slice/myservice.service/memory.limit_in_bytes如何获得104857600? 以及如何确保我在/etc/systemd/system/myservice.service.d/10-limits.conf中传递的所有内容都具有优先权?

0 个答案:

没有答案