mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Session preload: drop oom_score_adj raises so lmkd does not treat games as cached apps
steam-launch-wrapper starts every game with --oom-score-adjust 900; on Android 900 is CACHED_APP_MIN_ADJ, so lmkd kills the running game first when memory runs short (and on Linux 6.1 the raise becomes the process's permanent minimum). A process in the app cannot go below the score it inherits, so the writes that succeed from inside are raises: every write-open of /proc/<pid|self|thread-self>[/task/<tid>]/oom_score_adj (or oom_adj), through open/openat or fopen, goes to /dev/null, logged once. Based on the oom_score_adj redirect in the preload's opens.c by jdmg28 (https://github.com/jdmg28/DroidDeck-Mali/commit/6be00e00)
This commit is contained in:
1 parent
a447e9d7a0
commit
4367d0634f
4 files changed
+100
No files matched your search
@@ -0,0 +1,47 @@
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[1] / "linuxfs/preload/oomadj.c"
|
||||
|
||||
PROGRAM = r"""
|
||||
#include <stdio.h>
|
||||
const char *bl_oom_adj_redirect(const char *path, int writing);
|
||||
int main(int argc, char **argv) {
|
||||
for (int i = 1; i + 1 < argc; i += 2) printf("%s\n", bl_oom_adj_redirect(argv[i + 1], argv[i][0] == 'w'));
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("cc"), "needs cc")
|
||||
class OomAdjPreloadTest(unittest.TestCase):
|
||||
def test_only_writes_to_oom_files_go_to_dev_null(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
main = Path(tmp) / "main.c"
|
||||
main.write_text(PROGRAM)
|
||||
binary = Path(tmp) / "probe"
|
||||
subprocess.run(["cc", "-o", str(binary), str(main), str(SOURCE)], check=True)
|
||||
cases = [
|
||||
("w", "/proc/self/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/123/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/thread-self/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/12/task/34/oom_score_adj", "/dev/null"),
|
||||
("w", "/proc/self/oom_adj", "/dev/null"),
|
||||
("r", "/proc/self/oom_score_adj", "/proc/self/oom_score_adj"),
|
||||
("w", "/proc/self/oom_score", "/proc/self/oom_score"),
|
||||
("w", "/proc/abc/oom_score_adj", "/proc/abc/oom_score_adj"),
|
||||
("w", "/tmp/oom_score_adj", "/tmp/oom_score_adj"),
|
||||
]
|
||||
args = [str(binary)]
|
||||
for mode, path, _ in cases:
|
||||
args += [mode, path]
|
||||
out = subprocess.run(args, capture_output=True, text=True, check=True)
|
||||
self.assertEqual(out.stdout.split(), [want for _, _, want in cases])
|
||||
self.assertIn("oom_score_adj raise was dropped", out.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user