Unleash Linux process
2022-01-30
If you execute ulimit -a
in a shell
$ ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8192
-c: core file size (blocks) 0
-m: resident set size (kbytes) unlimited
-u: processes 95020
-n: file descriptors 1024
-l: locked-in-memory size (kbytes) 64
-v: address space (kbytes) unlimited
-x: file locks unlimited
-i: pending signals 95020
-q: bytes in POSIX msg queues 819200
-e: max nice 0
-r: max rt priority 0
-N 15: unlimited
it shows various resource limits imposed to the process. Same limits will eventually be inherited by the shell children.
In this case, you can observe Alpine Linux being quite restrictive on the maximum locked-in-memory size (64KB). This is usually not a problem, but particular programs might have a difficult time in such restricted environment. An example is Ardour, at the time of writing, my DAW of choice. If I just run it, the first thing it does is complaining. It wants the opportunity to lock more memory.
$ ardour6
WARNING: Your system has a limit for maximum amount of locked memory!
This might cause Ardour to run out of memory before your system runs
out of memory. You can view the memory limit with 'ulimit -l', and it
is normally controlled by /etc/security/limits.conf
Ardour6.9.0 (built using 6.9 and GCC version 10.3.1 20210625)
Looking for help, I couldn’t find a solution that applied to my case. Most
suggestions were about editing /etc/security/limits.conf
. Here you can
customize global limits for the user session. A comment in the same file reads:
#This file sets the resource limits for the users logged in via PAM.
. If I
logged in via a display manager such as LightDM, that would probably work, as
PAM would happily set my custom limits. The problem is I don’t use a DM.
I use a simple login shell, which doesn’t go through PAM.
I believe PRLIMIT(1) could be a workaround. This tool allows to set limits of a running process. So I prepared 2 sh lines that do the trick.
#!/bin/sh -eux
doas /usr/bin/prlimit --pid $$ --memlock=unlimited
exec "$@"
This script:
- unlimits the maximum locked memory for itself (
$$
); - replaces itself (
exec
) with whatever is passed inside$@
.
Because it needs root to increase a hard limit, I’ve told doas not to bother me asking for my password.
permit nopass fmac as root cmd /usr/bin/prlimit
Not ideal, but keeps it simple.
Now I just have to run Ardour with unlea.sh
, and it won’t
complain anymore.
$ unlea.sh ardour6
+ doas /usr/bin/prlimit --pid 7711 '--memlock=unlimited'
+ exec ardour6
Ardour6.9.0 (built using 6.9 and GCC version 10.3.1 20210625)
I can also confirm the new limits.
$ cat /proc/`pidof ardour-6.9.0`/limits
Limit Soft Limit Hard Limit Units
...
Max locked memory unlimited unlimited bytes
...
Last touch, since I like to start applications with Rofi, is to edit
~/.local/share/applications/ardour6.desktop
so that it will use unlea.sh.
$ cat .local/share/applications/ardour6.desktop
[Desktop Entry]
...
Exec=unlea.sh ardour6
...