fix psi support

This commit is contained in:
Alexey Avramov 2019-01-02 05:08:45 +09:00
parent 97c153247f
commit aa7ad46aed

64
nohang
View File

@ -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