update options names in conf

This commit is contained in:
Alexey Avramov 2019-06-06 22:40:42 +09:00
parent 9691c2300e
commit cc0b1151de
2 changed files with 87 additions and 88 deletions

116
nohang
View File

@ -5,7 +5,7 @@ import os
from ctypes import CDLL from ctypes import CDLL
from time import sleep, time from time import sleep, time
from operator import itemgetter from operator import itemgetter
from sys import stdout, stderr, argv, exit, version from sys import stdout, stderr, argv, exit
from re import search from re import search
from sre_constants import error as invalid_re from sre_constants import error as invalid_re
from signal import signal, SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGHUP from signal import signal, SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGHUP
@ -374,43 +374,43 @@ def pid_to_badness(pid):
if regex_matching: if regex_matching:
name = pid_to_name(pid) name = pid_to_name(pid)
for re_tup in processname_re_list: for re_tup in badness_adj_re_name_list:
if search(re_tup[1], name) is not None: if search(re_tup[1], name) is not None:
badness += int(re_tup[0]) badness += int(re_tup[0])
if re_match_cgroup_v1: if re_match_cgroup_v1:
cgroup_v1 = pid_to_cgroup_v1(pid) cgroup_v1 = pid_to_cgroup_v1(pid)
for re_tup in cgroup_v1_re_list: for re_tup in badness_adj_re_cgroup_v1_list:
if search(re_tup[1], cgroup_v1) is not None: if search(re_tup[1], cgroup_v1) is not None:
badness += int(re_tup[0]) badness += int(re_tup[0])
if re_match_cgroup_v2: if re_match_cgroup_v2:
cgroup_v2 = pid_to_cgroup_v2(pid) cgroup_v2 = pid_to_cgroup_v2(pid)
for re_tup in cgroup_v2_re_list: for re_tup in badness_adj_re_cgroup_v2_list:
if search(re_tup[1], cgroup_v2) is not None: if search(re_tup[1], cgroup_v2) is not None:
badness += int(re_tup[0]) badness += int(re_tup[0])
if re_match_realpath: if re_match_realpath:
realpath = pid_to_realpath(pid) realpath = pid_to_realpath(pid)
for re_tup in realpath_re_list: for re_tup in badness_adj_re_realpath_list:
if search(re_tup[1], realpath) is not None: if search(re_tup[1], realpath) is not None:
badness += int(re_tup[0]) badness += int(re_tup[0])
if re_match_cmdline: if re_match_cmdline:
cmdline = pid_to_cmdline(pid) cmdline = pid_to_cmdline(pid)
for re_tup in cmdline_re_list: for re_tup in badness_adj_re_cmdline_list:
if search(re_tup[1], cmdline) is not None: if search(re_tup[1], cmdline) is not None:
badness += int(re_tup[0]) badness += int(re_tup[0])
if re_match_environ: if re_match_environ:
environ = pid_to_environ(pid) environ = pid_to_environ(pid)
for re_tup in environ_re_list: for re_tup in badness_adj_re_environ_list:
if search(re_tup[1], environ) is not None: if search(re_tup[1], environ) is not None:
badness += int(re_tup[0]) badness += int(re_tup[0])
if re_match_uid: if re_match_uid:
uid = pid_to_uid(pid) uid = pid_to_uid(pid)
for re_tup in uid_re_list: for re_tup in badness_adj_re_uid_list:
if search(re_tup[1], uid) is not None: if search(re_tup[1], uid) is not None:
badness += int(re_tup[0]) badness += int(re_tup[0])
@ -2094,21 +2094,19 @@ log('Config: ' + config)
# dictionary with config options # dictionary with config options
config_dict = dict() config_dict = dict()
processname_re_list = [] badness_adj_re_name_list = []
cmdline_re_list = [] badness_adj_re_cmdline_list = []
environ_re_list = [] badness_adj_re_environ_list = []
uid_re_list = [] badness_adj_re_uid_list = []
cgroup_v1_re_list = [] badness_adj_re_cgroup_v1_list = []
cgroup_v2_re_list = [] badness_adj_re_cgroup_v2_list = []
realpath_re_list = [] badness_adj_re_realpath_list = []
soft_actions_list = [] soft_actions_list = []
# separator for optional parameters (that starts with @) # separator for optional parameters (that starts with @)
opt_separator = '///' opt_separator = '///'
# stupid conf parsing, need refactoring # stupid conf parsing, need refactoring
try: try:
with open(config) as f: with open(config) as f:
@ -2167,61 +2165,61 @@ try:
soft_actions_list.append(zzz) soft_actions_list.append(zzz)
if line.startswith('@PROCESSNAME_RE'): if line.startswith('@BADNESS_ADJ_RE_NAME'):
a = line.partition( a = line.partition('@BADNESS_ADJ_RE_NAME')[2].strip(
'@PROCESSNAME_RE')[2].strip(' \n').partition(opt_separator) ' \n').partition(opt_separator)
badness_adj = a[0].strip(' ') badness_adj = a[0].strip(' ')
reg_exp = a[2].strip(' ') reg_exp = a[2].strip(' ')
valid_re(reg_exp) valid_re(reg_exp)
processname_re_list.append((badness_adj, reg_exp)) badness_adj_re_name_list.append((badness_adj, reg_exp))
if line.startswith('@CMDLINE_RE'): if line.startswith('@BADNESS_ADJ_RE_CMDLINE'):
a = line.partition( a = line.partition('@BADNESS_ADJ_RE_CMDLINE')[2].strip(
'@CMDLINE_RE')[2].strip(' \n').partition(opt_separator) ' \n').partition(opt_separator)
badness_adj = a[0].strip(' ') badness_adj = a[0].strip(' ')
reg_exp = a[2].strip(' ') reg_exp = a[2].strip(' ')
valid_re(reg_exp) valid_re(reg_exp)
cmdline_re_list.append((badness_adj, reg_exp)) badness_adj_re_cmdline_list.append((badness_adj, reg_exp))
if line.startswith('@UID_RE'): if line.startswith('@BADNESS_ADJ_RE_UID'):
a = line.partition( a = line.partition('@BADNESS_ADJ_RE_UID')[2].strip(
'@UID_RE')[2].strip(' \n').partition(opt_separator) ' \n').partition(opt_separator)
badness_adj = a[0].strip(' ') badness_adj = a[0].strip(' ')
reg_exp = a[2].strip(' ') reg_exp = a[2].strip(' ')
valid_re(reg_exp) valid_re(reg_exp)
uid_re_list.append((badness_adj, reg_exp)) badness_adj_re_uid_list.append((badness_adj, reg_exp))
if line.startswith('@CGROUP_V1_RE'): if line.startswith('@BADNESS_ADJ_RE_CGROUP_V1'):
a = line.partition( a = line.partition('@BADNESS_ADJ_RE_CGROUP_V1')[2].strip(
'@CGROUP_V1_RE')[2].strip(' \n').partition(opt_separator) ' \n').partition(opt_separator)
badness_adj = a[0].strip(' ') badness_adj = a[0].strip(' ')
reg_exp = a[2].strip(' ') reg_exp = a[2].strip(' ')
valid_re(reg_exp) valid_re(reg_exp)
cgroup_v1_re_list.append((badness_adj, reg_exp)) badness_adj_re_cgroup_v1_list.append((badness_adj, reg_exp))
if line.startswith('@CGROUP_V2_RE'): if line.startswith('@BADNESS_ADJ_RE_CGROUP_V2'):
a = line.partition( a = line.partition('@BADNESS_ADJ_RE_CGROUP_V2')[2].strip(
'@CGROUP_V2_RE')[2].strip(' \n').partition(opt_separator) ' \n').partition(opt_separator)
badness_adj = a[0].strip(' ') badness_adj = a[0].strip(' ')
reg_exp = a[2].strip(' ') reg_exp = a[2].strip(' ')
valid_re(reg_exp) valid_re(reg_exp)
cgroup_v2_re_list.append((badness_adj, reg_exp)) badness_adj_re_cgroup_v2_list.append((badness_adj, reg_exp))
if line.startswith('@REALPATH_RE'): if line.startswith('@BADNESS_ADJ_RE_REALPATH'):
a = line.partition( a = line.partition('@BADNESS_ADJ_RE_REALPATH')[2].strip(
'@REALPATH_RE')[2].strip(' \n').partition(opt_separator) ' \n').partition(opt_separator)
badness_adj = a[0].strip(' ') badness_adj = a[0].strip(' ')
reg_exp = a[2].strip(' ') reg_exp = a[2].strip(' ')
valid_re(reg_exp) valid_re(reg_exp)
realpath_re_list.append((badness_adj, reg_exp)) badness_adj_re_realpath_list.append((badness_adj, reg_exp))
if line.startswith('@ENVIRON_RE'): if line.startswith('@BADNESS_ADJ_RE_ENVIRON'):
a = line.partition( a = line.partition('@BADNESS_ADJ_RE_ENVIRON')[2].strip(
'@ENVIRON_RE')[2].strip(' \n').partition(opt_separator) ' \n').partition(opt_separator)
badness_adj = a[0].strip(' ') badness_adj = a[0].strip(' ')
reg_exp = a[2].strip(' ') reg_exp = a[2].strip(' ')
valid_re(reg_exp) valid_re(reg_exp)
environ_re_list.append((badness_adj, reg_exp)) badness_adj_re_environ_list.append((badness_adj, reg_exp))
except PermissionError: except PermissionError:
@ -2241,54 +2239,54 @@ except FileNotFoundError:
exit(1) exit(1)
if processname_re_list == []: if badness_adj_re_name_list == []:
regex_matching = False regex_matching = False
else: else:
regex_matching = True regex_matching = True
if cmdline_re_list == []: if badness_adj_re_cmdline_list == []:
re_match_cmdline = False re_match_cmdline = False
else: else:
re_match_cmdline = True re_match_cmdline = True
if uid_re_list == []: if badness_adj_re_uid_list == []:
re_match_uid = False re_match_uid = False
else: else:
re_match_uid = True re_match_uid = True
if environ_re_list == []: if badness_adj_re_environ_list == []:
re_match_environ = False re_match_environ = False
else: else:
re_match_environ = True re_match_environ = True
if realpath_re_list == []: if badness_adj_re_realpath_list == []:
re_match_realpath = False re_match_realpath = False
else: else:
re_match_realpath = True re_match_realpath = True
if cgroup_v1_re_list == []: if badness_adj_re_cgroup_v1_list == []:
re_match_cgroup_v1 = False re_match_cgroup_v1 = False
else: else:
re_match_cgroup_v1 = True re_match_cgroup_v1 = True
if cgroup_v2_re_list == []: if badness_adj_re_cgroup_v2_list == []:
re_match_cgroup_v2 = False re_match_cgroup_v2 = False
else: else:
re_match_cgroup_v2 = True re_match_cgroup_v2 = True
# print(processname_re_list) # print(badness_adj_re_name_list)
# print(cmdline_re_list) # print(badness_adj_re_cmdline_list)
# print(uid_re_list) # print(badness_adj_re_uid_list)
# print(environ_re_list) # print(badness_adj_re_environ_list)
# print(realpath_re_list) # print(badness_adj_re_realpath_list)
# print(cgroup_v1_re_list) # print(badness_adj_re_cgroup_v1_list)
# print(cgroup_v2_re_list) # print(badness_adj_re_cgroup_v2_list)
# print(soft_actions_list) # print(soft_actions_list)

