From 795dd13474f55832916e49fd052721e40af7445c Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Sat, 14 Dec 2019 18:33:38 +0900 Subject: [PATCH] update conf and fix code style --- nohang/nohang | 458 +++++++------------------------------ nohang/nohang-desktop.conf | 16 +- nohang/nohang.conf | 16 +- tools/psi-top | 2 +- 4 files changed, 100 insertions(+), 392 deletions(-) diff --git a/nohang/nohang b/nohang/nohang index 5aa3b1b..5985036 100755 --- a/nohang/nohang +++ b/nohang/nohang @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""A daemon that prevents OOM in Linux systems.""" +"""A highly configurable OOM prevention daemon.""" import os from ctypes import CDLL @@ -11,12 +11,6 @@ from sre_constants import error as invalid_re from signal import signal, SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGHUP - -############################################################################### - -# define functions - - def exe(cmd): """ execute cmd in subprocess.Popen() """ @@ -35,7 +29,7 @@ def exe(cmd): proc.wait(timeout=exe_timeout) exit_status = proc.poll() t4 = monotonic() - log('Command ({}) execution completed in {} sec; exit status' \ + log('Command ({}) execution completed in {} sec; exit status' ': {}'.format(cmd_num, round(t4 - t3, 3), exit_status)) except TimeoutExpired: proc.kill() @@ -47,7 +41,6 @@ def exe(cmd): def start_thread(func, *a, **k): """ run function in a new thread """ - th = threading.Thread(target=func, args=a, kwargs=k, daemon=True) th_name = th.getName() @@ -55,7 +48,7 @@ def start_thread(func, *a, **k): log('Starting {} from {}'.format( th_name, threading.current_thread().getName() - )) + )) try: @@ -64,14 +57,12 @@ def start_thread(func, *a, **k): t2 = monotonic() if debug_threading: - log('{} has started in {} ms, {} threads are ' \ + log('{} has started in {} ms, {} threads are ' 'currently alive'.format(th_name, round(( t2 - t1) * 1000, 1), threading.active_count())) except RuntimeError: - log('RuntimeError: cannot start {}'.format(th_name)) - return 1 @@ -155,8 +146,6 @@ def root_notify_env(): def pop(cmd, username): """ run cmd in subprocess.Popen() """ - - cmd_num_dict['cmd_num'] += 1 cmd_num = cmd_num_dict['cmd_num'] @@ -164,8 +153,7 @@ def pop(cmd, username): cmd_num, cmd, threading.current_thread().getName() - )) - + )) if swap_total == 0: wait_time = 5 @@ -187,7 +175,8 @@ def pop(cmd, username): log('TimeoutExpired: notify user: {}'.format(username)) if debug_gui_notifications: - log('Popen time: {} sec; exit status: {}; cmd: {}'.format(round(t4 - t3, 3), err, cmd)) + log('Popen time: {} sec; exit status: {}; cmd: {}'.format( + round(t4 - t3, 3), err, cmd)) def send_notification(title, body): @@ -279,7 +268,6 @@ def send_notify_warn(): round(swap_free / (swap_total + 0.1) * 100) ) """ - start_thread(send_notification, title, body) @@ -379,36 +367,40 @@ def check_config(): log('\n5. Soft threshold') - log(' soft_threshold_min_mem: {} MiB, {} %'.format(round(soft_threshold_min_mem_mb), round(soft_threshold_min_mem_percent, 1))) + log(' soft_threshold_min_mem: {} MiB, {} %'.format( + round(soft_threshold_min_mem_mb), round( + soft_threshold_min_mem_percent, 1))) log(' soft_threshold_min_swap: {}'.format(soft_threshold_min_swap)) - log(' soft_threshold_max_zram: {} MiB, {} %'.format(round(soft_threshold_max_zram_mb), round(soft_threshold_max_zram_percent, 1))) + log(' soft_threshold_max_zram: {} MiB, {} %'.format( + round(soft_threshold_max_zram_mb), round( + soft_threshold_max_zram_percent, 1))) log(' soft_threshold_max_psi: {}'.format(soft_threshold_max_psi)) log('\n6. Hard threshold') - log(' hard_threshold_min_mem: {} MiB, {} %'.format(round(hard_threshold_min_mem_mb), round(hard_threshold_min_mem_percent, 1))) + log(' hard_threshold_min_mem: {} MiB, {} %'.format( + round(hard_threshold_min_mem_mb), round( + hard_threshold_min_mem_percent, 1))) log(' hard_threshold_min_swap: {}'.format(hard_threshold_min_swap)) - log(' hard_threshold_max_zram: {} MiB, {} %'.format(round(hard_threshold_max_zram_mb), round(hard_threshold_max_zram_percent, 1))) + log(' hard_threshold_max_zram: {} MiB, {} %'.format( + round(hard_threshold_max_zram_mb), round( + hard_threshold_max_zram_percent, 1))) log(' hard_threshold_max_psi: {}'.format(hard_threshold_max_psi)) log('\n7. Customize victim selection: adjusting badness of processes') log('\n7.1. Ignore positive oom_score_adj') - log(' ignore_positive_oom_score_adj: {}'.format(ignore_positive_oom_score_adj)) + log(' ignore_positive_oom_score_adj: {}'.format( + ignore_positive_oom_score_adj)) log('\n7.2. Forbid negative badness') - log(' forbid_negative_badness: {}'.format(forbid_negative_badness)) + log(' forbid_negative_badness: {}'.format( + forbid_negative_badness)) log('\n7.3. ') - - - - - - log('7.3.1. Matching process names with RE patterns') if len(badness_adj_re_name_list) > 0: log(' regexp: badness_adj:') @@ -441,9 +433,6 @@ def check_config(): else: log(' (not set)') - - - log('7.3.5. Matching realpath with RE patterns') if len(badness_adj_re_realpath_list) > 0: log(' regexp: badness_adj:') @@ -452,10 +441,6 @@ def check_config(): else: log(' (not set)') - - - - log('7.3.5.1. Matching cwd with RE patterns') if len(badness_adj_re_cwd_list) > 0: log(' regexp: badness_adj:') @@ -464,19 +449,6 @@ def check_config(): else: log(' (not set)') - - - - - - - - - - - - - log('7.3.6. Matching cmdlines with RE patterns') if len(badness_adj_re_cmdline_list) > 0: log(' regexp: badness_adj:') @@ -493,17 +465,6 @@ def check_config(): else: log(' (not set)') - - - - - - - - - - - log('\n8. Customize corrective actions') if len(soft_actions_list) > 0: @@ -596,7 +557,6 @@ def get_swap_threshold_tuple(string): def find_cgroup_indexes(): """ Find cgroup-line positions in /proc/*/cgroup file. """ - cgroup_v1_index = cgroup_v2_index = None with open('/proc/self/cgroup') as f: @@ -748,8 +708,6 @@ def pid_to_starttime(pid): return float(starttime) / SC_CLK_TCK - - def pid_to_nssid(pid): """ handle FNF error! """ @@ -765,17 +723,6 @@ def pid_to_nssid(pid): return nssid - - - - - - - - - - - def get_victim_id(pid): """victim_id is starttime + pid""" try: @@ -903,16 +850,6 @@ def pid_to_cwd(pid): return '' - - - - - - - - - - def pid_to_uid(pid): """return euid""" try: @@ -930,7 +867,6 @@ def pid_to_uid(pid): def pid_to_badness(pid): """Find and modify badness (if it needs).""" - try: oom_score = int(rline1('/proc/' + pid + '/oom_score')) @@ -965,18 +901,12 @@ def pid_to_badness(pid): if search(re_tup[1], realpath) is not None: badness += int(re_tup[0]) - if re_match_cwd: cwd = pid_to_cwd(pid) for re_tup in badness_adj_re_cwd_list: if search(re_tup[1], cwd) is not None: badness += int(re_tup[0]) - - - - - if re_match_cmdline: cmdline = pid_to_cmdline(pid) for re_tup in badness_adj_re_cmdline_list: @@ -1010,7 +940,6 @@ def pid_to_badness(pid): def pid_to_status(pid): """ """ - try: with open('/proc/' + pid + '/status') as f: @@ -1121,8 +1050,8 @@ def errprint(*text): def mlockall(): - """Lock all memory to prevent swapping nohang process.""" - + """ + """ MCL_CURRENT = 1 MCL_FUTURE = 2 MCL_ONFAULT = 4 @@ -1149,7 +1078,6 @@ def mlockall(): def update_stat_dict_and_print(key): """ """ - if key is not None: if key not in stat_dict: @@ -1175,7 +1103,6 @@ def update_stat_dict_and_print(key): def find_psi_metrics_value(psi_path, psi_metrics): """ """ - if psi_support: if psi_metrics == 'some_avg10': @@ -1200,7 +1127,8 @@ def find_psi_metrics_value(psi_path, psi_metrics): def check_mem_and_swap(): - """find mem_available, swap_total, swap_free""" + """ + """ with open('/proc/meminfo') as f: for n, line in enumerate(f): if n == 2: @@ -1216,7 +1144,7 @@ def check_mem_and_swap(): def check_zram(): - """find MemUsedZram""" + """Find MemUsedZram.""" disksize_sum = 0 mem_used_total_sum = 0 @@ -1243,24 +1171,9 @@ def check_zram(): return (mem_used_total_sum + disksize_sum * ZRAM_DISKSIZE_FACTOR) / 1024.0 -''' -def format_time(t): - t = int(t) - if t < 60: - return '{} sec'.format(t) - if t >= 60 and t < 3600: - m = t // 60 - s = t % 60 - return '{} min {} sec'.format(m, s) - h = t // 3600 - s0 = t - h * 3600 - m = s0 // 60 - s = s0 % 60 - return '{} h {} min {} sec'.format(h, m, s) -''' - - def format_time(t): + """ + """ t = int(t) if t < 60: @@ -1334,7 +1247,7 @@ def conf_parse_bool(param): def rline1(path): - """read 1st line from path.""" + """Read 1st line from the path.""" try: with open(path) as f: for line in f: @@ -1356,7 +1269,7 @@ def percent(num): def just_percent_mem(num): - """convert num to percent and justify""" + """Convert num to percent and justify.""" return str(round(num * 100, 1)).rjust(4, ' ') @@ -1367,7 +1280,7 @@ def just_percent_swap(num): def human(num, lenth): - """Convert KiB values to MiB values with right alignment""" + """Convert KiB values to MiB values with right alignment.""" return str(round(num / 1024)).rjust(lenth, ' ') @@ -1460,14 +1373,9 @@ def find_victim(_print_proc_table): elif extra_table_info == 'realpath': extra_table_title = 'realpath' - elif extra_table_info == 'cwd': extra_table_title = 'cwd' - - - - else: extra_table_title = '' @@ -1522,23 +1430,9 @@ def find_victim(_print_proc_table): elif extra_table_info == 'cwd': extra_table_line = pid_to_cwd(pid) - - - - else: extra_table_line = '' - - - # nssid = pid_to_nssid(pid) - # nn = pid_to_name(nssid) - # extra_table_line = '{} ({})'.format(nssid, nn) - - - - - log('#{} {} {} {} {} {} {} {} {} {} {} {}'.format( pid.rjust(7), ppid.rjust(7), @@ -1672,12 +1566,6 @@ def find_victim_info(pid, victim_badness, name): if i is state_index: state = f_list[i].split('\t')[1].rstrip() - """ - if i is ppid_index: - pass - # ppid = f_list[i].split('\t')[1] - """ - if i is uid_index: uid = f_list[i].split('\t')[2] @@ -1838,7 +1726,8 @@ def check_mem_swap_ex(): warning_threshold_min_swap_kb = swap_total * \ warning_threshold_min_swap_percent / 100.0 else: - warning_threshold_min_swap_kb = swap_kb_dict['warning_threshold_min_swap_kb'] + warning_threshold_min_swap_kb = swap_kb_dict[ + 'warning_threshold_min_swap_kb'] if swap_total > hard_threshold_min_swap_kb: swap_sigkill_pc = percent( @@ -1855,7 +1744,10 @@ def check_mem_swap_ex(): if (mem_available <= hard_threshold_min_mem_kb and swap_free <= hard_threshold_min_swap_kb): - mem_info = 'Memory status that requires corrective actions:\n MemAvailable [{} MiB, {} %] <= hard_threshold_min_mem [{} MiB, {} %]\n SwapFree [{} MiB, {} %] <= hard_threshold_min_swap [{} MiB, {} %]'.format( + mem_info = 'Memory status that requires corrective actions:\n Mem' \ + 'Available [{} MiB, {} %] <= hard_threshold_min_mem [{} MiB' \ + ', {} %]\n SwapFree [{} MiB, {} %] <= hard_threshold_m' \ + 'in_swap [{} MiB, {} %]'.format( kib_to_mib(mem_available), percent(mem_available / mem_total), @@ -1869,12 +1761,13 @@ def check_mem_swap_ex(): return (SIGKILL, mem_info, mem_available, hard_threshold_min_swap_kb, soft_threshold_min_swap_kb, swap_free, swap_total) - - if (mem_available <= soft_threshold_min_mem_kb and swap_free <= soft_threshold_min_swap_kb): - mem_info = 'Memory status that requires corrective actions:\n MemAvailable [{} MiB, {} %] <= soft_threshold_min_mem [{} MiB, {} %]\n SwapFree [{} MiB, {} %] <= soft_threshold_min_swap [{} MiB, {} %]'.format( + mem_info = 'Memory status that requires corrective actions:\n M' \ + 'emAvailable [{} MiB, {} %] <= soft_threshold_min_mem [{} MiB,' \ + ' {} %]\n SwapFree [{} MiB, {} %] <= soft_threshold_min_swa' \ + 'p [{} MiB, {} %]'.format( kib_to_mib(mem_available), percent(mem_available / mem_total), @@ -1888,7 +1781,6 @@ def check_mem_swap_ex(): return (SIGTERM, mem_info, mem_available, hard_threshold_min_swap_kb, soft_threshold_min_swap_kb, swap_free, swap_total) - if low_memory_warnings_enabled: if (mem_available <= warning_threshold_min_mem_kb and swap_free <= @@ -1907,7 +1799,9 @@ def check_zram_ex(): if mem_used_zram >= hard_threshold_max_zram_kb: - mem_info = 'Memory status that requires corrective actions:\n MemUsedZram [{} MiB, {} %] >= hard_threshold_max_zram [{} MiB, {} %]'.format( + mem_info = 'Memory status that requires corrective actions:\n Mem' \ + 'UsedZram [{} MiB, {} %] >= hard_threshold_max_zram [{} MiB' \ + ', {} %]'.format( kib_to_mib(mem_used_zram), percent(mem_used_zram / mem_total), @@ -1916,10 +1810,11 @@ def check_zram_ex(): return SIGKILL, mem_info, mem_used_zram - if mem_used_zram >= soft_threshold_max_zram_kb: - mem_info = 'Memory status that requires corrective actions:\n MemUsedZram [{} MiB, {} %] >= soft_threshold_max_zram [{} M, {} %]'.format( + mem_info = 'Memory status that requires corrective actions:\n ' \ + 'MemUsedZram [{} MiB, {} %] >= soft_threshold_max_zram [{}' \ + ' M, {} %]'.format( kib_to_mib(mem_used_zram), percent(mem_used_zram / mem_total), kib_to_mib(soft_threshold_max_zram_kb), @@ -1942,7 +1837,6 @@ def check_psi_ex(psi_t0, psi_kill_exceeded_timer, psi_term_exceeded_timer, x0): x0 = monotonic() psi_avg_value = find_psi_metrics_value(psi_path, psi_metrics) - # print(psi_avg_value) psi_post_action_delay_timer = monotonic() - last_action_dict['t'] # psi_t0 @@ -2031,29 +1925,16 @@ def is_victim_alive(victim_id): """ We do not have a reliable sign of the end of the release of memory: https://github.com/rfjakob/earlyoom/issues/128#issuecomment-507023717 - - Варианты возврата: - 0 X, nonexist, другой процесс (полн конец имплементации, можно не делать POST SIGKILL DELAY) - 1 rp true - 2 R освобождает память. Ждем смерти. - 3 Z возможно уже освободил память. Конец отслеживания """ - - # Проверка целостности жертвы starttime, pid = victim_id.split('_pid') new_victim_id = get_victim_id(pid) if victim_id != new_victim_id: return 0 - # Жива ли жертва? exe_exists = os.path.exists('/proc/{}/exe'.format(pid)) if exe_exists: return 1 - # далее жертва смертельно ранена. Дифференцируемся по State. - # R -> 2 # отслеживать жертву дальше - # X, FNFE, PLE -> 0 - state = pid_to_state(pid) if state == 'R': @@ -2068,20 +1949,6 @@ def is_victim_alive(victim_id): return 0 - - - - - - - - - - - - - - def implement_corrective_action( threshold, mem_info_list, @@ -2093,35 +1960,20 @@ def implement_corrective_action( zram_threshold, zram_info, psi_info): - """ - Great and terrible function. - """ - log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') + log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' + '>>>>>>>>>>>>>>') debug_corrective_action = True time0 = monotonic() - # 1. Очистка словаря от мертвых. Итерация по словарю, отслеживание умирающих. - # 2. Итерация по оставшемуся словарю. Поиск дельт. Если хоть у одного - # дельта НЕ истекла - ЖДЕМ, выход из фции. - - # print(v_dict) nu = [] for victim_id in v_dict: iva = is_victim_alive(victim_id) - #print(iva, victim_id) if iva == 0 or iva == 3: nu.append(victim_id) - """ - continue - if iva == 1: - continue - if iva == 2: - pass # быстро отследить умирающего - """ for i in nu: if debug_corrective_action: @@ -2130,10 +1982,6 @@ def implement_corrective_action( x = False cache_list = [] - #cache_list.append(('foo', 0.01)) - #cache_list.append(('boo', 1111.01)) - # 2 - # print(v_dict) for victim_id in v_dict: tx = v_dict[victim_id]['time'] @@ -2141,17 +1989,13 @@ def implement_corrective_action( if ddt < victim_cache_time: if debug_corrective_action: - log( - 'victim_cache_time is not exceeded for {} ({} < {})'.format( - victim_id, round(ddt, 3), victim_cache_time - ) - ) + log('victim_cache_time is not exceeded for {} ({} <' + ' {})'.format(victim_id, round(ddt, 3), victim_cache_time)) x = True cache_list.append((victim_id, ddt)) break if x: - # print(cache_list) e = sorted(cache_list, key=itemgetter(1), reverse=False) cached_victim_id = e[0][0] @@ -2243,14 +2087,12 @@ def implement_corrective_action( log('Sleep {} sec (over_sleep)'.format(over_sleep)) sleep(over_sleep) - log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<') + log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<' + '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<') return psi_t0 - # log('Try to implement a corrective action...') - if print_victim_status: - # victim badness ищи снова, не полагайся на старое victim_info = find_victim_info(pid, victim_badness, name) log(victim_info) @@ -2283,13 +2125,6 @@ def implement_corrective_action( pid)).replace('$SERVICE', service) start_thread(exe, cmd) - """ - if exit_status == 0: - success = True - else: - success = False - """ - response_time = monotonic() - time0 exit_status = None @@ -2316,23 +2151,15 @@ def implement_corrective_action( '\n Send {} to the victim; {}'.format( sig_dict[threshold], send_result) - # success = True - if threshold is SIGKILL: vwd = True except FileNotFoundError: vwd = True - # success = False - # response_time = monotonic() - time0 - # send_result = 'no such process; response time: {} ms'.format(round(response_time * 1000)) key = 'The victim died in the search process: ' \ 'FileNotFoundError' except ProcessLookupError: vwd = True - # success = False - # response_time = monotonic() - time0 - # send_result = 'no such process; response time: {} ms'.format(round(response_time * 1000)) key = 'The victim died in the search process: ' \ 'ProcessLookupError' @@ -2340,7 +2167,6 @@ def implement_corrective_action( log(preventing_oom_message) except UnboundLocalError: pass - # preventing_oom_message = key if not vwd: if victim_id not in v_dict: @@ -2352,25 +2178,9 @@ def implement_corrective_action( last_action_dict['t'] = kill_timestamp = monotonic() - # print(v_dict) - - # response_time = monotonic() - time0 - - # log('success: ' + str(success)) - # log('victim will die: ' + str(vwd)) - # log('response_time: ' + str(response_time) + ' sec') - - # НАЧАЛО ОТСЛЕЖИВАНИЯ СОСТОЯНИЯ ЖЕРТВЫ. Можно вынести в отд фц. Приним - # айди, логирует, возвращает что-то. - - # Далее поработать со словарями. Жертва тут умерла - сброс таймера. Все - # старые жертвы умерли до 3х секунд с следующих циклах - сброс таймера. - # После этого все должно быть супер охуенно. - while True: sleep(0.01) d = monotonic() - kill_timestamp - #print('Прошло времени:', d) iva = is_victim_alive(victim_id) if iva == 0: @@ -2382,22 +2192,23 @@ def implement_corrective_action( break elif iva == 1: - #print('Жива и занимает память') if vwd and d > sensitivity_test_time + 10: - log("The victim doesn't respond on corrective action in {} sec".format(round(d, 3))) + log("The victim doesn't respond on corrective action' \ + ' in {} sec".format( + round(d, 3))) break if not vwd and d > sensitivity_test_time: - log("The victim doesn't respond on corrective action in {} sec".format(round(d, 3))) + log("The victim doesn't respond on corrective actio' \ + 'n in {} sec".format( + round(d, 3))) break elif iva == 2: pass - #print('Смертельно ранена и освобождает память. Дождаться окончания освобождения памяти.') - else: # 3 - #print('Z и быстро освобождает память, если еще не. Поспать немножно и выйти из цикла.') + else: log('The victim became a zombie in {} sec'.format(round(d, 3))) @@ -2457,31 +2268,14 @@ def implement_corrective_action( log('Sleep {} sec (over_sleep)'.format(over_sleep)) sleep(over_sleep) - log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<') + log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<' + '<<<<<<<<<<<<<<<<<') return psi_t0 - - - - - - - - - - - - - - - - - def sleep_after_check_mem(): """Specify sleep times depends on rates and avialable memory.""" - if stable_sleep: if debug_sleep: @@ -2572,8 +2366,8 @@ def calculate_percent(arg_key): 'ge [0; 100]\nExit'.format(arg_key)) exit(1) - # soft_threshold_min_mem_percent is clean and valid float percentage. Can - # translate into Kb + # soft_threshold_min_mem_percent is clean and valid float + # percentage. Can translate into Kb mem_min_kb = mem_min_percent / 100 * mem_total mem_min_mb = round(mem_min_kb / 1024) @@ -2794,15 +2588,12 @@ badness_adj_re_realpath_list = [] badness_adj_re_cwd_list = [] - - - soft_actions_list = [] # separator for optional parameters (that starts with @) opt_separator = '///' -# stupid conf parsing, need refactoring +# stupid conf parsing, it needs refactoring try: with open(config) as f: @@ -2908,8 +2699,6 @@ try: valid_re(reg_exp) badness_adj_re_realpath_list.append((badness_adj, reg_exp)) - - if line.startswith('@BADNESS_ADJ_RE_CWD'): a = line.partition('@BADNESS_ADJ_RE_CWD')[2].strip( ' \n').partition(opt_separator) @@ -2918,18 +2707,6 @@ try: valid_re(reg_exp) badness_adj_re_cwd_list.append((badness_adj, reg_exp)) - - - - - - - - - - - - if line.startswith('@BADNESS_ADJ_RE_ENVIRON'): a = line.partition('@BADNESS_ADJ_RE_ENVIRON')[2].strip( ' \n').partition(opt_separator) @@ -2986,21 +2763,12 @@ else: re_match_realpath = True - - if badness_adj_re_cwd_list == []: re_match_cwd = False else: re_match_cwd = True - - - - - - - if badness_adj_re_cgroup_v1_list == []: re_match_cgroup_v1 = False else: @@ -3022,10 +2790,6 @@ else: ############################################################################### - - - - # extracting parameters from the dictionary # check for all necessary parameters # validation of all parameters @@ -3042,26 +2806,13 @@ debug_sleep = conf_parse_bool('debug_sleep') hide_corrective_action_type = conf_parse_bool('hide_corrective_action_type') - - low_memory_warnings_enabled = conf_parse_bool('low_memory_warnings_enabled') - - - - - - - - - post_action_gui_notifications = conf_parse_bool( 'post_action_gui_notifications') - - debug_threading = conf_parse_bool('debug_threading') @@ -3084,16 +2835,20 @@ ignore_positive_oom_score_adj = conf_parse_bool( hard_threshold_min_mem_percent) = calculate_percent('hard_threshold_min_mem') (soft_threshold_max_zram_kb, soft_threshold_max_zram_mb, - soft_threshold_max_zram_percent) = calculate_percent('soft_threshold_max_zram') + soft_threshold_max_zram_percent) = calculate_percent( + 'soft_threshold_max_zram') (hard_threshold_max_zram_kb, hard_threshold_max_zram_mb, - hard_threshold_max_zram_percent) = calculate_percent('hard_threshold_max_zram') + hard_threshold_max_zram_percent) = calculate_percent( + 'hard_threshold_max_zram') (warning_threshold_min_mem_kb, warning_threshold_min_mem_mb, - warning_threshold_min_mem_percent) = calculate_percent('warning_threshold_min_mem') + warning_threshold_min_mem_percent) = calculate_percent( + 'warning_threshold_min_mem') (warning_threshold_max_zram_kb, warning_threshold_max_zram_mb, - warning_threshold_max_zram_percent) = calculate_percent('warning_threshold_max_zram') + warning_threshold_max_zram_percent) = calculate_percent( + 'warning_threshold_max_zram') if 'post_zombie_delay' in config_dict: @@ -3138,10 +2893,6 @@ else: exit(1) - - - - if 'exe_timeout' in config_dict: exe_timeout = string_to_float_convert_test( config_dict['exe_timeout']) @@ -3156,10 +2907,6 @@ else: exit(1) - - - - if 'fill_rate_mem' in config_dict: fill_rate_mem = string_to_float_convert_test(config_dict['fill_rate_mem']) if fill_rate_mem is None: @@ -3433,10 +3180,6 @@ if separate_log: errprint('ERROR: permission denied: {}'.format(logfile)) - - - - if 'min_mem_report_interval' in config_dict: min_mem_report_interval = string_to_float_convert_test( config_dict['min_mem_report_interval']) @@ -3535,33 +3278,20 @@ if print_proc_table_flag: func_print_proc_table() - - - -########################################################################## - - - - -if (low_memory_warnings_enabled or \ - post_action_gui_notifications or \ - check_warning_exe or \ - soft_actions or \ - post_kill_exe != ''): +if (low_memory_warnings_enabled or + post_action_gui_notifications or + check_warning_exe or + soft_actions or + post_kill_exe != ''): import threading import shlex from subprocess import Popen, TimeoutExpired - - - psi_support = os.path.exists(psi_path) -########################################################################## - # Get KiB levels if it's possible. soft_threshold_min_swap_tuple = get_swap_threshold_tuple( @@ -3594,19 +3324,14 @@ if swap_warn_is_percent: warning_threshold_min_swap_percent = warning_threshold_min_swap_tuple[0] else: warning_threshold_min_swap_kb = warning_threshold_min_swap_tuple[0] - swap_kb_dict['warning_threshold_min_swap_kb'] = warning_threshold_min_swap_kb - - -########################################################################## + swap_kb_dict[ + 'warning_threshold_min_swap_kb'] = warning_threshold_min_swap_kb if print_config_at_startup or check_config_flag: check_config() -########################################################################## - - # for calculating the column width when printing mem and zram mem_len = len(str(round(mem_total / 1024.0))) @@ -3622,26 +3347,17 @@ fill_rate_zram = fill_rate_zram * 1024 warn_time_now = 0 -warn_time_delta = 1000 # ? +warn_time_delta = 1000 # ? warn_timer = 0 -########################################################################## - - if not root: log('WARNING: effective UID != 0; euid={}; processes with other e' 'uids will be invisible for nohang'.format(self_uid)) -# Try to lock all memory - mlockall() -########################################################################## - - -# print_self_rss() psi_avg_string = '' # will be overwritten if PSI monitoring enabled @@ -3696,18 +3412,10 @@ envd = dict() envd['list_with_envs'] = envd['t'] = None - - cmd_num_dict = dict() cmd_num_dict['cmd_num'] = 0 - - - -########################################################################## - - while True: (masf_threshold, masf_info, mem_available, hard_threshold_min_swap_kb, diff --git a/nohang/nohang-desktop.conf b/nohang/nohang-desktop.conf index db79e7c..5f5cb70 100644 --- a/nohang/nohang-desktop.conf +++ b/nohang/nohang-desktop.conf @@ -88,7 +88,7 @@ fill_rate_swap = 1500 Type: float Valid values: -fill_rate_zram = 6000 +fill_rate_zram = 4000 Description: Type: float @@ -150,7 +150,7 @@ warning_threshold_min_mem = 20 % Type: float (+ % or M) Valid values: -warning_threshold_min_swap = 20 % +warning_threshold_min_swap = 25 % Description: Type: float (+ % or M) @@ -184,13 +184,13 @@ env_cache_time = 300 Type: float (+ % or M) Valid values: -soft_threshold_min_mem = 8 % +soft_threshold_min_mem = 6 % Description: Type: float (+ % or M) Valid values: -soft_threshold_min_swap = 8 % +soft_threshold_min_swap = 9 % Description: Type: float (+ % or M) @@ -208,13 +208,13 @@ soft_threshold_max_psi = 60 6. Hard threshold -hard_threshold_min_mem = 4 % +hard_threshold_min_mem = 2 % Description: Type: float (+ % or M) Valid values: -hard_threshold_min_swap = 4 % +hard_threshold_min_swap = 3 % Description: Type: float (+ % or M) @@ -226,7 +226,7 @@ hard_threshold_max_zram = 65 % Type: float Valid values: -hard_threshold_max_psi = 90 +hard_threshold_max_psi = 80 ############################################################################### @@ -350,7 +350,7 @@ post_kill_exe = Type: integer Valid values: -min_badness = 10 +min_badness = 5 Description: Type: float diff --git a/nohang/nohang.conf b/nohang/nohang.conf index 62fd2ca..cab089c 100644 --- a/nohang/nohang.conf +++ b/nohang/nohang.conf @@ -88,7 +88,7 @@ fill_rate_swap = 1500 Type: float Valid values: -fill_rate_zram = 6000 +fill_rate_zram = 4000 Description: Type: float @@ -150,7 +150,7 @@ warning_threshold_min_mem = 20 % Type: float (+ % or M) Valid values: -warning_threshold_min_swap = 20 % +warning_threshold_min_swap = 25 % Description: Type: float (+ % or M) @@ -184,13 +184,13 @@ env_cache_time = 300 Type: float (+ % or M) Valid values: -soft_threshold_min_mem = 8 % +soft_threshold_min_mem = 6 % Description: Type: float (+ % or M) Valid values: -soft_threshold_min_swap = 8 % +soft_threshold_min_swap = 9 % Description: Type: float (+ % or M) @@ -208,13 +208,13 @@ soft_threshold_max_psi = 60 6. Hard threshold -hard_threshold_min_mem = 4 % +hard_threshold_min_mem = 2 % Description: Type: float (+ % or M) Valid values: -hard_threshold_min_swap = 4 % +hard_threshold_min_swap = 3 % Description: Type: float (+ % or M) @@ -226,7 +226,7 @@ hard_threshold_max_zram = 65 % Type: float Valid values: -hard_threshold_max_psi = 90 +hard_threshold_max_psi = 80 ############################################################################### @@ -350,7 +350,7 @@ post_kill_exe = Type: integer Valid values: -min_badness = 10 +min_badness = 5 Description: Type: float diff --git a/tools/psi-top b/tools/psi-top index 1a510e7..5216ada 100755 --- a/tools/psi-top +++ b/tools/psi-top @@ -13,7 +13,7 @@ def psi_path_to_metrics(psi_path): psi_list = f.readlines() # print(psi_list) some_list, full_list = psi_list[0].split(' '), psi_list[1].split(' ') - #print(some_list, full_list) + # print(some_list, full_list) some_avg10 = some_list[1].split('=')[1] some_avg60 = some_list[2].split('=')[1] some_avg300 = some_list[3].split('=')[1]