добавлена опция print_sleep_pediods
This commit is contained in:
parent
4aa96f0eda
commit
d625e513ba
@ -48,7 +48,7 @@ https://2ch.hk/s/res/2310304.html#2311483, https://archive.li/idixk
|
||||
- по умолчанию высокий приоритет процесса `nice -20`, может регулироваться через конфиг
|
||||
- предотвращение самоубийства с помощью `self_oom_score_adj = -1000`
|
||||
- возможность задания `oom_score_min` для предотвращения убийства невиновных
|
||||
- verbosity: опциональность печати параметров конфига при старте программы, опциональность печати результатов проверки памяти
|
||||
- verbosity: опциональность печати параметров конфига при старте программы, опциональность печати результатов проверки памяти и времени между проверками пяти
|
||||
- возможность предотвращения избыточного убийства процессов с помощью задания миниального `oom_score` для убиваемых процессов и установка минимальной задержки просле отправки сигналов (параметры конфига `min_delay_after_sigkill` и `min_delay_after_sigterm`)
|
||||
- наличие `man` страницы
|
||||
- наличие установщика для пользователей `systemd`
|
||||
|
46
nohang
46
nohang
@ -125,7 +125,6 @@ def find_victim_and_send_signal(signal):
|
||||
func_decrease_oom_score_adj(oom_score_adj_before, oom_score_adj_after)
|
||||
|
||||
oom_list = []
|
||||
|
||||
for i in os.listdir('/proc'):
|
||||
if i.isdigit() is not True:
|
||||
continue
|
||||
@ -161,9 +160,18 @@ def find_victim_and_send_signal(signal):
|
||||
print(' Operation not permitted')
|
||||
|
||||
else:
|
||||
|
||||
print(' oom_score {} < oom_score_min {}'.format(oom_score, oom_score_min))
|
||||
|
||||
# спать всегда или только при успешной отправке сигнала?
|
||||
if signal is 9:
|
||||
if print_sleep_pediods:
|
||||
print(' sleep', min_delay_after_sigkill)
|
||||
sleep(min_delay_after_sigterm)
|
||||
else:
|
||||
if print_sleep_pediods:
|
||||
print(' sleep', min_delay_after_sigterm)
|
||||
sleep(min_delay_after_sigterm)
|
||||
|
||||
|
||||
###########################################################################################
|
||||
|
||||
@ -191,7 +199,6 @@ mem_total = int(mem_list[0].split(':')[1].split(' ')[-2])
|
||||
# еще найти позиции VmRSS & VmSwap
|
||||
|
||||
|
||||
|
||||
###########################################################################################
|
||||
|
||||
# - получение пути к конфигу
|
||||
@ -236,7 +243,6 @@ print('Path to nohang config file:', config)
|
||||
|
||||
# - парсинг конфига с получением словаря параметров
|
||||
|
||||
|
||||
try:
|
||||
with open(config) as f:
|
||||
config_dict = dict()
|
||||
@ -267,7 +273,6 @@ except IndexError:
|
||||
# - извлечение параметров из словаря, проверка наличия всех необходимых параметров
|
||||
|
||||
|
||||
|
||||
if 'print_config' in config_dict:
|
||||
print_config = config_dict['print_config']
|
||||
if print_config == 'True':
|
||||
@ -285,7 +290,6 @@ else:
|
||||
print('print_config not in config, exit!')
|
||||
exit()
|
||||
|
||||
|
||||
if 'print_mem_check_results' in config_dict:
|
||||
print_mem_check_results = config_dict['print_mem_check_results']
|
||||
if print_mem_check_results == 'True':
|
||||
@ -303,6 +307,23 @@ else:
|
||||
print('print_mem_check_results not in config, exit!')
|
||||
exit()
|
||||
|
||||
if 'print_sleep_pediods' in config_dict:
|
||||
print_sleep_pediods = config_dict['print_sleep_pediods']
|
||||
if print_sleep_pediods == 'True':
|
||||
print_sleep_pediods = True
|
||||
elif print_sleep_pediods == 'False':
|
||||
print_sleep_pediods = False
|
||||
else:
|
||||
print(
|
||||
'invalid print_sleep_pediods value {} (should be True or False), exit!'.format(
|
||||
print_sleep_pediods
|
||||
)
|
||||
)
|
||||
exit()
|
||||
else:
|
||||
print('print_sleep_pediods not in config, exit!')
|
||||
exit()
|
||||
|
||||
if 'mlockall' in config_dict:
|
||||
mlockall = config_dict['mlockall']
|
||||
if mlockall == 'True':
|
||||
@ -555,6 +576,7 @@ else:
|
||||
if print_config:
|
||||
print('print_config: {}'.format(print_config))
|
||||
print('print_mem_check_results: {}'.format(print_mem_check_results))
|
||||
print('print_sleep_pediods: {}'.format(print_sleep_pediods))
|
||||
print('mlockall: {} ({})'.format(mlockall, mla_res))
|
||||
print('self_nice: {} ({})'.format(self_nice, self_nice_result))
|
||||
print('self_oom_score_adj: {} ({})'.format(self_oom_score_adj, self_oom_score_adj_result))
|
||||
@ -580,7 +602,7 @@ if print_config:
|
||||
|
||||
|
||||
|
||||
# для рассчета ширины столбцов mem и zram
|
||||
# для рассчета ширины столбцов при печати mem и zram
|
||||
mem_len = len(str(round(mem_total / 1024.0)))
|
||||
|
||||
|
||||
@ -676,7 +698,6 @@ while True:
|
||||
)
|
||||
)
|
||||
find_victim_and_send_signal(9)
|
||||
sleep(min_delay_after_sigkill)
|
||||
continue
|
||||
|
||||
|
||||
@ -691,7 +712,6 @@ while True:
|
||||
)
|
||||
)
|
||||
find_victim_and_send_signal(9)
|
||||
sleep(min_delay_after_sigkill)
|
||||
continue
|
||||
|
||||
|
||||
@ -711,7 +731,6 @@ while True:
|
||||
)
|
||||
)
|
||||
find_victim_and_send_signal(15)
|
||||
sleep(min_delay_after_sigterm)
|
||||
|
||||
|
||||
# MEM ZRAM TERM
|
||||
@ -725,12 +744,14 @@ while True:
|
||||
)
|
||||
)
|
||||
find_victim_and_send_signal(15)
|
||||
sleep(min_delay_after_sigterm)
|
||||
|
||||
|
||||
|
||||
# задание периода в зависимости от рейтов и уровней доступной памяти
|
||||
t_mem = mem_available / 1000000.0 / rate_mem
|
||||
|
||||
t_swap = swap_free / 10000000.0 / rate_swap
|
||||
|
||||
t_zram = (mem_total * 0.8 - mem_used_zram) / 1000000.0 / rate_zram
|
||||
if t_zram < 0.01:
|
||||
t_zram = 0.01
|
||||
@ -743,8 +764,9 @@ while True:
|
||||
else:
|
||||
t = t_mem_zram
|
||||
|
||||
|
||||
try:
|
||||
if print_sleep_pediods:
|
||||
print('sleep', round(t, 2))
|
||||
sleep(t)
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
|
@ -19,6 +19,12 @@ print_config = True
|
||||
|
||||
print_mem_check_results = True
|
||||
|
||||
Печатать ли время сна между проверками памяти и после отправки
|
||||
сигналов. Можно установить в значение True для дебага.
|
||||
Допустимые значения: True и False
|
||||
|
||||
print_sleep_pediods = False
|
||||
|
||||
#####################################################################
|
||||
|
||||
II. САМОЗАЩИТА ПРОЦЕССА
|
||||
@ -138,6 +144,8 @@ min_delay_after_sigkill = 3
|
||||
|
||||
decrease_oom_score_adj = False
|
||||
|
||||
Допустимые значения - целые числа из диапазона [0; 1000]
|
||||
|
||||
oom_score_adj_before = 10
|
||||
oom_score_adj_after = 5
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user