Interpreting vmstat (virtual memory and system statistics)

I was asked about vmstat recently and didn’t know as much as I should.  I’m writing a brief post to help myself learn it a little more.

Here’s an excerpt of the manual:

vmstat.png

So what can you do with vmstat?  If you run it without specifying any parameters, it gives you an average view of virtual memory and system usage since your last reboot.

If you run it with the 1 parameter (vmstat 1), it runs (and re-measures) every 1 second, until you break out of it:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 3  0      0  44712 110052 623096    0    0    30    28  217  888 13  3 83  1  0
 0  0      0  44408 110052 623096    0    0     0     0   88 1446 31  4 65  0  0
 0  0      0  44524 110052 623096    0    0     0     0   84  872 11  2 87  0  0

If you want to see how much memory is swapped in/out from disk, check out the si/so (swapped in/swapped out) columns.

If the amount of memory in the free column is low, you’ll want to check which processes are consuming the most memory.  (with top, for example)

But wait – you can also troubleshoot CPU and disk bottlenecks with vmstat:

For disk bottlenecks, look at the b (blocked) column.  This tells you the number of threads that were blocked/waiting on IO completion.  It should be 0 most of the time, but if it’s not, you can investigate further with iostat.

For CPU bottlenecks, look at the r (run queue) column.  These are the threads that were waiting for a CPU to become available in order to run.  If you see more than 2-5 times the number of CPUs on the system listed in this column, there may be a CPU bottleneck.

For more info, see The Geek Diary’s guide to troubleshooting with vmstat – it’s an excellent resource.  And if you want to know how to run something slightly similar to vmstat on macOS, try vm_stat.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s