You are not logged in.

#1 2021-01-22 08:35:09

1ptb3b
Member
Registered: 2017-01-17
Posts: 60

sudo systemd-run cgroups work, but systemd-run user cgroups don't

Hello, I'm trying to limit the number of CPU cores my binary has access to. I followed the guide here: https://wiki.archlinux.org/index.php/cg … cgroups_v2

I got this to work correctly.

$ sudo systemd-run -p AllowedCPUs=0 -- ./my-bin

I was able to verify that my-bin only uses 1 CPU core by checking in htop.

However, if I try to run as a non-root user, then this doesn't work. I'm able to see all the cores light up in htop.

$ systemd-run --user -p AllowedCPUs=0 -- ./my-bin

The right controllers seem to be enabled.

$ cat /sys/fs/cgroup/user.slice/user-1000.slice/cgroup.controllers    
cpuset cpu io memory pids

I also edited user@1000.service to include Delegate=yes.

This is my systemd version.

$ systemctl --version
systemd 247 (247.2-1-arch)
+PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYP
T +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 
default-hierarchy=hybrid

Offline

Board footer

Powered by FluxBB