Home / Solaris 10 / How to calculate SAR and VMSTAT memory values

How to calculate SAR and VMSTAT memory values

Most of the UNIX beginners are very confused with sar and vmstat outputs.In most of the occasion they are not able to determine the free memory and free swap in order to find the memory bottleneck.Not all the time  “top” command will give right values. Ksar graphical tool also very useful to analysis bottleneck.

SAR:
Now we will see how to calculate free memory and swap
Formula:
Free memory in GB= freemem*pagesize/1024/1024/1024
Free swap in GB=freeswap*512/1024/1024/1024
To find the page size value,
[root@wSolarisN ~]# pagesize
8192

FYI:In x86 pagesize value is 4k and in SPARC its 8k.

As per the above commands output,
Free memory in GB =6917436*8192/1024/1024/1024=52.77GB
Free swap in GB=89634194*512/1024/1024/1024=42.74GB
[root@solarisN~]# sar -r 5 5
SunOS SolarisN 5.10 Generic_147440-09 sun4v 03/12/2013
08:16:18 freemem freeswap
08:16:23 6916895 89225128
08:16:28 6918127 89796122
08:16:34 6917438 89645747
08:16:39 6917972 89797936
08:16:45 6916954 89760317
Average 6917436 89634194

VMSTAT:
vmstat will provide the free memory and free swap in KB .So its very easy to calculate unlike the SAR values.

Formula:
Free memory in GB=value/1024/1024
Free swap in GB=value/1024/1024
Free swap in GB=44905096/1024/1024=42.82GB
Free memory in GB=55305768/1024/1024=52.74GB
[root@solarisN ~]# vmstat 5 5
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr m1 m1 m1 m2 in sy cs us sy id
6 0 0 96425064 87221048 18 63 10 0 0 0 0 4 4 4 81 921 923 908 2 0 98
1 0 0 44907344 55306816 1 6 0 0 0 0 0 0 0 0 0 961 1254 954 0 0 99
3 0 0 44854688 55307016 1 1 0 0 0 0 0 0 0 0 0 945 1216 936 0 0 99
13 0 0 44912064 55312408 1 2 0 0 0 0 0 0 0 0 0 944 1221 943 0 0 99
1 0 0 44905096 55305768 1 2 0 0 0 0 0 0 0 0 0 969 1274 966 0 0 99

Thank you for reading this article.Please leave a comment if you have any doubt ,i will get back to you as soon as possible.
VMTURBO-CLOUD-CAPACITY

12 comments

  1. Free memory in GB=44905096/1024/1024=42.82GB

    what is 1024/1024

    I AM NOT CLEAR ON THAT

  2. VMSTAT values will in KiloBytes. In order to convert those values in to GB = 44905096/1024/1024=42.82GB…

  3. Hi Lingeswaran,

    I want to know the swap calculation
    Free swap in GB=89634194*512/1024/1024/1024=42.74GB

    What is 512 in the above calculation?

  4. good one ..thank you ..

  5. This clears up my doubts getting available free memory.
    Thanks for sharing.

  6. thank you very much
    But I wish to understand some things
    is this true or not ?
    RAM is the Memory
    Swap is a space on the H.D.D to add more memory for OS
    Virtual Memory = swap + RAM
    I have a server [ Solaris Domain] with 256 GB Mem and swap 48 GB
    # prtconf | grep Memory
    Memory size: 260864 Megabytes

    # swap -lh
    swapfile dev swaplo blocks free
    /dev/zvol/dsk/rpool/swap 287,2 8K 48G 48G

    Now when I write
    # swap -sh
    total: 61G allocated + 6.2G reserved = 67G used, 134G available

    I expected that [67G used + 134G available = 201 GB ] equal to [ Memory size 256 + swap -lh 48G = 304 GB]

    why this differance ??

    what exactly swap means ? the total of Mem plus partion on H.D.D or only partion on H.D.D

    thanks

  7. Why my calculation seems different, Please correct me.

    LRUE# /usr/sbin/prtconf | grep -i memory
    prtconf: devinfo facility not available
    Memory size: 10240 Megabytes #Memory size: 10 GB

    LRUE# sar -ru 5 5
    SunOS yosn66 5.10 Generic_144488-05 sun4v 03/04/2015
    12:47:53 freemem freeswap %usr %sys %wio %idle
    12:47:58 2980197 105450576 0 1 0 99
    12:48:03 2980199 105450576 0 1 0 99
    12:48:09 2980168 105450251 1 1 0 98
    12:48:14 2980160 105450186 1 1 0 98
    12:48:19 2980207 105450576 1 1 0 98

    Average 2980185 105450426
    Average 1 1 0 98
    LRUE#

    LRUE# pagesize
    8192

    Now when I calculating it then see what is output-

    Free memory in GB =2980185*8192/1024/1024/1024=22.73GB #how it is possible even I have only total 10 GB RAM
    Free swap in GB=105450426*512/1024/1024/1024=50.28GB

  8. Hi
    below is the vmstat 1 2 output from non global zone ..my zone system is having only 8GB..then why it is showing free memory as 220739616/1024/1024 =210.5137 GB

    Please help me know the memory calculation in this case

    kthr memory page disk faults cpu
    r b w swap free re mf pi po fr de sr s0 s1 s2 s3 in sy cs us sy id
    0 0 0 222348992 224202896 1561 4572 0 0 0 0 0 0 -0 4 4 10306 73687 15355 19 4 77

    0 0 0 218022328 220739616 27 196 0 0 0 0 0 0 0 0 0 17020 69022 28971 31 4 65

Leave a Reply

Your email address will not be published. Required fields are marked *