fix psi support
This commit is contained in:
parent
ec1f94542e
commit
7aaa2fdc72
31
nohang
31
nohang
@ -27,8 +27,10 @@ wait_time = 2
|
|||||||
cache_time = 30
|
cache_time = 30
|
||||||
cache_path = '/dev/shm/nohang_env_cache'
|
cache_path = '/dev/shm/nohang_env_cache'
|
||||||
|
|
||||||
psi_support = os.path.exists('/memory')
|
|
||||||
|
|
||||||
|
psi_path = '/proc/pressure/memory'
|
||||||
|
|
||||||
|
psi_support = os.path.exists(psi_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ psi_support = os.path.exists('/memory')
|
|||||||
|
|
||||||
def psi_mem_some_avg_total():
|
def psi_mem_some_avg_total():
|
||||||
if psi_support:
|
if psi_support:
|
||||||
return float(rline1('/memory').rpartition('=')[2])
|
return float(rline1(psi_path).rpartition('=')[2])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1541,24 +1543,39 @@ avg_min_time = 3
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
|
if psi_support:
|
||||||
ta0 = time()
|
ta0 = time()
|
||||||
a0 = psi_mem_some_avg_total()
|
a0 = psi_mem_some_avg_total()
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
|
||||||
if psi_support:
|
if psi_support:
|
||||||
|
|
||||||
ta1= time()
|
ta1= time()
|
||||||
|
dt = ta1 - ta0
|
||||||
|
|
||||||
|
if dt >= avg_min_time:
|
||||||
|
|
||||||
a1 = psi_mem_some_avg_total()
|
a1 = psi_mem_some_avg_total()
|
||||||
avg = (a1 - a0) / (ta1 - ta0) / 100
|
avg = (a1 - a0) / (ta1 - ta0) / 100
|
||||||
a0 = a1
|
|
||||||
|
|
||||||
print('PSI mem avg:', round(avg, 2))
|
print('PSI mem avg:', round(avg, 2))
|
||||||
|
ta0 = ta1
|
||||||
|
a0 = a1
|
||||||
|
|
||||||
|
|
||||||
|
if avg >= sigkill_psi:
|
||||||
|
time0 = time()
|
||||||
|
mem_info = 'avg ({}) > sigkill_psi ({})'.format(avg, sigkill_psi)
|
||||||
|
find_victim_and_send_signal(SIGKILL)
|
||||||
|
elif avg >= sigterm_psi:
|
||||||
|
time0 = time()
|
||||||
|
mem_info = 'avg ({}) > sigterm_psi ({})'.format(avg, sigterm_psi)
|
||||||
|
find_victim_and_send_signal(SIGTERM)
|
||||||
|
else:
|
||||||
|
print('PSI is OK')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
21
nohang.conf
21
nohang.conf
@ -39,6 +39,17 @@ $IGNORE_SWAPSPACE = FALSE
|
|||||||
|
|
||||||
$IGNORE_ZRAM = TRUE
|
$IGNORE_ZRAM = TRUE
|
||||||
|
|
||||||
|
$IGNORE_PSI = TRUE
|
||||||
|
$SIGKILL_PSI_AVG = 80
|
||||||
|
$SIGTERM_PSI_AVG = 60
|
||||||
|
$PSI_AVG_TIME = 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
1. Thresholds below which a signal should be sent to the victim
|
1. Thresholds below which a signal should be sent to the victim
|
||||||
@ -90,9 +101,9 @@ zram_max_sigkill = 55 %
|
|||||||
|
|
||||||
Valid values are positive floating-point numbers.
|
Valid values are positive floating-point numbers.
|
||||||
|
|
||||||
rate_mem = 6
|
rate_mem = 60
|
||||||
rate_swap = 3
|
rate_swap = 30
|
||||||
rate_zram = 1
|
rate_zram = 10
|
||||||
|
|
||||||
See also https://github.com/rfjakob/earlyoom/issues/61
|
See also https://github.com/rfjakob/earlyoom/issues/61
|
||||||
|
|
||||||
@ -289,7 +300,7 @@ zram_max_warnings = 40 %
|
|||||||
200 MiB. On Debian 8, Debian 9, Ubuntu 16.04 there is no such
|
200 MiB. On Debian 8, Debian 9, Ubuntu 16.04 there is no such
|
||||||
problem. Other distros is not tested.
|
problem. Other distros is not tested.
|
||||||
|
|
||||||
mlockall = False
|
mlockall = True
|
||||||
|
|
||||||
Установка отрицательных значений niceness и oom_score_adj
|
Установка отрицательных значений niceness и oom_score_adj
|
||||||
требует наличия root прав.
|
требует наличия root прав.
|
||||||
@ -336,7 +347,7 @@ print_config = False
|
|||||||
Print memory check results.
|
Print memory check results.
|
||||||
Valid values are True and False.
|
Valid values are True and False.
|
||||||
|
|
||||||
print_mem_check_results = False
|
print_mem_check_results = True
|
||||||
|
|
||||||
Print sleep periods between memory checks.
|
Print sleep periods between memory checks.
|
||||||
Valid values are True and False.
|
Valid values are True and False.
|
||||||
|
@ -1,33 +1,34 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from sys import stdout
|
||||||
|
|
||||||
from sys import stdout, stderr
|
mlockall = True
|
||||||
|
|
||||||
|
if mlockall:
|
||||||
|
from ctypes import CDLL
|
||||||
|
CDLL('libc.so.6').mlockall(3)
|
||||||
|
|
||||||
psi_path = '/proc/pressure/memory'
|
psi_path = '/proc/pressure/memory'
|
||||||
|
|
||||||
psi_support = os.path.exists(psi_path)
|
psi_support = os.path.exists(psi_path)
|
||||||
|
|
||||||
|
|
||||||
def rline1(path):
|
def rline1(path):
|
||||||
"""read 1st line from path."""
|
"""read 1st line from path."""
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
return line[:-1]
|
return line[:-1]
|
||||||
|
|
||||||
|
|
||||||
def psi_mem_some_avg_total():
|
def psi_mem_some_avg_total():
|
||||||
return float(rline1(psi_path).rpartition('=')[2])
|
return float(rline1(psi_path).rpartition('=')[2])
|
||||||
|
|
||||||
avg_min_time = 0.1
|
avg_min_time = 1
|
||||||
|
|
||||||
if psi_support:
|
if psi_support:
|
||||||
ta0 = time()
|
ta0 = time()
|
||||||
a0 = psi_mem_some_avg_total()
|
a0 = psi_mem_some_avg_total()
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if psi_support:
|
if psi_support:
|
||||||
@ -38,11 +39,17 @@ while True:
|
|||||||
if dt >= avg_min_time:
|
if dt >= avg_min_time:
|
||||||
|
|
||||||
a1 = psi_mem_some_avg_total()
|
a1 = psi_mem_some_avg_total()
|
||||||
avg = (a1 - a0) / (ta1 - ta0) / 100
|
avg = (a1 - a0) / (ta1 - ta0) / 10000
|
||||||
|
|
||||||
|
print('avg time:', round(dt, 1))
|
||||||
print('PSI mem avg:', round(avg, 2))
|
print('PSI mem avg:', round(avg, 2))
|
||||||
|
print(rline1(psi_path), '\n')
|
||||||
ta0 = ta1
|
ta0 = ta1
|
||||||
a0 = a1
|
a0 = a1
|
||||||
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
sleep(1)
|
sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user