1. We can use free -m to see the memory usage.
free -m
total used free shared buffers cached
Mem: 1900 1882 17 0 192 1445
-/+ buffers/cache: 245 1655
Swap: 2055 28 2026
(unit in MB)
2. The other way is to use vmstat.
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 29332 17912 197088 1479916 0 1 150 50 1 1 2 0 97 0 0
(unit in KB)
3. or we can stat the information under /proc.
/proc/slabinfo: memory used by slab by linux kernel
/proc/meminfo: memory used by struct page by kernel in each page
/proc/$pid/stam: memory used by RSS (resident set size, physic memory, not virtual memory)
/proc/$pid/smaps: shared memory of a process
Here is a simple shell script to stat these information.
------------------------------------------------
#!/bin/sh
#memory used by resident set size (physic memory, not virtual memory)
for PROC in `ls /proc/ | grep '^[0-9]'`
do
if test -f /proc/$PROC/statm; then
MEM=`cat /proc/$PROC/statm | awk '{print $2}'`
RSS=`expr $RSS + $MEM`
fi
done
RSS=`expr $RSS \* 4`
echo "RSS: $RSS kB"
#memory used by slab by linux kernel
SLAB=`cat /proc/slabinfo | grep -v '# name' | grep -v 'slabinfo - version' | awk '{s+=$3*$4} ;END {print s/1024}'`
echo "SLAB: $SLAB kB"
#memory used by struct page by kernel in each page
PAGETABLE=`cat /proc/meminfo | grep PageTables | awk '{print $2}'`
echo "PAGETABLE: $PAGETABLE kB"
TOTAL=`expr $RSS + $SLAB + $PAGETABLE`
echo "---------total:$TOTAL kB"