diff --git a/nohang/nohang b/nohang/nohang index 227db14..3d16e0d 100755 --- a/nohang/nohang +++ b/nohang/nohang @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""A highly configurable OOM prevention daemon.""" +"""A sophisticated low memory handler.""" import os from ctypes import CDLL @@ -665,6 +665,22 @@ def print_version(): exit() +def psi_file_mem_to_metrics(psi_path): + """ + """ + with open(psi_path) as f: + psi_list = f.readlines() + some_list, full_list = psi_list[0].split(' '), psi_list[1].split(' ') + some_avg10 = some_list[1].split('=')[1] + some_avg60 = some_list[2].split('=')[1] + some_avg300 = some_list[3].split('=')[1] + full_avg10 = full_list[1].split('=')[1] + full_avg60 = full_list[2].split('=')[1] + full_avg300 = full_list[3].split('=')[1] + return (some_avg10, some_avg60, some_avg300, + full_avg10, full_avg60, full_avg300) + + def pid_to_cgroup_v1(pid): """ """ @@ -2881,8 +2897,21 @@ debug_threading = conf_parse_bool('debug_threading') psi_checking_enabled = conf_parse_bool('psi_checking_enabled') + + ignore_psi = not psi_checking_enabled + +if psi_checking_enabled: + + try: + psi_file_mem_to_metrics('/proc/pressure/memory') + except Exception as e: + print('WARNING: PSI metrics are not provided by the kernel: {}'.format( + e)) + ignore_psi = True + + zram_checking_enabled = conf_parse_bool('zram_checking_enabled') ignore_zram = not zram_checking_enabled @@ -3171,6 +3200,15 @@ else: if 'psi_path' in config_dict: psi_path = config_dict['psi_path'] + if not ignore_psi: + try: + psi_file_mem_to_metrics(psi_path) + except Exception as e: + print('WARNING: invalid psi_path "{}": {}'.format( + psi_path, e)) + ignore_psi = True + + else: errprint('psi_path is not in config\nExit') exit(1) diff --git a/tools/psi-top b/tools/psi-top index 5216ada..7502982 100755 --- a/tools/psi-top +++ b/tools/psi-top @@ -73,8 +73,12 @@ else: psi_support = os.path.exists(psi_path) -if not psi_support: - print('PSI is not supported, /proc/pressure/memory does not exist. Exit.') + +try: + psi_path_to_metrics(psi_path) +except Exception as e: + print('ERROR: {}'.format(e)) + print('PSI metrics are not provided by the kernel. Exit.') exit(1) diff --git a/tools/psi2log b/tools/psi2log index 321da05..f78470d 100755 --- a/tools/psi2log +++ b/tools/psi2log @@ -193,9 +193,12 @@ if log_file is not None: log('log file: {}'.format(log_file)) -if not os.path.exists('/proc/pressure'): - log('ERROR: /proc/pressure does not exist, PSI is not supported, exit') - exit() +try: + psi_file_mem_to_metrics('/proc/pressure/memory') +except Exception as e: + print('ERROR: {}'.format(e)) + print('PSI metrics are not provided by the kernel. Exit.') + exit(1) if target == 'SYSTEM_WIDE':