forked from ShawnZhong/MadFS
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.py
executable file
·44 lines (32 loc) · 1.16 KB
/
init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import os
from pathlib import Path
from scripts.utils import system
def init():
cmds = ""
# enable huge pages
if Path("/proc/sys/vm/nr_hugepages").read_text() != "512\n":
cmds += "sudo sysctl -w vm.nr_hugepages=512\n"
# expose kernel addresses for perf
if Path("/proc/sys/kernel/kptr_restrict").read_text() != "0\n":
cmds += "sudo sysctl -w kernel.kptr_restrict=0\n"
# allow kernel profiling
if Path("/proc/sys/kernel/perf_event_paranoid").read_text() != "-1\n":
cmds += "sudo sysctl -w kernel.perf_event_paranoid=-1\n"
# increase max number of mmap regions
if Path("/proc/sys/vm/max_map_count").read_text() != "131072\n":
cmds += "sudo sysctl -w vm.max_map_count=131072\n"
# disable CPU frequency scaling
paths = [
Path(f"/sys/devices/system/cpu/cpu{i}/cpufreq/scaling_governor")
for i in range(os.cpu_count())
]
cmds += " &&\n".join(
f"echo performance | sudo tee {path} >/dev/null"
for path in paths
if path.read_text() != "performance\n"
)
if cmds != "":
system(cmds)
if __name__ == "__main__":
init()