-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathksm
executable file
·83 lines (71 loc) · 1.85 KB
/
ksm
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/sbin/openrc-run
readonly ksm_dir=/sys/kernel/mm/ksm
readonly ksm_pages_sharing=${ksm_dir}/pages_sharing
readonly ksm_pages_to_scan=${ksm_dir}/pages_to_scan
readonly ksm_run=${ksm_dir}/run
readonly not_supported="Kernel does not support Kernel Samepage Merging"
readonly page_size=$(getconf PAGESIZE)
btoh() {
awk '{
if ($1 == 1) {
print "1 byte"
} else {
split("bytes KiB MiB GiB TiB PiB EiB ZiB YiB", suffix)
for (power = 1; $1 > 1024; power++) {
$1 /= 1024
}
if ( power > 1 ) {
format = "%.2f %s"
} else {
format = "%d %s"
}
printf(format, $1, suffix[power])
}
}' <<< "${1}"
}
depend() {
before libvirtd
}
start() {
ebegin "Starting KSM (Kernel Samepage Merging)"
if [[ ! -f "${ksm_run}" ]]; then
eend 1 "${not_supported}"
return 1
fi
if [[ -n "${pages_to_scan}" ]]; then
echo "${pages_to_scan}" > "${ksm_pages_to_scan}"
fi
echo 1 > "${ksm_run}"
eend "${?}"
}
stop() {
ebegin "Stopping KSM (Kernel Samepage Merging)"
if [[ ! -f "${ksm_run}" ]]; then
eend 1 "${not_supported}"
return 1
fi
echo 0 > "${ksm_run}"
eend "${?}"
}
status() {
if [[ ! -f "${ksm_run}" ]]; then
eerror "${not_supported}"
return 1
fi
local run=$(cat "${ksm_run}")
local sharing=$(cat "${ksm_pages_sharing}")
local saved=$((sharing * page_size))
local human=$(btoh "${saved}")
if [[ "${run}" -eq 1 ]]; then
einfo "KSM (Kernel Samepage Merging) is running; ${human} saved"
return 0
else
einfo "KSM (Kernel Samepage Merging) is not running; ${human} saved"
return 1
fi
}
# Local Variables:
# mode: sh
# sh-basic-offset: 4
# indent-tabs-mode: nil
# End: