fix psi support

This commit is contained in:
Alexey Avramov 2019-01-02 16:34:28 +09:00
parent ec1f94542e
commit 7aaa2fdc72
3 changed files with 58 additions and 23 deletions

31
nohang
View File

@ -27,8 +27,10 @@ wait_time = 2
cache_time = 30
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():
if psi_support:
return float(rline1('/memory').rpartition('=')[2])
return float(rline1(psi_path).rpartition('=')[2])
@ -1541,24 +1543,39 @@ avg_min_time = 3
##########################################################################
ta0 = time()
a0 = psi_mem_some_avg_total()
if psi_support:
ta0 = time()
a0 = psi_mem_some_avg_total()
while True:
if psi_support:
ta1= time()
dt = ta1 - ta0
if dt >= avg_min_time:
a1 = psi_mem_some_avg_total()
avg = (a1 - a0) / (ta1 - ta0) / 100
a0 = a1
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')

View File

@ -39,6 +39,17 @@ $IGNORE_SWAPSPACE = FALSE
$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
@ -90,9 +101,9 @@ zram_max_sigkill = 55 %
Valid values are positive floating-point numbers.
rate_mem = 6
rate_swap = 3
rate_zram = 1
rate_mem = 60
rate_swap = 30
rate_zram = 10
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
problem. Other distros is not tested.
mlockall = False
mlockall = True
Установка отрицательных значений niceness и oom_score_adj
требует наличия root прав.
@ -336,7 +347,7 @@ print_config = False
Print memory check results.
Valid values are True and False.
print_mem_check_results = False
print_mem_check_results = True
Print sleep periods between memory checks.
Valid values are True and False.

View File

@ -1,33 +1,34 @@
#!/usr/bin/env python3
from time import sleep, time
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_support = os.path.exists(psi_path)
def rline1(path):
"""read 1st line from path."""
with open(path) as f:
for line in f:
return line[:-1]
def psi_mem_some_avg_total():
return float(rline1(psi_path).rpartition('=')[2])
avg_min_time = 0.1
avg_min_time = 1
if psi_support:
ta0 = time()
a0 = psi_mem_some_avg_total()
while True:
if psi_support:
@ -38,11 +39,17 @@ while True:
if dt >= avg_min_time:
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(rline1(psi_path), '\n')
ta0 = ta1
a0 = a1
stdout.flush()
sleep(1)
sleep(0.1)