====== Технология cgroup ====== * [[https://habrahabr.ru/company/selectel/blog/303190/|Механизмы контейнеризации: cgroups]] (сокращение от control groups, контрольные группы) * [[https://habr.com/ru/companies/redhatrussia/articles/423051/|Борьба за ресурсы, часть 1: Основы Cgroups]] ===== cgroup v2 ===== * [[https://pavlokhmel.com/cgroup-v2-limit-memory-and-cpu-usage-for-all-users-on-linux.html|Cgroups v2 - limit memory and CPU usage for all users on Linux]] # lssubsys -a # systemd-cgls /apache2 # cat /sys/fs/cgroup/system.slice/apache2.service/memory.high # echo 2000000 > /sys/fs/cgroup/system.slice/apache2.service/memory.high # time curl 127.0.0.1 # systemctl edit --force --full my.slice [Unit] Description=My Slice Before=slices.target [Slice] MemoryAccounting=true MemoryLimit=64M MemoryHigh=64M CPUAccounting=true CPUQuota=5% TasksMax=4096 # systemctl edit apache2.service [Service] Slice=my.slice # systemctl daemon-reload # systemctl restart apache2.service # systemd-cgls /apache2 # cat /sys/fs/cgroup/my.slice/memory.high # cat /sys/fs/cgroup/my.slice/cpu.max ===== cgroup v1 (Debian10/Ubuntu20) ===== # ls /sys/fs/cgroup/ # mkdir /sys/fs/cgroup/memory/group0 # echo $$ > /sys/fs/cgroup/memory/group0/tasks # echo 1M > /sys/fs/cgroup/memory/group0/memory.limit_in_bytes или # echo 512K > /sys/fs/cgroup/memory/group0/memory.limit_in_bytes # vim anyfile