How do I set cgroup limits for systemd user slices?

Solution 1:

This worked for me on Ubuntu 16.04:

Edit /etc/systemd/logind.conf and set

UserTasksMax=12299

After rebooting my machine I could see the above value set (1000 is my UID):

cat /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.max
12299

Extract form man logind.conf:

   UserTasksMax=
       Sets the maximum number of OS tasks each user may run concurrently. This controls the TasksMax= setting of the per-user slice unit, see systemd.resource-control(5) for details. Defaults to 12288
       (12K). If assigned the special value "infinity", no tasks limit is applied.