Tuesday, January 3, 2012

Available, used and free memory in AIX

Use lsattr to get the size of your memory:

# lsattr -E -l sys0 | grep realmem
realmem         32636928           Amount of usable physical memory in Kbytes        False

Or prtconf:

# prtconf -m
Memory Size: 31872 MB

lsattr will show your memory size in KB while prtconf will show it in MB. Much more interesting is the current usage of the memory. You can see it with svmon:

# svmon -G
               size      inuse       free        pin    virtual
memory      8159232    8153411       5821    3572893    8143413

The second value (8153411) is the current used memory. To read it right you have to know that AIX divides the memory in 256MB segments. That means that you have to divide the value by 256 to see the correct value in MB:

# echo 8153411/256 | bc -l

You can do the same with the first value, it will show the size of your memory in MB again which will be same value like prtconf above:

# echo 8159232/256 | bc -l

Here is a small script that will show your memory in GB:

# mkdir -p /usr/local/sbin
# vi /usr/local/sbin/
memory=`prtconf -m | awk 'BEGIN {FS=" "} {print $3/1024}'`
usedmem=`svmon -G | grep memory | awk 'BEGIN {FS=" "} {print $3/256/1024}'`
freemem=`echo $memory-$usedmem | bc -l`

# Conclusion
echo "Avai Mem: $memory GB"
echo "Free Mem: $freemem GB"
echo "Used Mem: $usedmem GB"

Make it executable and run it (make sure that /usr/local/sbin is in your path):

# chmod 755 /usr/local/sbin/
Avai Mem: 31.125 GB
Free Mem: .0292 GB
Used Mem: 31.0958 GB