3

I created a cgroup named mycgroup using mkdir /sys/fs/cgroup/mycgroup.

Before executing echo +cpu > /sys/fs/cgroup/cgroup.subtree_control:

[root@host ~]# cat /sys/fs/cgroup/mycgroup/cpu.max cat: /sys/fs/cgroup/mycgroup/cpu.max: No such file or directory 

After executing echo +cpu > /sys/fs/cgroup/cgroup.subtree_control:

[root@host ~]# cat /sys/fs/cgroup/mycgroup/cpu.max max 100000 

But after executing systemctl daemon-reload:

[root@host ~]# cat /sys/fs/cgroup/mycgroup/cpu.max cat: /sys/fs/cgroup/mycgroup/cpu.max: No such file or directory 

Daemon reload is resetting the cgroup.subtree_control file. How do I make the setting permanent so that daemon reload does not remove cpu from the file?

1
  • 1
    The subtree_control modifications don't survive reboot either. I would very much like to discover how the defaults are set also. I have other Debian installs that default to having the cpu controller enabled in subtree_control. Commented Sep 25, 2023 at 16:32

1 Answer 1

0

Figured it out.

Quote from Where are systemd's configurations for cgroups?

As I read it, if no units have a value set for CPUShares and CPUAccounting is not explicitly enabled anywhere (and DefaultCPUAccounting is not set in system.conf) then systemd may not (will not?) use the cpu hierarchy at all.

This is mostly true. Simply putting the line DefaultCPUAccounting=yes into /etc/systemd/system.conf had no effect for me.

The takeaway: If no service unit files require the CPU controller, it seems systemd doesn't turn it on.

So I tested it. I rebooted into a fresh Debian 12 system.

cat /sys/fs/cgroup/cgroup.subtree_control memory pids 

I added this to the [Service] section of /usr/lib/systemd/system/nginx.service:

# https://unix.stackexchange.com/a/495013/237874 # https://unix.stackexchange.com/questions/494843/how-to-limit-a-systemd-service-to-play-nice-with-the-cpu/495013#495013 CPUQuota=75% 

Then...

systemctl daemon-reload cat /sys/fs/cgroup/cgroup.subtree_control cpu memory pids 

Even after a reboot, subtree_control still lists cpu!

Edit: CPUQuota=75% in the /usr/lib/systemd/system/nginx.service file produces this:

cat /sys/fs/cgroup/system.slice/nginx.service/cpu.max 75000 100000 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.