1. Someone said me that, systemd takes control of cgroup-tools package after Debian 10, so in Debian 11. I checked it and it seems correct. But I do not know how to use systemd and it looks more complex than cgroups.
2. I searched the internet and find a way to create cgroup service to limit chromium's cpu limit in https://gist.github.com/jakewarren/477e ... 7a7c9abaa3. I modify the code given there to create a configuration file >> /etc/cgconfig.conf :
Code: Select all
group browsers {
perm {
task {
uid = user;
gid = user;
}
admin {
uid = root;
gid = root;
}
}
cpu {
# Allow chromium to use only %25 of the cpu
cpu.shares = 250 ;
}
memory {
# Allow chromium to use 256 MB ram maximum
memory.limit_in_bytes = "256m";
}
}
group important {
perm {
task {
uid = user;
gid = user;
}
admin {
uid = root;
gid = root;
}
}
cpu {
# Allow other processes to use %75 of CPU
cpu.shares = 750;
}
memory {
# Allow chromium to use 512MB maximum
memory.limit_in_bytes = "512m";
}
}
mount {
cpuacct = /sys/fs/cgroup/cpuacct;
memory = /sys/fs/cgroup/memory;
devices = /sys/fs/cgroup/devices;
freezer = /sys/fs/cgroup/freezer;
net_cls = /sys/fs/cgroup/net_cls;
blkio = /sys/fs/cgroup/blkio;
cpuset = /sys/fs/cgroup/cpuset;
cpu = /sys/fs/cgroup/cpu;
}
Then I created file called "/etc/cgrules.conf" to define a process (i.e. chromium browser executable file) for browsers group for "user:user" :
Code: Select all
# user:process subsystems group
user:/usr/bin/chromium %U --incognito cpu,cpuset,cpuacct browsers
Code: Select all
[Unit]
Description=Load cgroup configs
After=default.target
[Service]
Type=forking
ExecStartPre=/bin/echo "Precessing /etc/cgconfig.cong..."
ExecStartPre=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf
ExecStartPre=/bin/echo "Processing /etc/cgrules.conf file..."
ExecStart=/usr/sbin/cgrulesengd --logfile=/var/log/cgrulesengd.log
Restart=on-failure
[Install]
WantedBy=multi-user.target
In /etc/systemd/system/ folder, I changed the permission of the file by
Code: Select all
sudo chmod 777 cgroup.service
Next, I tried to enable service by using
Code: Select all
sudo systemctl enable cgroup.service
Code: Select all
sudo systemctl start cgroup.service
Code: Select all
cgroups.service - Load cgroup configs
Loaded: loaded (/etc/systemd/system/cgroups.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2021-10-30 18:47:04 GMT; 7min ago
CPU: 6ms
Eki 30 18:47:04 debian systemd[1]: cgroups.service: Scheduled restart job, restart counter is at 5ms.
Eki 30 18:47:04 debian systemd[1]: Stopped Load cgroup configs.
Eki 30 18:47:04 debian systemd[1]: cgroups.service: Start request repeated too quickly.
Eki 30 18:47:04 debian systemd[1]: cgroups.service: Failed with result 'exit-code'.
Eki 30 18:47:04 debian systemd[1]: Failed to start Load cgroup configs.
Code: Select all
cgroups.service - Load cgroup configs
Loaded: loaded (/etc/systemd/system/cgroups.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2021-10-30 19:15:53 GMT; 20min ago
Process: 4638 ExecStartPre=/bin/echo Precessing /etc/cgconfig.cong... (code=exited, status=0/SUCCESS)
Process: 4639 ExecStartPre=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf (code=exited, status=101)
CPU: 5ms
Eki 30 19:15:53 debian systemd[1]: cgroups.service: Scheduled restart job, restart counter is at 5.
Eki 30 19:15:53 debian systemd[1]: Stopped Load cgroup configs.
Eki 30 19:15:53 debian systemd[1]: cgroups.service: Start request repeated too quickly.
Eki 30 19:15:53 debian systemd[1]: cgroups.service: Failed with result 'exit-code'.
Eki 30 19:15:53 debian systemd[1]: Failed to start Load cgroup configs.
Code: Select all
sudo /usr/sbin/cgconfigparser -l /etc/cgconfig.conf
Code: Select all
Error: cannot mount memory to /sys/fs/cgroup/memory: Device or resource busy
/usr/sbin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup mounting failed