-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuksmdstats
executable file
·39 lines (38 loc) · 2.39 KB
/
uksmdstats
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
#!/bin/sh
export TEXTDOMAIN='uksmdstats'
export TEXTDOMAINDIR='/usr/share/locale'
if [ -f /sys/kernel/process_ksm/process_ksm_enable ] && [ -f /sys/kernel/process_ksm/process_ksm_disable ] && [ -f /sys/kernel/process_ksm/process_ksm_status ]; then
echo "======================================================"
echo "uksmd with uksmdstats support. Powered by CachyOS Team"
echo "======================================================"
while true; do
echo "$( gettext "Full scans" ): $(cat /sys/kernel/mm/ksm/full_scans)"
echo "$( gettext "Interval" ): $(cat /sys/kernel/mm/ksm/sleep_millisecs)" ms
echo ":"
echo "$( gettext "Max page sharing ratio" ): $(cat /sys/kernel/mm/ksm/max_page_sharing)"
echo "$( gettext "Pages to scan" ): $(cat /sys/kernel/mm/ksm/pages_to_scan)"
echo "$( gettext "Pages over ratio" ): $(cat /sys/kernel/mm/ksm/stable_node_chains)"
echo "$( gettext "Duplicated pages" ): $(cat /sys/kernel/mm/ksm/stable_node_dups)"
echo "$( gettext "Use zero pages" ): $(cat /sys/kernel/mm/ksm/use_zero_pages)"
if [ "$(cat /sys/kernel/mm/ksm/pages_shared)" -gt 0 ] && [ "$(cat /sys/kernel/mm/ksm/pages_sharing)" -gt 0 ]; then
echo "$( gettext "Sharing/shared ratio" ): $(awk "BEGIN {x=$(cat /sys/kernel/mm/ksm/pages_sharing);y=$(cat /sys/kernel/mm/ksm/pages_shared);print x/y}")"
echo "$( gettext "Unshared/sharing ratio" ): $(awk "BEGIN {x=$(cat /sys/kernel/mm/ksm/pages_unshared);y=$(cat /sys/kernel/mm/ksm/pages_sharing);print x/y}")"
else
echo "$( gettext "Sharing/shared ratio" ): 0"
echo "$( gettext "Unshared/sharing ratio" ): 0"
fi
echo ":"
# formula MiB: $page_value * page size in Bytes / (1024 * 1024)
# = $page_value * 4096 / (1024 / 1024) = $page_value / 256 (MiB)
echo "$( gettext "Pages sharing" ): $(awk '{ print($0 / 256) }' /sys/kernel/mm/ksm/pages_sharing):MiB"
echo "$( gettext "Pages shared" ): $(awk '{ print($0 / 256) }' /sys/kernel/mm/ksm/pages_shared):MiB"
echo "$( gettext "Pages unshared" ): $(awk '{ print($0 / 256) }' /sys/kernel/mm/ksm/pages_unshared):MiB"
echo ":"
# https://www.kernel.org/doc/Documentation/admin-guide/mm/ksm.rst
# general_profit =~ pages_sharing * sizeof(page) - (all_rmap_items) * sizeof(rmap_item);
echo "$( gettext "General profit" ): $(awk '{ print($0 / 1024 / 1024) }' /sys/kernel/mm/ksm/general_profit):MiB"
break
done | column -t -s':'
else
echo -e "$( gettext "The kernel you are using does not support" ) UKSMD."
fi