我正在考虑cgroups
在我的 Linux 机器上工作,这很痛苦。
我觉得这应该容易得多,因为资源管理对于健康的桌面环境非常关键,这就是我尝试使用它的原因,但我刚刚遇到了很多问题。
我有一个/etc/cgconfig.conf
如下所示的文件:
group "chromium_slack" {
perm {
admin {
uid = "nate";
gid = "nate";
}
task {
uid = "nate";
gid = "nate";
}
}
cpu {
shares="50";
}
memory {
swappiness="60";
limit_in_bytes="256000000";
}
}
当我cgconfig
用这个启动服务时:
sudo systemctl start cgconfig.service
我得到的服务状态Cgroup, requested group parameter does not exist
如下所示:
× cgconfig.service - Control Group configuration service
Loaded: loaded (/usr/lib/systemd/system/cgconfig.service; enabled; preset: disabled)
Active: failed (Result: exit-code) since Thu 2022-12-15 15:17:16 EST; 11min ago
Process: 9559 ExecStart=/usr/bin/cgconfigparser -l /etc/cgconfig.conf -s 1664 (code=exited, status=95)
Main PID: 9559 (code=exited, status=95)
CPU: 8ms
Dec 15 15:17:16 nx systemd[1]: Starting Control Group configuration service...
Dec 15 15:17:16 nx cgconfigparser[9559]: /usr/bin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup, requested group parameter does not exist
Dec 15 15:17:16 nx systemd[1]: cgconfig.service: Main process exited, code=exited, status=95/n/a
Dec 15 15:17:16 nx systemd[1]: cgconfig.service: Failed with result 'exit-code'.
Dec 15 15:17:16 nx systemd[1]: Failed to start Control Group configuration service.
但是当我尝试cgcreate
像这样手动完成这一切时:
sudo cgcreate -a $USER -g memory,cpu:chromium_slack
sudo echo 256M > /sys/fs/cgroup/chromium_slack/memory.limit_in_bytes
我收到一个permission denied: /sys/fs/cgroup/chromium_slack/memory.limit_in_bytes
错误。
所以我想我的问题是......我到底如何让它发挥作用?
答案1
您应该在 root shell 内发出重定向:
sudo su - -c 'echo 256M > /sys/fs/cgroup/chromium_slack/memory.limit_in_bytes'