View File

@ -159,7 +159,6 @@ min_badness = 20
min_delay_after_sigterm = 3 min_delay_after_sigterm = 3
Valid values are True and False. Valid values are True and False.
Values are case sensitive.
decrease_oom_score_adj = False decrease_oom_score_adj = False
@ -189,7 +188,7 @@ oom_score_adj_max = 0
Syntax: Syntax:
@PROCESSNAME_RE badness_adj /// RE_pattern @BADNESS_ADJ_RE_NAME badness_adj /// RE_pattern
New badness value will be += badness_adj New badness value will be += badness_adj
@ -197,44 +196,46 @@ oom_score_adj_max = 0
with different badness_adj values. with different badness_adj values.
Example: Example:
@BADNESS_ADJ_RE_NAME -500 /// ^sshd$
@PROCESSNAME_RE -500 /// ^sshd$
5.2 Matching cmdlines with RE patterns 5.2 Matching CGroup-line (v1 and v2) with RE patterns
@BADNESS_ADJ_RE_CGROUP_V1 -50 /// ^/system.slice
@BADNESS_ADJ_RE_CGROUP_V1 50 /// foo.service
@BADNESS_ADJ_RE_CGROUP_V1 -50 /// ^/user.slice
@BADNESS_ADJ_RE_CGROUP_V2 100 /// ^/workload
5.3 Matching eUIDs with RE patterns
@BADNESS_ADJ_RE_UID -100 /// ^0$
5.4 Matching realpath with RE patterns
@BADNESS_ADJ_RE_REALPATH 20 /// ^/usr/bin/foo
5.5 Matching cmdlines with RE patterns
A good option that allows fine adjustment. A good option that allows fine adjustment.
Prefer chromium tabs and electron-based apps Prefer chromium tabs and electron-based apps
@CMDLINE_RE 200 /// --type=renderer @BADNESS_ADJ_RE_CMDLINE 200 /// --type=renderer
Prefer firefox tabs (Web Content and WebExtensions) Prefer firefox tabs (Web Content and WebExtensions)
@CMDLINE_RE 100 /// -appomni @BADNESS_ADJ_RE_CMDLINE 100 /// -appomni
@CMDLINE_RE -200 /// ^/usr/lib/virtualbox @BADNESS_ADJ_RE_CMDLINE -200 /// ^/usr/lib/virtualbox
5.3 Matching eUIDs with RE patterns
The most slow option
@UID_RE -100 /// ^0$
5.4 Matching CGroup-line with RE patterns
@CGROUP_V1_RE -50 /// ^/system.slice
@CGROUP_V1_RE 50 /// foo.service
@CGROUP_V1_RE -50 /// ^/user.slice
@CGROUP_V2_RE 100 /// ^/workload
5.5 Matching realpath with RE patterns
@REALPATH_RE 20 /// ^/usr/bin/foo
5.6 Matching environ with RE patterns 5.6 Matching environ with RE patterns
@ENVIRON_RE 100 /// USER=user @BADNESS_ADJ_RE_ENVIRON 100 /// USER=user
Note that you can control badness also via systemd units via Note that you can control badness also via systemd units via
OOMScoreAdjust, see OOMScoreAdjust, see
@ -318,7 +319,7 @@ print_sleep_periods = False
print_total_stat = True print_total_stat = True
print_proc_table = False print_proc_table = True
Valid values: Valid values:
None None
@ -331,7 +332,7 @@ print_proc_table = False
extra_table_info = cgroup_v1 extra_table_info = cgroup_v1
print_victim_info = False print_victim_info = True
max_ancestry_depth = 1 max_ancestry_depth = 1