This content is submitted by a BigAdmin user. It has not been reviewed for technical accuracy by Sun Microsystems, though it may have been lightly edited to improve readability. If you find an error or would like to comment on the article, please contact the submitter or use the comment field at the bottom of the article.
Community submissions may not follow Sun trademark guidelines. For information on Sun trademarks, please see http://www.sun.com/suntrademarks/.
Understanding the Differences Between prstat and vmstat Output in the Solaris OS
Victor Feng, March 2008
As you know, prstat and vmstat are used to check system performance. Sometimes, however, the results returned by prstat show a huge difference from those returned by vmstat.
When this happens, which results should we trust? As a rule of thumb, we should trust the results from vmstat. This article provides the following examples, which show why:
Note: This information applies to systems that run the Solaris 9 or 10 Operating System.
Memory Usage Example
In a system with 8 GB memory, we have Oracle9i Database Enterprise Edition version 9.2.0.7, with maximum memory of about 1 GB and with Oracle shut down.
The vmstat output shows that the system has about 6.1 GB free memory:
# vmstat 3 3
kthr memory page disk faults
cpu
r b w swap free re mf pi po fr de sr m0 m4 m5 m1 in sy
cs us sy id
0 0 0 7189112 5702984 32 46 133 1 1 0 0 0 0 0 0 585 2205
1589 0 1 98
0 0 0 8831928 6112816 0 2 0 0 0 0 0 0 0 0 0 390 1492
1399 0 0 100
0 0 0 8831928 6112816 0 0 0 0 0 0 0 0 0 0 0 418 1599
1469 0 0 100
The prstat output shows that user oracle uses 107 MB of memory:
I wrote a perl script that uses the same logic as prstat -a and shows that
user oracle uses 7.2 GB of memory:
# ./psusedmemorybyuser.pl
User Used Vir Mem Used Phy Mem Percent of Phy Mem
oracle 17478336 7277728 88.839453125
root 2185424 839112 10.24306640625
lp 2920 1352 0.01650390625
feng 22648 14112 0.172265625
daemon 2512 1792 0.021875
cpadmin 2223928 660024 8.05693359375
The prstat command should not simply add up the memory of each process of a user, because many
processes share memory with each other. Let's take a look at process 20078 and see how much memory it really uses:
The additional memory needed for process 20078 is 1,792 Kbytes (Anon), and the rest of the memory is from the
shared memory.
CPU Usage Example
Let's continue by looking at another example, this time for CPU usage on the same system with Oracle running. The
consumecpu.sh script consumes one CPU 100%.
# vmstat 3 3
kthr memory page disk faults
cpu
r b w swap free re mf pi po fr de sr m0 m4 m5 m1 in sy
cs us sy id
0 0 0 7191624 5702752 32 47 133 1 1 0 0 0 0 0 0 584 2204
1588 0 1 98
0 0 0 6991608 5363216 0 2 0 0 0 0 0 0 0 0 0 404 1551
1431 0 0 100
0 0 0 6991608 5363216 0 0 0 0 0 0 0 0 0 0 0 606 1526
1458 0 1 99
#
# ./consumecpu.sh &
[3] 23485
# vmstat 3 3
kthr memory page disk faults
cpu
r b w swap free re mf pi po fr de sr m0 m4 m5 m1 in sy
cs us sy id
0 0 0 7191608 5702728 33 48 133 1 1 0 0 0 0 0 0 584 2206
1588 0 1 98
0 0 0 6991288 5362944 1887 15569 0 0 0 0 0 0 0 0 0 449 35719
2542 16 35 49
0 0 0 6991272 5362880 1895 15633 0 0 0 0 0 0 0 0 0 463 35972
2567 17 33 49
#
# prstat
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
23485 root 1136K 1000K run 0 0 0:00:08 4.3% consumecpu.sh/1
13182 root 1952K 1736K cpu0 59 0 0:00:00 0.1% prstat/1
25955 root 17M 12M sleep 53 2 0:00:11 0.0% ns-httpd/2
So, based on vmstat, consumecpu.sh consumes 50% of the CPU.
But based on prstat, it consumes 4.3% of the CPU.
Here's what the consumecpu.sh script does:
# cat consumecpu.sh
#!/bin/sh
while true
do
:
done
I ran truss to trace the number of system call forks caused by
consumecpu.sh.
As you can see, there are many forks for the while loop in the Bourne shell. These processes
are so short-lived that prstat is not able to capture them.
# vmstat 3 3
kthr memory page disk faults
cpu
r b w swap free re mf pi po fr de sr m0 m4 m5 m1 in sy
cs us sy id
0 0 0 7191304 5702200 33 54 132 1 1 0 0 0 0 0 0 584 2218
1588 0 1 98
0 0 0 6994808 5366080 0 2 0 0 0 0 0 0 0 0 0 469 1567
1464 0 1 99
0 0 0 6994808 5366080 0 2 0 0 0 0 0 0 0 0 0 469 1567
1464 0 1 99
#
# ./consumecpu.sh &
[5] 4066
# vmstat 3 3
kthr memory page disk faults
cpu
r b w swap free re mf pi po fr de sr m0 m4 m5 m1 in sy
cs us sy id
0 0 0 7191344 5702272 33 54 133 1 1 0 0 0 0 0 0 584 2219
1588 0 1 98
0 0 0 6991776 5363040 0 2 0 0 0 0 0 0 0 0 0 453 1628
1448 50 0 50
0 0 0 6991776 5363032 1 0 0 0 0 0 0 0 0 0 0 494 1559
1415 50 0 50
#
# prstat
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
4066 root 2520K 1872K cpu0 30 0 0:01:24 49% consumecpu.sh/1
4068 root 1952K 1728K cpu1 49 0 0:00:00 0.1% prstat/1
20078 oracle 1108M 472M sleep 59 0 0:00:01 0.0% oracle/1
Now both vmstat and prstat show that
consumecpu.sh consumes 49% of the CPU.
Acknowledgements
Thanks to Darren Dunham for his contribution!
Note: This tech tip expands on ideas explored in discussion groups online.
The information and links on this page have been provided by a BigAdmin user. The submitter is solely responsible for such information and links. Sun is not responsible for the availability of external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. Sun will not be responsible or liable, directly or indirectly, for any actual or alleged damage or loss caused by or in connection with use of or reliance on the information posted here, or goods or services available on or through any external site or resource.
Comments (latest comments first)
Discuss and comment on this resource in the BigAdmin Wiki
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License.