fix readme

This commit is contained in:
Alexey Avramov 2019-02-12 00:42:00 +09:00
parent a1e7b25ad0
commit 24c928aea2
2 changed files with 17 additions and 8 deletions

View File

@ -3,12 +3,12 @@
Nohang is a highly configurable daemon for Linux which is able to correctly prevent [out of memory](https://en.wikipedia.org/wiki/Out_of_memory) (OOM) and keep system responsiveness in low memory conditions. Nohang is a highly configurable daemon for Linux which is able to correctly prevent [out of memory](https://en.wikipedia.org/wiki/Out_of_memory) (OOM) and keep system responsiveness in low memory conditions.
![pic](https://i.imgur.com/Hq1JPMs.png)
## What is the problem? ## What is the problem?
OOM conditions may cause [freezes](https://en.wikipedia.org/wiki/Hang_(computing)), [livelocks](https://en.wikipedia.org/wiki/Deadlock#Livelock), drop [caches](https://en.wikipedia.org/wiki/Page_cache) and processes to be killed (via sending [SIGKILL](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL)) instead of trying to terminate them correctly (via sending [SIGTERM](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGTERM) or takes other corrective action). Some applications may crash if it's impossible to allocate memory. OOM conditions may cause [freezes](https://en.wikipedia.org/wiki/Hang_(computing)), [livelocks](https://en.wikipedia.org/wiki/Deadlock#Livelock), drop [caches](https://en.wikipedia.org/wiki/Page_cache) and processes to be killed (via sending [SIGKILL](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL)) instead of trying to terminate them correctly (via sending [SIGTERM](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGTERM) or takes other corrective action). Some applications may crash if it's impossible to allocate memory.
![pic](https://i.imgur.com/yS81KAY.png)
Here are the statements of some users: Here are the statements of some users:
> "How do I prevent Linux from freezing when out of memory? > "How do I prevent Linux from freezing when out of memory?
@ -27,7 +27,10 @@ Also look at [Why are low memory conditions handled so badly?](https://www.reddi
- Use of [earlyoom](https://github.com/rfjakob/earlyoom). This is a simple and very lightweight OOM preventer written in C (the best choice for emedded and old servers). It has a minimum dependencies and can work with oldest kernels. - Use of [earlyoom](https://github.com/rfjakob/earlyoom). This is a simple and very lightweight OOM preventer written in C (the best choice for emedded and old servers). It has a minimum dependencies and can work with oldest kernels.
- Use of [oomd](https://github.com/facebookincubator/oomd). This is a userspace OOM killer for linux systems whitten in C++ and developed by Facebook. Needs Linux 4.20+. - Use of [oomd](https://github.com/facebookincubator/oomd). This is a userspace OOM killer for linux systems whitten in C++ and developed by Facebook. Needs Linux 4.20+.
- Use of nohang (maybe this is a good choice for modern desktops and servers if you need fine tuning). - Use of `nohang` (maybe this is a good choice for modern desktops and servers if you need fine tuning).
![pic](https://i.imgur.com/Hq1JPMs.png)
The tools listed above may work at the same time on one computer. The tools listed above may work at the same time on one computer.
@ -211,6 +214,7 @@ Please create [issues](https://github.com/hakavlad/nohang/issues). Use cases, fe
- Add the ability to send any signal instead of SIGTERM for processes with certain names - Add the ability to send any signal instead of SIGTERM for processes with certain names
- Handle `UnicodeDecodeError` if victim name consists of many unicode characters - Handle `UnicodeDecodeError` if victim name consists of many unicode characters
- Improve user input validation - Improve user input validation
- Fix `mlockall()` using `MCL_ONFAULT` and lock all memory by default
- [v0.1](https://github.com/hakavlad/nohang/releases/tag/v0.1), 2018-11-23 - [v0.1](https://github.com/hakavlad/nohang/releases/tag/v0.1), 2018-11-23
- 1st release - 1st release

15
nohang
View File

@ -427,7 +427,7 @@ def send_notify_etc(pid, name, command):
pid: str process pid pid: str process pid
""" """
title = 'Hang prevention' title = 'Hang prevention'
body = 'Victim is process <b>{}</b> [{}]\nExecute the command:\n<b>{}</b>'.format( body = 'Victim is process <b>{}</b>, {}\nExecute the command:\n<b>{}</b>'.format(
name.replace('&', '*'), name.replace('&', '*'),
pid, pid,
command.replace('&', '*') command.replace('&', '*')
@ -691,8 +691,12 @@ def find_victim_and_send_signal(signal):
len_vm = len(str(vm_size)) len_vm = len(str(vm_size))
try:
realpath = os.path.realpath('/proc/' + pid + '/exe')
except FileNotFoundError:
print('Victim died: /proc/{}/exe does not exists'.format(pid))
realpath = os.path.realpath('/proc/' + pid + '/exe')
state = pid_to_state(pid) state = pid_to_state(pid)
pname = pid_to_name(ppid.strip('\n ')) pname = pid_to_name(ppid.strip('\n '))
# print([ppid], [pname]) # print([ppid], [pname])
@ -736,10 +740,9 @@ def find_victim_and_send_signal(signal):
cmdline cmdline
) )
else: else:
# нахер такое ветвление # нахер такое ветвление
victim_info = '\033[4mFound a process with highest badness:\033[0m' \ victim_info = '\033[4mFound a process with highest badness:\033[0m' \
'\n Name: \033[33m{}\033[0m' \ '\n Name: \033[33m{}\033[0m' \
'\n PID: \033[33m{}\033[0m' \ '\n PID: \033[33m{}\033[0m' \
@ -958,11 +961,13 @@ def calculate_percent(arg_key):
########################################################################## ##########################################################################
# Lock all memory
mlockall() mlockall()
##########################################################################
# find mem_total # find mem_total