systemd provides a powerful tool, systemd-run which can constrain how many system resources an application started by it can use. It can limit (non-exhaustive list) use of CPU, memory and disk. However, this powerful too is too complicated to use on the command line. A wrapper is required to make it easily accessible. Use case: running resource intensive tasks (such as backups, compression) without making the system (almost) unusable by the load generated by that task.
limit-low design goals:
Do one thing and do it well.
The one thing is to be a wrapper that limits system resources for wrapped
applications.
Being as non-intrusive as possible. For example, not adding extraneous
output to stdout such as
āRunning scope as unit: run-r0d607a8f35dc4dea909b830f9d922b99.scopeā.
limit-low is a around systemd-run setting systemd-run parameters to run an
application with limited system resources. systemd-run itself is using Linux cgroups.
systemd upstream feature request:
To start graphical (GUI) applications such as Tor Browser it requires installation of package dbus-user-session. The (non-)security impact of this is being discussed here: dbus - user vs system session.
Depending on the outcome of that discussion, dbus-user-session will be installed by default in Kicksecure and Whonix or perhaps systemd-run can be run with different parameters such as --scope not requiring dbus-user-session. --scope as alternative works but systemd tells:
--pty/--pipe is not compatible in timer or --scope mode
Perhaps it would be better to implement this with plain cgroups, i.e. cgexec? Avoiding systemd-run. Could avoid a lot issues such as dbus, environment variables, and whatnot.
Neither with cgroups one can easily say āuse maximum hard limit of xx % of available system resources (CPU, RAM, IO) for this applicationā.
Maxmium RAM can be a hard limit such as xxxx MB.
Throttling a device IO (virtual) (harddrive) syntax is <major>:<minor> <bytes_per_second>. See https://lqhl.me/blog/2015/09/09/network-disk-bandwidth-limiting-on-linux/. Also a hardcoded value. Which value to choose? One would have to benchmark the disk first before deciding on a reasonable value. Also finding out <major>:<minor> is non-trivial from a script.
It seems cgroups resource moderation is more useful to say āwithin this cgroup this application can use xx % of CPUā. This might be useful when implementing this for the whole system.
Maybe just combining ionice with nice would be a good enough hack. I.e.
ionice --class 3 nice -n 19 application-name
But that wouldnāt limit maximum RAM the application can use. And once RAM is exhausted, system will probably freeze or get so slow that one would loose patience and reboot.
Would be best if Debian had this implemented for the whole system. For example guaranteeing that X always has sufficient system resources and cannot be starved by a broken application.