OS Memory Usage   «Prev  Next»
Lesson 4Using vmstat to infer memory usage
ObjectiveCheck the vmstat run queue.

Identifying CPU Bottlenecks with vmstat

The vmstat utility is very useful for detecting memory problems. As the UNIX OS performs memory management, UNIX keeps internal statistics about the rate of page-out and page-in operations from RAM memory. The vmstat utility displays these memory structures and shows the internals of memory activity.

Memory usage: the “r” and “pi” columns

For memory usage, we are primarily interested in only two columns: the run queue “r” and the page-in column “pi.” Whenever we experience a non-zero value for pi, we know that our server is swapping memory. Memory paging slows down Oracle transactions, and this is often reflected in the run queue r column. If the value of the r column exceeds the number of CPUs on your server, and you do not have CPU bottlenecks (where us plus sy equals 100) then you may be waiting for memory.
The following diagram contains information with respect to the vmstat output.

memory-column
  1. Kernel thread data including r run queue.
  2. Includes average memory avm, free memory free
  3. Includes retained memory re, page-in pi, and page-out po
  4. Includes user CPU us, system CPU sy, idle CPU id, and wait CPU wa

To receive a vmstat listing for each second, use the command below. As illustrated, a new output line appears each second after the vmstat command.
vmstat
vmstat

In the case above, we see that we are not experiencing memory swapping because the pi column is zero.
Values in the r column (OS run queue) indicate tasks waiting for service. This could be due to memory bottlenecks, but could also be due to CPU or disk I/O waits. Whenever the r (run queue) column exceeds the number of CPUs on your server, you are experiencing a bottleneck because tasks are waiting for service. If high run queue values are seen in conjunction with high page-in operations, you may have a memory problem.
The next lesson shows how to track OS statistics.

vmstat to Infer Memory Usage - Exercise

Before moving on to the next lesson, click the Exercise link below to test your ability to manage OS memory.
vmstat to Infer Memory Usage - Exercise