This commit is contained in:
Alexey Avramov
2019-03-21 19:17:53 +09:00
parent d97338a8eb
commit 6ca23b4bfe
9 changed files with 18 additions and 31 deletions

102
misc/nohang_new.conf Normal file
View File

@@ -0,0 +1,102 @@
This is nohang config file.
Lines starting with $ contain obligatory parameters.
Lines starting with @ contain optional parameters.
Other lines are comments.
1. Ignore PSI and zram.
$IGNORE_PSI = TRUE
$IGNORE_ZRAM = TRUE
2. Poll rate
$POLL_RATE = 60
$MIN_SLEEP = 0.1
$MAX_SLEEP = 2
3. GUI notifications
$GUI_CORRECTIVE_ACTIONS = FALSE
$GUI_LOW_MEMORY_WARNINGS = FALSE
$GUI_WARNINGS_MIN_MEM = 20 %
$GUI_WARNINGS_MIN_SWAP = 20 %
$GUI_WARNINGS_MAX_ZRAM = 45 %
$GUI_MIN_DELAY_AFTER_WARNING = 15
@EXE_INSTEAD_OF_GUI_WARNING wall -n "LOW MEMORY!"
@EXE_INSTEAD_OF_GUI_WARNING echo 'test'
@EXE_INSTEAD_OF_GUI_WARNING echo 'test2'
4. SIGTERM-related parameters
$SIGTERM_MIN_MEM = 10 %
$SIGTERM_MIN_SWAP = 10 %
$SIGTERM_MAX_ZRAM = 50 %
$DELAY_AFTER_SIGTERM = 0.2
$SIGTERM_MAX_PSI_SOME_AVG10_THRESHOLD = 60
$SIGTERM_MAX_PSI_SOME_AVG10_DURATION = 5
$DELAY_AFTER_SIGTERM_PSI_SOME_AVG10 = 40
The execution of specified command instead of sending a SIGTERM signal.
Syntax example:
<key> <regular expression> /// <command>
@EXE_INSTEAD_OF_SIGTERM_RE_PROCESSNAME ^foo$ /// kill -9 $PID && echo "Praise KEK, kill $NAME" &
@EXE_INSTEAD_OF_SIGTERM_RE_CMDLINE ^/sbin/foo /// systemctl restart foo
@EXE_INSTEAD_OF_SIGTERM_RE_UID ^1000$ /// pkill -SEGV $NAME
@EXE_INSTEAD_OF_SIGTERM_RE_UID ^1001$ /// pkill -HUP $NAME
5. SIGKILL-related parameters
$SIGKILL_MIN_MEM = 5 %
$SIGKILL_MIN_SWAP = 5 %
$SIGKILL_MAX_ZRAM = 55 %
$DELAY_AFTER_SIGKILL = 1
$SIGKILL_MAX_PSI_SOME_AVG10_THRESHOLD = 90
$SIGKILL_MAX_PSI_SOME_AVG10_DURATION = 5
$DELAY_AFTER_SIGKILL_PSI_SOME_AVG10 = 60
6. Adjusting badness of processes
$OOM_SCORE_ADJ_LIMIT = -1
Badness adjusting by matching process name, cmdline and eUID with specified regular expression.
Example badness adj rules
<key> <regular expression> /// <badness_adj>
@BADNESS_ADJ_RE_CMDLINE -childID|--type=renderer /// 200
@BADNESS_ADJ_RE_NAME ^Xorg$ /// -100
@BADNESS_ADJ_RE_UID ^0$ /// -50
7. Avoid killing small processes (innocent victims)
$MIN_VICTIM_BADNESS = 20
8. Verbosity
$PRINT_CONFIG_AT_STARTUP = FALSE
$PRINT_TOTAL_STAT = TRUE
$PRINT_MEM_CHECK_RESULTS = FALSE
$MIN_DELAY_AFTER_PRINT_MEM_CHECK_RESULTS = 60
$PRINT_SLEEP_PERIODS = FALSE

125
misc/oom-trigger Executable file
View File

@@ -0,0 +1,125 @@
#!/usr/bin/env python3
"""
Interactive OOM trigger
"""
import os
from argparse import ArgumentParser
##########################################################################
# find mem_total
# find positions of SwapFree and SwapTotal in /proc/meminfo
with open('/proc/meminfo') as file:
mem_list = file.readlines()
mem_list_names = []
for s in mem_list:
mem_list_names.append(s.split(':')[0])
if mem_list_names[2] != 'MemAvailable':
print('Your Linux kernel is too old, Linux 3.14+ requied\nExit')
exit()
swap_total_index = mem_list_names.index('SwapTotal')
swap_free_index = swap_total_index + 1
mem_total = int(mem_list[0].split(':')[1].strip(' kB\n'))
# Get names from /proc/*/status to be able to get VmRSS and VmSwap values
with open('/proc/self/status') as file:
status_list = file.readlines()
status_names = []
for s in status_list:
status_names.append(s.split(':')[0])
vm_rss_index = status_names.index('VmRSS')
vm_swap_index = status_names.index('VmSwap')
# вариант - сжирать мегабайты исходя из собственного VmRSS + VmSwap
print(mem_total, swap_total_index, swap_free_index, vm_rss_index, vm_swap_index)
##########################################################################
def continue_anyway():
"""
Mem hog if mem err
"""
expanding_list = []
while True:
try:
expanding_list.append(os.urandom(1))
except MemoryError:
continue
def unlimited_memhog():
'''
unlimited mem hogging
'''
print('Вводите целые неотрицательные числа. Чем больше, тем быстрее потребление памяти.\n1000 same обеспечивает потребление на уровне полтора гиг в секунду,\nurandom работает на скорости максимум 170 M/s')
same = input("same: ")
urandom = input("urandom: ")
expanding_list = []
print('Unlimited memhogging started!')
while True:
try:
expanding_list.append(os.urandom(int(urandom)))
expanding_list.append('#' * int(same))
except MemoryError:
print('MemoryError; continue anyway!')
continue_anyway()
##########################################################################
# basic bifurcation
print('WARNING: эта прога способна потратить память и повесить систему, будьте осторожны.')
print('При ее работе следите за показателями памяти.')
expanding_list = []
'''
hogging не то
u - unlimited mem hogging with choice of speed and entropy
n - limited mem hogging (hog указанный далее объем метров)
a - уменьшать обем общей доступной памяти (MemAvailable + SwapFree) до тех пор, пока он не станет ниже заданного далее объема
'''
try:
while True:
print('Select an option from the list below, enter selected letter and press Enter')
print('8 или i или I - запустить бесконечное потребление, предложив выбрать скорость потребления и энтропию')
print('q или любой другой символ - выход (можно просто нажать Enter)')
li = input(': ')
if li is 'i' or li is 'I' or li is '8':
unlimited_memhog()
else:
exit()
except KeyboardInterrupt:
print()
os.kill(os.getpid(), 15)

51
misc/psi-monitor Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env python3
from time import sleep, time
import os
from sys import stdout
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 = 1
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) / 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(0.1)

2
misc/psi_dummy Normal file
View File

@@ -0,0 +1,2 @@
some avg10=29.70 avg60=51.59 avg300=22.92 total=195239452
full avg10=28.82 avg60=49.77 avg300=21.83 total=182504463