hw-test/scripts/scan-meminfo

97 lines
2.4 KiB
Text
Raw Normal View History

#!/bin/bash
if [[ -z $OUTPUT_DIR ]] ; then
source scan-dmidecode
fi
cat /proc/meminfo > $OUTPUT_DIR/meminfo
2016-12-23 02:41:53 -06:00
MEM_RESERVED=64 #MB
MEM_AVAILABLE=`cat /proc/meminfo \
| grep '^MemAvailable' \
| grep 'kB' \
| cut -d ':' -f 2 \
| sed 's/[^0-9]\+//g'`
#echo "MEM_AVAILABLE: $MEM_AVAILABLE"
#MEM_AVAILABLE=
2016-12-13 19:52:26 -06:00
if [[ -z $MEM_AVAILABLE ]] ; then
MEM_FREE=`cat /proc/meminfo \
| grep '^MemFree:' \
2016-12-13 19:52:26 -06:00
| grep 'kB' \
| cut -d ':' -f 2 \
| sed 's/[^0-9]\+//g'`
MEM_BUFF=`cat /proc/meminfo \
| grep '^Buffers:' \
| grep 'kB' \
| cut -d ':' -f 2 \
| sed 's/[^0-9]\+//g'`
MEM_RECL=`cat /proc/meminfo \
| grep '^SReclaimable:' \
| grep 'kB' \
| cut -d ':' -f 2 \
| sed 's/[^0-9]\+//g'`
MEM_SHM=`cat /proc/meminfo \
| grep '^Shmem:' \
| grep 'kB' \
| cut -d ':' -f 2 \
| sed 's/[^0-9]\+//g'`
MEM_CACH=`cat /proc/meminfo \
| grep '^Cached:' \
| grep 'kB' \
| cut -d ':' -f 2 \
| sed 's/[^0-9]\+//g'`
if [[ -z $MEM_FREE ]] ; then
echo "Error: Could not parse /proc/meminfo for MemFree" >&2
exit 4
fi
if [[ -z $MEM_BUFF ]] ; then
echo "Error: Could not parse /proc/meminfo for Buffers" >&2
exit 5
fi
if [[ -z $MEM_RECL ]] ; then
echo "Could not parse /proc/meminfo for SReclaimable" >&2
MEM_RECL=0
fi
if [[ -z $MEM_SHM ]] ; then
echo "Could not parse /proc/meminfo for Shmem" >&2
MEM_SHM=0
fi
if [[ -z $MEM_CACH ]] ; then
echo "Error: Could not parse /proc/meminfo for Cached" >&2
exit 6
fi
echo "MEM_FREE: $MEM_FREE"
echo "MEM_BUFF: $MEM_BUFF"
echo "MEM_RECL: $MEM_RECL"
echo "MEM_SHM: $MEM_SHM"
echo "MEM_CACH: $MEM_CACH"
# MEM_AVAILABLE=$(( MEM_FREE + MEM_BUFF + MEM_CACH ))
# echo "MEM_AVAILABLE: $MEM_AVAILABLE"
MEM_AVAILABLE=$(( MEM_FREE + MEM_RECL - MEM_SHM + MEM_CACH ))
# echo "MEM_AVAILABLE: $MEM_AVAILABLE"
2016-12-13 19:52:26 -06:00
fi
echo "MEM_AVAILABLE: $MEM_AVAILABLE"
2016-12-13 19:52:26 -06:00
if [[ -z $MEM_AVAILABLE ]] ; then
echo "Error: Could not parse /proc/meminfo for available memory" >&2
exit 2
fi
MEM_TESTABLE=$(( MEM_AVAILABLE - (MEM_RESERVED * 1024) ))
if (( $MEM_TESTABLE < 1024 )) ; then
echo "Testable memory $MEM_TESTABLE lower than 1 MB. Exiting" >&2
exit 3
fi
2016-12-21 22:42:56 -06:00
# TODO: Hardcoded values for Debug. Please comment them out for production.
2016-12-14 19:45:04 -06:00
# Hardcoded 13 GiB for debug
#MEM_TESTABLE=13631488
# Hardcoded 13 MiB for debug
2016-12-21 23:24:52 -06:00
#MEM_TESTABLE=16384
2016-12-14 19:45:04 -06:00
# Hardcoded 130 MiB for debug
2016-12-23 03:42:14 -06:00
#MEM_TESTABLE=163840
2016-12-13 19:52:26 -06:00
export MEM_TESTABLE
echo "$MEM_AVAILABLE kB available in system"
2016-12-13 19:52:26 -06:00
echo "$MEM_TESTABLE kB usable for memtester"