From aa7ad46aed767dbd85ddc249f882cbca0c2301aa Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Wed, 2 Jan 2019 05:08:45 +0900 Subject: [PATCH] fix psi support --- nohang | 64 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/nohang b/nohang index 6b1658d..89832a6 100755 --- a/nohang +++ b/nohang @@ -27,6 +27,12 @@ wait_time = 2 cache_time = 30 cache_path = '/dev/shm/nohang_env_cache' + +psi_support = os.path.exists('/proc/pressure/memory') + + + + ########################################################################## @@ -34,10 +40,14 @@ cache_path = '/dev/shm/nohang_env_cache' def psi_mem_some_avg_total(): - if os.path.exists('/proc/pressure/memory'): + if psi_support: return float(rline1('/proc/pressure/memory').rpartition('=')[2]) + + + + def check_mem(): """find mem_available""" return int(rline1('/proc/meminfo').split(':')[1].strip(' kB\n')) @@ -1518,7 +1528,6 @@ stdout.flush() -psi_support = os.path.exists('/proc/pressure/memory') @@ -1536,6 +1545,9 @@ avg_min_time = 3 sigterm_psi = 60 sigkill_psi = 80 + +#print(psi_support) + if psi_support: ta0 = time() a0 = psi_mem_some_avg_total() @@ -1547,26 +1559,38 @@ while True: if psi_support: ta1= time() - a1 = psi_mem_some_avg_total() - avg = (a1 - a0) / (ta1 - ta0) / 100 - a0 = a1 - - print('PSI mem avg:', round(avg, 2)) - - - - - if avg >= sigkill_psi: - time0 = time() - mem_info = 'avg > sigkill_avg' - find_victim_and_send_signal(SIGKILL) - elif avg >= sigterm_psi: - time0 = time() - mem_info = 'avg ({}) > sigterm_avg ({})'.format(avg, sigterm_avg) - find_victim_and_send_signal(SIGTERM) - else: + dt = ta1 - ta0 + #print(dt) + if dt < avg_min_time: pass + #a0 = a1 + (psi_mem_some_avg_total() - a0) + + else: + + + + + + a1 = psi_mem_some_avg_total() + avg = (a1 - a0) / (ta1 - ta0) / 100 + a0 = a1 + print('PSI mem avg:', round(avg, 2)) + if avg >= sigkill_psi: + time0 = time() + mem_info = 'avg > sigkill_avg' + find_victim_and_send_signal(SIGKILL) + elif avg >= sigterm_psi: + time0 = time() + mem_info = 'avg ({}) > sigterm_avg ({})'.format(avg, sigterm_avg) + find_victim_and_send_signal(SIGTERM) + else: + pass + + + ta0 = ta1 + + mem_available, swap_total, swap_free = check_mem_and_swap() # if swap_min_sigkill is set in percent