jupyterhub / systemdspawner

Spawn JupyterHub single-user notebook servers with systemd
BSD 3-Clause "New" or "Revised" License
92 stars 45 forks source link

Resolve all fixme notes related to cgroup #126

Closed consideRatio closed 1 year ago

consideRatio commented 1 year ago

Two FIXME notes

There are two FIXME notes related to cgroups in systemdspawner.py:

https://github.com/jupyterhub/systemdspawner/blob/38875b4df8f91a36655f848439440fd31d549b98/systemdspawner/systemdspawner.py#L295-L305

Let's try resolve them!

Systemd's three modes

I figure we are not managing cgroups directly, but relying on systemd to do various things with cgroups when we use it to start system transient service units. It seems that there are three modes for systemd to run in:

To check if unified mode is used, we can check like this:

# short version of the same command:
# stat -fc %T /sys/fs/cgroup/
#
stat --file-system --format=%T /sys/fs/cgroup/

# if "cgroup2fs" is the output, then systemd runs in unified mode

Systemd function based on mode

Systemd can't support all functions or do it the same way in all the modes, and there are some notes about various modes in systemd docs about resource control.

CPUAccounting

This seems supported no matter what mode systemd runs in.

CPUQuota

CPUQuota seems supported on when systemd running in either mode.

It seems to be implemented differently behind the scenes using cgroup v1's cpu.cfs_quota_us or cgroup v2's cpu.max depending on.

MemoryAccounting

Should be fine to use no matter what.

MemoryLimit

This apparently is deprecated and replaced with MemoryMax instead, which is supported since at least v243 so we should be fine to replace MemoryLimit with MemoryMax.

Reference

behrmann commented 1 year ago

This apparently is deprecated and replaced with MemoryMax instead, which is supported since at least v243

MemoryMax= has been around since at least v232.

Generally, with given minimum systemd version, I wouldn't worry about cgroupv1 and say the system has to be at least hybrid.