fix mlockall
This commit is contained in:
parent
4d8660957b
commit
f3d2e4e099
45
nohang
45
nohang
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""A daemon that prevents OOM in Linux systems."""
|
||||
import os
|
||||
import ctypes
|
||||
from time import sleep, time
|
||||
from operator import itemgetter
|
||||
from sys import stdout
|
||||
@ -44,20 +45,12 @@ stop_cont = False
|
||||
stop_cont_warn = False
|
||||
|
||||
|
||||
##########################################################################
|
||||
|
||||
# define functions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
# define MCL_CURRENT 1 /* Lock all currently mapped pages. */
|
||||
# define MCL_FUTURE 2 /* Lock all additions to address
|
||||
space. */
|
||||
# define MCL_ONFAULT 4 /* Lock all pages that are
|
||||
faulted in. */
|
||||
https://code.woboq.org/gcc/include/bits/mman-linux.h.html
|
||||
'''
|
||||
import ctypes
|
||||
def mlockall():
|
||||
|
||||
MCL_CURRENT = 1
|
||||
MCL_FUTURE = 2
|
||||
@ -65,18 +58,15 @@ MCL_ONFAULT = 4
|
||||
|
||||
libc = ctypes.CDLL('libc.so.6', use_errno=True)
|
||||
|
||||
def mlockall(flags=MCL_CURRENT|MCL_FUTURE|MCL_ONFAULT):
|
||||
result = libc.mlockall(flags)
|
||||
result = libc.mlockall(MCL_CURRENT|MCL_FUTURE|MCL_ONFAULT)
|
||||
if result != 0:
|
||||
raise Exception("cannot lock memmory, errno=%s" % ctypes.get_errno())
|
||||
|
||||
mlockall()
|
||||
|
||||
|
||||
##########################################################################
|
||||
|
||||
# define functions
|
||||
|
||||
result = libc.mlockall(MCL_CURRENT|MCL_FUTURE)
|
||||
if result != 0:
|
||||
print('Can not lock all memory')
|
||||
else:
|
||||
print('All memory locked with MCL_CURRENT|MCL_FUTURE')
|
||||
else:
|
||||
print('All memory locked with MCL_CURRENT|MCL_FUTURE|MCL_ONFAULT')
|
||||
|
||||
|
||||
def pid_to_state(pid):
|
||||
@ -395,6 +385,9 @@ def notify_send_wait(title, body):
|
||||
|
||||
def notify_helper(title, body):
|
||||
'''GUI notification with UID = 0'''
|
||||
|
||||
# os.system(notify_helper_path + ' foo bar &')
|
||||
|
||||
with Popen([notify_helper_path, title, body]) as proc:
|
||||
try:
|
||||
proc.wait(timeout=wait_time)
|
||||
@ -1028,6 +1021,12 @@ def calculate_percent(arg_key):
|
||||
##########################################################################
|
||||
|
||||
|
||||
|
||||
mlockall()
|
||||
|
||||
|
||||
|
||||
|
||||
# find mem_total
|
||||
# find positions of SwapFree and SwapTotal in /proc/meminfo
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user