-
-
Save dsd/a8988bf0b81a6163475988120fe8d9cd to your computer and use it in GitHub Desktop.
psi killer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import time | |
import re | |
THRESHOLD = 10 | |
def main(): | |
sysrq_mask = int(open("/proc/sys/kernel/sysrq").read()) | |
sysrq_mask = sysrq_mask | 0x40 | |
open("/proc/sys/kernel/sysrq", "w").write(str(sysrq_mask)) | |
while True: | |
time.sleep(5) | |
pressure_info = open("/proc/pressure/memory").readlines()[1] | |
match = re.match(r'full avg10=([\d\.]+).*', pressure_info) | |
full_avg10 = float(match.groups()[0]) | |
print (full_avg10) | |
if full_avg10 > THRESHOLD: | |
print("Above threshold limit, killing task and pausing for recovery") | |
open("/proc/sysrq-trigger", "w").write("f") | |
time.sleep(10) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment