3

I'm using kubuntu 18.04

While testing a script which spawns a lot of parallel processes, I started getting fork: retry: resource temporarily unavailable error messages. Assuming that this was a per-user process limit, I started looking through the usual process limit configurations; eventually, I convinced myself that Ubuntu is now using systemd to configure per user limits, and that the limit I need to change is TasksMax.

In particular, by recursive grepping I eventually found this file:

$ cat /run/systemd/transient/user-1000.slice
# This is a transient unit file, created programmatically via the systemd API. Do not edit.
[Unit]
Description=User Slice of rici
After=systemd-logind.service
After=systemd-user-sessions.service

[Slice]
TasksMax=10813

I understand all that, but it doesn't tell me how I do change this value. All it does is tell me how not to do it (by editing the file). It also doesn't provide the least hint of how the number 10813 was computed; on the fact of it, it seems like an odd (albeit not quite prime) value to come up with as a default.

  1. Is there some simple command in the vein of ulimit which I can use to change this setting on-the-fly? Or even a complicated one? (And could I have used this hypothetical command to ascertain the current limit?)

  2. If I really have to restart my login session to change the task limit -- something I'd really prefer to avoid -- what do I have to poke to change the default value?

2
  • 1
    see here , but in particular the comments at the end for your case. Aug 20, 2018 at 22:05
  • @dougsmythies: Thanks. That helped me get the test done, anyway. If I understood the way it all worked better, I'd try to condense that down to a simple pithy answer, but I don't feel up to it quite yet.
    – rici
    Aug 20, 2018 at 22:40

1 Answer 1

0

Systemd use a linux kernel feature called cgroups to control the amount of resources users can use. This feature is somewhat more comprehensive than the traditional rlimit which is set using the ulimit command.

As you have discovered, number of threads+processes you can have is controlled by the systemd TasksMax parameter. The description of this parameter says:

This either takes an absolute number of tasks or a percentage value that is taken relative to the configured maximum number of tasks on the system.

For individual user logins, this parameter is typically controlled by a file /usr/lib/systemd/system/user-.slice.d/10-defaults.conf which contains:

[Slice]
TasksMax=33%

This explains the seemingly odd value you found for your user login - it is a percentage of the overall value of pids.max (or for earlier kernels, threads-max).

To change the value:

  1. Create a file /etc/systemd/system/user-.slice.d/99-taskmax.conf containing:
[Slice]
TasksMax=80% # or whatever value you want
  1. Reload systemd:
systemctl daemon-reload

You can alter the value for individual users by creating drop-in files under directories named /usr/lib/systemd/system/user-${UID}.slice.d where ${UID} is the user ID of the user you wish to alter.

Note also that the name of the drop in file is important: the files in all directories, including those under /usr/lib, are sorted according to their file name, and the last encountered value for each parameter is the value that will be used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .