Nohang is a highly configurable daemon for Linux which is able to correctly prevent out of memory (OOM) and keep system responsiveness in low memory conditions.
What is the problem?
OOM conditions may cause freezes, livelocks, drop caches and processes to be killed (via sending SIGKILL) instead of trying to terminate them correctly (via sending SIGTERM or takes other corrective action). Some applications may crash if it's impossible to allocate memory.
Here are the statements of some users:
"How do I prevent Linux from freezing when out of memory? Today I (accidentally) ran some program on my Linux box that quickly used a lot of memory. My system froze, became unresponsive and thus I was unable to kill the offender. How can I prevent this in the future? Can't it at least keep a responsive core or something running?"
"With or without swap it still freezes before the OOM killer gets run automatically. This is really a kernel bug that should be fixed (i.e. run OOM killer earlier, before dropping all disk cache). Unfortunately kernel developers and a lot of other folk fail to see the problem. Common suggestions such as disable/enable swap, buy more RAM, run less processes, set limits etc. do not address the underlying problem that the kernel's low memory handling sucks camel's balls."
Also look at Why are low memory conditions handled so badly? (discussion with 480+ posts on r/linux).
- Use of earlyoom. This is a simple and lightweight OOM preventer written in C.
- Use of oomd. This is a userspace OOM killer for linux systems whitten in C++ and developed by Facebook.
- Use of nohang.
SIGTERMas signals that can be sent to the victim
- impact on the badness of processes via matching their names with regular expressions
- possibility of restarting processes via command like
systemctl restart somethingif the process is selected as a victim
- GUI notifications: OOM prevention results and low memory warnings
mem_used_totalas a trigger)
- customizable intensity of monitoring
- convenient configuration with a well commented config file
Video: nohang prevents OOM after the command
while true; do tail /dev/zero; done has been executed.
For basic usage:
To show GUI notifications:
libnotify(Fedora, Arch Linux) or
libnotify-bin(Debian GNU/Linux, Ubuntu)
procpsif nohang is started as root
Memory and CPU usage
- VmRSS is 10 — 14 MiB depending on the settings (about 10 MiB by default)
- CPU usage depends on the level of available memory (the frequency of memory status checks increases as the amount of available memory decreases) and monitoring intensity (can be changed by the user via the config)
The program is unstable and some fixes are required before the first stable version will be released (need documentation, translation, review and some optimisation).
Download, install, uninstall
$ git clone https://github.com/hakavlad/nohang.git $ cd nohang
$ sudo make install
To enable and start on systems with systemd:
$ sudo make systemd
$ sudo make uninstall
Command line options
./nohang -h usage: nohang [-h] [-c CONFIG] optional arguments: -h, --help show this help message and exit -c CONFIG, --config CONFIG path to the config file, default values: ./nohang.conf, /etc/nohang/nohang.conf
How to configure nohang
The program can be configured by editing the config file. The configuration includes the following sections:
- Memory levels to respond to as an OOM threat
- The frequency of checking the level of available memory (and CPU usage)
- The prevention of killing innocent victims
- Impact on the badness of processes via matching their names with regular expressions
- The execution of a specific command instead of sending the SIGTERM signal
- GUI notifications:
- results of preventing OOM
- low memory warnings
- Preventing the slowing down of the program
- Output verbosity
Just read the description of the parameters and edit the values. Please restart nohang to apply changes. Default path to the config after installing is
If nohang is installed on a system that uses systemd, you can use the following command to view the log:
$ sudo journalctl -eu nohang
Please create issues. Use cases, feature requests and any questions are welcome.