Pages

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
31849.26171875000000000000

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
31872.00000000000000000000

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

# mkdir -p /usr/local/sbin
# vi /usr/local/sbin/free.sh
#!/bin/ksh
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/free.sh
# free.sh
Avai Mem: 31.125 GB
Free Mem: .0292 GB
Used Mem: 31.0958 GB

1 comment:

  1. Memory is in 4K blocks on 256MB segments as stated. You can see this when running "svmon -G", there will be a page size stanza right at the end. The line starting "s" is for "small" (or standard) memory blocks, "m" for medium (64 k blocks). If you multiply out by these numbers then you math will all work out...

    ie 1 medium block is worth 16 small blocks. If you multiple m blocks by 16 and add that to the number of s blocks you get the same number as is in the "memory" line.

    ReplyDelete