-
Notifications
You must be signed in to change notification settings - Fork 2
/
lshp
executable file
·76 lines (69 loc) · 2.57 KB
/
lshp
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
#!/bin/bash
# $Id: lsthp,v 1.5 2019/04/03 21:17:33 root Exp $
#
PRINT_PATTERN="%-38s %-10s : %s %s\n"
typeset -i index=0
if [[ $UID -ne 0 ]]; then
echo "Run $0 as root!" ; exit 127
fi
# Loop start
if [[ -f /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages && $(cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages) != 0 ]]; then
# find smaps for procs with 2Mb hugepages.
huge_pid_list=$(/bin/egrep -s 'KernelPageSize:[[:space:]]+2048 kB' /proc/*/smaps|cut -d: -f1|xargs)
if [[ -z ${huge_pid_list} ]]; then
printf "#### No 2Mb HugePages found!\n"
else
if [[ $index -eq 0 ]]; then
# Header
printf "${PRINT_PATTERN}" "# [procname] (2Mb HugePages)" "PID" "Size" "unit"
fi
(/bin/egrep -B11 -s 'KernelPageSize:[[:space:]]+2048 kB' ${huge_pid_list}| grep '/smaps.Size:'| \
sed -e 's@/proc/@@' -e 's@/smaps.Size:@@' | \
awk '{ print $2,$3,$1}'| \
while read size unit pid
do
if [[ -f /proc/${pid}/status ]]; then
pidname=$(egrep -s 'Name:' /proc/${pid}/status|awk '{ print $2}')
if [[ "$pidname" = "qemu-kvm" || "$pidname" = "qemu-system-x86" ]]; then
guestname="$(strings -a /proc/${pid}/cmdline |egrep -A1 -i '^-name'|sed -e 's@,debug.*@@' -e 's@guest=@@'|tail -1)"
else
guestname=""
fi
printf "${PRINT_PATTERN}" "${pidname} [ ${guestname} ]" "(${pid})" "${size}" "${unit}"
fi
index=1
done)|sort -u
fi
else
printf "#### No 2Mb HugePages found!\n"
fi
# find smaps for procs with 1Gb hugepages.
if [[ -f /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages && $(cat /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages) != 0 ]]; then
huge_pid_list=$(/bin/egrep -s 'KernelPageSize:[[:space:]]+1048576 kB' /proc/*/smaps|cut -d: -f1|xargs)
if [[ -z ${huge_pid_list} ]]; then
printf "#### No 1Gb HugePages found!\n"
else
if [[ $index -eq 0 ]]; then
# Header
printf "${PRINT_PATTERN}" "# [procname] (1Gb HugePages)" "PID" "Size" "unit"
fi
(/bin/egrep -B11 -s 'KernelPageSize:[[:space:]]+1048576 kB' ${huge_pid_list}| grep '/smaps.Size:'| \
sed -e 's@/proc/@@' -e 's@/smaps.Size:@@' | \
awk '{ print $2,$3,$1}'| \
while read size unit pid
do
if [[ -f /proc/${pid}/status ]]; then
pidname=$(egrep -s 'Name:' /proc/${pid}/status|awk '{ print $2}')
if [[ "$pidname" = "qemu-kvm" || "$pidname" = "qemu-system-x86" ]]; then
guestname="$(strings -a /proc/${pid}/cmdline |egrep -A1 -i '^-name'|sed -e 's@,debug.*@@' -e 's@guest=@@'|tail -1)"
else
guestname=""
fi
printf "${PRINT_PATTERN}" "${pidname} [ ${guestname} ]" "(${pid})" "${size}" "${unit}"
fi
index=1
done)|sort -u
fi
else
printf "#### No 1Gb HugePages found!\n"
fi