-
Notifications
You must be signed in to change notification settings - Fork 0
/
uksmstat-max
37 lines (37 loc) · 1.01 KB
/
uksmstat-max
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
#!/bin/lksh
sleep=5
cycle=10
oldmemuse=0
if [ -f /dev/shm/uksm.maxmemuse ]; then
read maxmemuse < /dev/shm/uksm.maxmemuse
else
maxmemuse=0
fi
while : ; do
read memuse < /sys/kernel/mm/uksm/pages_sharing
while read -r line
do
if [ "${line%:*}" = "KsmZeroPages" ]; then
ksmzero=${line//[a-zA-Z:]/}
break
fi
done < /proc/meminfo
shareplususe=$(($memuse * 4096 + ${ksmzero//[a-zA-Z:]/} * 1024 ))
if [ $shareplususe -gt $maxmemuse ]; then
maxmemuse=$shareplususe
echo $maxmemuse > /dev/shm/uksm.maxmemuse
fi
if [ $cycle -eq 10 ] ; then
memuse=$(numfmt --to=iec-i --suffix=B --padding=6 $shareplususe )
if [ ! "$memuse" = "$oldmemuse" ]; then
read scanpages < /sys/kernel/mm/uksm/pages_scanned
scanpages=$(numfmt --to=si --padding=5 $scanpages )
maxmemuseb=$(numfmt --to=iec-i --suffix=B --padding=6 $maxmemuse)
echo `date +%T` "sharing+zero: $memuse ($maxmemuseb), pages_scanned:$scanpages"
oldmemuse=$memuse
fi
cycle=0
fi
sleep $sleep
((cycle++))
done