Lightweight Linux low-memory and OOM prevention daemon written in Rust (inspired by hakavlad/nohang).
oxihang monitors RAM, swap, zram, and Linux PSI pressure before the kernel stalls under memory thrashing, terminates or runs custom corrective actions against the highest-badness process, and notifies active Wayland/X11 desktop sessions over D-Bus.
- Minimal resident footprint: ~2.1 MiB stripped LTO binary, ~2.5–4.0 MiB resident memory (
VmRSS), persistent/procfile handles, andmlockall(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)so resident pages stay locked under pressure without faulting unused virtual mappings. - Declarative configuration: Supports
@BADNESS_ADJ_RE_*,@SOFT_ACTION_RE_*,@check_kmsg,%andMthresholds, PSI, and zram rules. - Host-aware config generator:
--generate-configprobes RAM, swap, zram, PSI, ZFS ARC, and running desktop/audio sessions to emit a self-validated configuration tailored to the current machine. - Multi-signal pressure detection: Combines
MemAvailable(plus reclaimable ZFS ARC),SwapFree, zram usage (mm_stat/mem_used_total), and Linux PSI (/proc/pressure/memorywhenSwapTotal > 0) with sustained exceedance tracking. - Race-free victim signaling: Identifies victims by
(pid, starttime)and signals viapidfd_open+pidfd_send_signal(falling back to verifiedkill(2)on older kernels), escalatingSIGTERM→SIGKILLaftermax_soft_exit_time. - Kernel OOM watcher (
@check_kmsg): Non-blocking/dev/kmsgreader thread with lock-free atomics to coordinate post-OOM cooldowns and avoid duplicate kills. - Safe custom actions: Direct
argvexecution (no/bin/sh) with bounded workers, process-group isolation, and hard timeouts for@SOFT_ACTION_RE_*/post_kill_exe($PID,$NAME,$SERVICE) andwarning_exe. - Zero-dependency desktop notifications: Pure-Rust
org.freedesktop.Notifications.Notifyclient over Unix path and abstract D-Bus sockets for both Wayland and X11 (nosudo,doas,notify-send, orzbus).
- OS: Linux 3.14+ (
MemAvailablein/proc/meminfo; Linux 4.20+ for PSI, Linux 5.3+ forpidfd_open/pidfd_send_signal) - Build: Rust 1.88+ (edition 2024)
cargo install oxihanggit clone https://github.com/Unknown2077/oxihang.git
cd oxihang
cargo build --releaseThe compiled binary is placed at target/release/oxihang.
# 1. Generate a config tuned for the current machine
oxihang --generate-config -c /tmp/oxihang.conf
# 2. Inspect how current processes are scored
oxihang --tasks -c /tmp/oxihang.conf
# 3. Test monitoring safely without sending signals, commands, or notifications
oxihang --monitor --dry-run -c /tmp/oxihang.conf| Option | Description |
|---|---|
-h, --help |
Show help text and exit |
-v, --version |
Show version and exit |
-c, --config PATH |
Config file path (-c=PATH, -cPATH, --config=PATH also accepted; optional output path for --generate-config) |
--generate-config [auto|default|desktop] |
Generate a host-tuned config to stdout or -c PATH (never overwrites an existing path; --generate-config=PROFILE also accepted) |
--check |
Validate and print the parsed configuration, then exit |
--tasks |
Print the scored process table and exit |
--monitor |
Start live memory pressure monitoring |
--dry-run |
Log decisions without signaling processes, spawning commands, or sending notifications (valid only with --monitor) |
# Print an auto-detected config to stdout
oxihang --generate-config
# Write an explicit desktop config (refuses to overwrite existing paths)
oxihang --generate-config desktop -c /etc/oxihang/oxihang-desktop.conf
# Validate a configuration against current host memory/swap
oxihang --check -c /etc/oxihang/oxihang-desktop.conf
# Run the live daemon in the foreground
sudo oxihang --monitor -c /etc/oxihang/oxihang-desktop.confTwo baseline profiles are shipped under config/:
config/oxihang.conf— headless/server profile (notifications disabled by default).config/oxihang-desktop.conf— desktop/laptop profile (@check_kmsg, PSI, low-memory warnings, D-Bus notifications, and browser/Electron renderer scoring).
Running oxihang --generate-config starts from the matching profile and automatically adjusts zram_checking_enabled, psi_checking_enabled, and negative badness protection (-300) for active desktop compositors, shells, and audio daemons.
Note on zram: On systems where swap is backed primarily by zram, set
zram_checking_enabled = True(handled automatically by--generate-config) so memory exhaustion is still caught whenSwapFreeremains above its threshold.
Two mutually conflicting, hardened service units are provided in systemd/:
systemd/oxihang-desktop.service— desktop profile (preserves/tmpaccess for X11dbus-launchsockets).systemd/oxihang.service— headless/server profile (enablesPrivateTmp=true).
sudo install -Dm755 target/release/oxihang /usr/local/bin/oxihang
sudo mkdir -p /etc/oxihang
# Option A: generate a host-tuned config directly
sudo /usr/local/bin/oxihang --generate-config desktop -c /etc/oxihang/oxihang-desktop.conf
# Option B: install the shipped static configs instead
# sudo install -Dm644 config/oxihang.conf /etc/oxihang/oxihang.conf
# sudo install -Dm644 config/oxihang-desktop.conf /etc/oxihang/oxihang-desktop.conf
# Enable ONE service unit (desktop example shown; use oxihang.service on headless systems)
sudo install -Dm644 systemd/oxihang-desktop.service /etc/systemd/system/oxihang-desktop.service
sudo systemctl daemon-reload
sudo systemctl enable --now oxihang-desktop.serviceNote on
systemd-oomd: Both units setManagedOOMPreference=omitsosystemd-oomddoes not killoxihangitself. If you wantoxihangto be the sole low-memory handler, disablesystemd-oomdor tune thresholds so the two daemons do not compete.
- Privilege isolation: Systemd units apply
OOMScoreAdjust=-1000,OOMPolicy=continue,MemoryMax=64M,MemorySwapMax=0,TasksMax=64,ProtectSystem=strict,InaccessiblePaths=/home /root,MemoryDenyWriteExecute=true,RestrictNamespaces=true,DevicePolicy=closed(/dev/kmsg r), and a minimalCapabilityBoundingSet(CAP_KILL,CAP_IPC_LOCK,CAP_SYS_PTRACE,CAP_DAC_READ_SEARCH,CAP_SETUID,CAP_SETGID,CAP_SYSLOG). - Per-thread D-Bus credential drop: Notification worker threads permanently drop UID/GID/supplementary groups via raw Linux syscalls before connecting to user session buses and verify
SO_PEERCREDpeer UID ownership. - No shell injection: Custom actions tokenize and expand
$PID,$NAME, and$SERVICEdirectly intoargvwithout invoking/bin/sh.
MIT — see LICENSE.