From 158404867fab5bf8431939df66fdfc362493dc36 Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Wed, 12 Dec 2018 02:29:35 +0900 Subject: [PATCH] display VmSize of victim in reports --- README.md | 4 ++-- nohang | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 10155d8..963562c 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ The program can be configured by editing the [config file](https://github.com/ha 1. Memory levels to respond to as an OOM threat 2. The frequency of checking the level of available memory (and CPU usage) 3. The prevention of killing innocent victims -4. Impact on the badness of processes via matching their names and cmdlines with regular expressions +4. Impact on the badness of processes via matching their names, cmdlines and UIDs with regular expressions 5. The execution of a specific command instead of sending the SIGTERM signal 6. GUI notifications: - results of preventing OOM @@ -190,7 +190,7 @@ Please create [issues](https://github.com/hakavlad/nohang/issues). Use cases, fe - Fix: replace `re.fullmatch()` by `re.search()` - Validation RE patterns at startup - Improve output: - - Display `UID`, `RssAnon`, `RssFile`, `RssShmem` and `cmdline` of the victim in corrective action reports + - Display `UID`, `VmSize`, `RssAnon`, `RssFile`, `RssShmem` and `cmdline` of the victim in corrective action reports - Print in terminal with colors - Optimize limiting `oom_score_adj`: now it can works without UID=0 - Optimize GUI warnings: find env without run `ps` and `env` (partially implemented) diff --git a/nohang b/nohang index 9ef4fb1..c4b47cc 100755 --- a/nohang +++ b/nohang @@ -422,6 +422,11 @@ def find_victim_and_send_signal(signal): uid = line.split('\t')[1] continue + + if n is vm_size_index: + vm_size = kib_to_mib(int(line.split('\t')[1][:-4])) + continue + if n is vm_rss_index: vm_rss = kib_to_mib(int(line.split('\t')[1][:-4])) continue @@ -477,12 +482,13 @@ def find_victim_and_send_signal(signal): '\n PID: \033[33m{}\033[0m' \ '\n UID: \033[33m{}\033[0m' \ '\n Badness: \033[33m{}\033[0m' \ + '\n VmSize: \033[33m{}\033[0m MiB' \ '\n VmRSS: \033[33m{}\033[0m MiB' \ '\n VmSwap: \033[33m{}\033[0m MiB' \ '\n CmdLine: \033[33m{}\033[0m' \ '\n Execute the command: \033[4m{}\033[0m' \ '\n Exit status: {}; response time: {} ms'.format( - name, pid, uid, victim_badness, vm_rss, vm_swap, + name, pid, uid, victim_badness, vm_size, vm_rss, vm_swap, cmdline, command, exit_status, round(response_time * 1000)) @@ -516,11 +522,12 @@ def find_victim_and_send_signal(signal): '\n PID: \033[33m{}\033[0m' \ '\n UID: \033[33m{}\033[0m' \ '\n Badness: \033[33m{}\033[0m' \ + '\n VmSize: \033[33m{}\033[0m MiB' \ '\n VmRSS: \033[33m{}\033[0m MiB' \ '\n VmSwap: \033[33m{}\033[0m MiB' \ '\n CmdLine: \033[33m{}\033[0m' \ '\n Sending \033[4m{}\033[0m to the victim; {}'.format( - name, pid, uid, victim_badness, vm_rss, vm_swap, + name, pid, uid, victim_badness, vm_size, vm_rss, vm_swap, cmdline, sig_dict[signal], send_result) print(mem_info) print(preventing_oom_message) @@ -704,6 +711,7 @@ status_names = [] for s in status_list: status_names.append(s.split(':')[0]) +vm_size_index = status_names.index('VmSize') vm_rss_index = status_names.index('VmRSS') vm_swap_index = status_names.index('VmSwap') uid_index = status_names.index('Uid')