bustd is a lightweight process killer daemon for out-of-memory scenarios for Linux!
bustd seems to use less memory than some other lean daemons such as earlyoom:
$ ps -F -C bustd
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
vrmiguel 353609 187407 5 151 8 2 01:20 pts/2 00:00:00 target/x86_64-unknown-linux-musl/release/bustd -V -n
$ ps -F -C earlyoom
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
vrmiguel 350497 9498 0 597 688 6 01:12 pts/1 00:00:00 ./earlyoom/¹: RSS stands for resident set size and represents the portion of RAM occupied by a process.
²: Compared when bustd was in this commit and earlyoom in this one.
bustd compiled with musl libc and earlyoom with glibc through GCC 11.1. Different configurations would likely change these figures.
Much like earlyoom and nohang, bustd uses adaptive sleep times during its memory polling. Unlike these two, however, bustd does not read from /proc/meminfo, instead opting for the sysinfo syscall.
This approach has its up- and downsides. The amount of free RAM that sysinfo reads does not account for cached memory, while MemAvailable in /proc/meminfo does.
The sysinfo syscall is one order of magnitude faster, at least according to this kernel patch (granted, from 2015).
As bustd can't solely rely on the free RAM readings of sysinfo, we check for memory stress through Pressure Stall Information.
Much like earlyoom, bustd uses mlockall to avoid being sent to swap, which allows the daemon to remain responsive even when the system memory is under heavy load and susceptible to thrashing.
The Linux kernel, since version 4.20 (and built with CONFIG_PSI=y), presents canonical new pressure metrics for memory, CPU, and IO.
In the words of Facebook Incubator:
PSI stats are like barometers that provide fair warning of impending resource
shortages, enabling you to take more proactive, granular, and nuanced steps
when resources start becoming scarce.
bustd watches the some avg10 value reported by /proc/pressure/memory. This is the percentage of recent time during which at least one task was stalled by memory pressure. Once free RAM falls to 15% or less, bustd will, by default, kill a process when the ten-second pressure average reaches 25%, i.e. when tasks have recently been stalled about a quarter of the time (the exact percentage is configurable)
Available on the Arch User Repository
Available on the GURU project
Available on the Pop!_OS PPA (outdated)
Requirements:
- Rust toolchain
- Any C compiler
- Linux 4.20+ built with
CONFIG_PSI=y
git clone https://github.com/vrmiguel/bustd
cd bustd && cargo run --releaseThe -n, --no-daemon flag is useful for running bustd through an init system such as systemd.
Binaries are generated at every commit through GitHub Actions
- Allow for customization of the critical scenario (PSI cutoff)
- Command-line argument for disabling daemonization (useful for runnning
bustdas a systemd service) - Allow the user to setup a list of software that
bustdshould never kill - Notification sending and general notification customization settings