cpu.max not created with cgroup2
Closed this issue · 3 comments
Xeway commented
res := cgroup2.Resources{
CPU: &cgroup2.CPU{
Max: cgroup2.NewCPUMax(nil, &maxCPUValue),
},
}
if err := m.Update(&res); err != nil {
log.Fatal(err)
}
When I run: go build && sudo ./my-program
, I get the error: open /sys/fs/cgroup/my_cgroup.slice/cpu.max: permission denied
.
And in reality, the cpu.max file doesn't exists. I tried to create it but I always get permission denied
even when I change chmod to 777 for /sys/fs/cgroup/my_cgroup.slice
directory.
axliupore commented
What environment are you running in?
Xeway commented
My bad, fixed it with echo '+cpu' | sudo tee /sys/fs/cgroup/cgroup.subtree_control
.
Xeway commented
If anyone passes by, instead of directly writing to cgroup.subtree_control
file, you can also add controllers with ToggleControllers
function.
Here's an example of how to use it to add memory and cpu controllers:
// Enable the memory and CPU controllers
if err := m.ToggleControllers([]string{"memory", "cpu"}, cgroup2.Enable); err != nil {
log.Fatal(err)
}