好的,我设法做到了与您相同的方式,但是做了一些更改:
1)我安装了相同的实用程序:
sudo apt-get install cgroup-bin cgroup-lite cgroup-tools cgroupfs-mount libcgroup1
2)我这样编辑conf文件:
/etc/init/cgroup-lite.conf
description "mount available cgroup filesystems"
author "Serge Hallyn <serge.hallyn@canonical.com>"
start on mounted MOUNTPOINT=/sys/fs/cgroup
pre-start script
test -x /bin/cgroups-mount || { stop; exit 0; }
test -d /sys/fs/cgroup || { stop; exit 0; }
/bin/cgroups-mount
cgconfigparser -l /etc/cgconfig.conf
end script
post-stop script
if [ -x /bin/cgroups-umount ]
then
/bin/cgroups-umount
fi
end script
/etc/cgconfig.conf
# Since systemd is working well, this section may not be necessary.
# Uncomment if you need it
#
# mount {
# cpuacct = /cgroup/cpuacct;
# memory = /cgroup/memory;
# devices = /cgroup/devices;
# freezer = /cgroup/freezer;
# net_cls = /cgroup/net_cls;
# blkio = /cgroup/blkio;
# cpuset = /cgroup/cpuset;
# cpu = /cgroup/cpu;
# }
group limitcpu{
cpu {
cpu.shares = 400;
}
}
group limitmem{
memory {
memory.limit_in_bytes = 512m;
}
}
group limitio{
blkio {
blkio.throttle.read_bps_device = "252:0 2097152";
}
}
group browsers {
cpu {
# Set the relative share of CPU resources equal to 25%
cpu.shares = "256";
}
memory {
# Allocate at most 512M of memory to tasks
memory.limit_in_bytes = "512m";
# Apply a soft limit of 512 MB to tasks
memory.soft_limit_in_bytes = "384m";
}
}
group media-players {
cpu {
# Set the relative share of CPU resources equal to 25%
cpu.shares = "256";
}
memory {
# Allocate at most 256M of memory to tasks
memory.limit_in_bytes = "256m";
# Apply a soft limit of 196 MB to tasks
memory.soft_limit_in_bytes = "128m";
}
}
cgconfigparser -l /etc/cgconfig.conf
和 /etc/cgrules.conf
user:process subsystems group
[user]:/usr/lib/chromium-browser/chromium-browser cpu,memory browsers
[user]:/usr/bin/clementine cpu,memory media-players
例如,使用您的用户名而不是[user]。您可以添加需要限制的应用程序,并定义您是否希望它们受CPU,内存或两者限制。
我在中编辑了这一GRUB_CMDLINE_LINUX_DEFAULT行/etc/default/grub:
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1"
更新它:
sudo update-grub
3)最后重新启动以应用更改。
这就是我的工作方式。在此之前,我经常使用多任务处理OOM,例如使用大量资源的铬浏览器,克莱门汀,崇高文本和其他应用程序,现在它们运行平稳,我可以更好地完成多任务。
我真的希望这可以帮助其他人。
当前使用具有Intel Dual Core 2.6 Ghz和4 Gb的Ubuntu 16.04 LTS 。内存。
cgconfig.conf而不是cgconf.conf。如果systemd正在执行其工作,则我认为您不需要mount此文件中的部分。