95 lines
2.3 KiB
Bash
Executable file
95 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
if [[ -z $OUTPUT_DIR ]] ; then
|
|
source scan-dmidecode
|
|
fi
|
|
|
|
cat /proc/meminfo > $OUTPUT_DIR/meminfo
|
|
|
|
MEM_RESERVED=256 #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=
|
|
if [[ -z $MEM_AVAILABLE ]] ; then
|
|
MEM_FREE=`cat /proc/meminfo \
|
|
| grep '^MemFree:' \
|
|
| 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"
|
|
fi
|
|
echo "MEM_AVAILABLE: $MEM_AVAILABLE"
|
|
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
|
|
# Hardcoded 13 GiB for debug
|
|
#MEM_TESTABLE=13631488
|
|
# Hardcoded 13 MiB for debug
|
|
MEM_TESTABLE=16384
|
|
# Hardcoded 130 MiB for debug
|
|
#MEM_TESTABLE=163840
|
|
export MEM_TESTABLE
|
|
|
|
echo "$MEM_AVAILABLE kB available in system"
|
|
echo "$MEM_TESTABLE kB usable for memtester"
|
|
|
|
|
|
|