This article provides information on how to monitory the Virtual Memory by using the vmsat command.
Usage of vmstat for troubleshooting:
- Identifying high CPU usage.
- Monitoring the Virtual Memory in real-time.
- Monitoring the system performance.
The vmstat command, as its name suggests, reports the virtual memory statistics. It shows how much virtual memory is present, how much is free, and paging activity. Most importantly, it prints page-ins and page-outs, as they occur.
To monitor the virtual memory activity on your system, it is best to use vmstat with a delay. A delay is the number of seconds between updates. Five seconds is the recommended delay interval. By default, vmstat displays the following information just once:
procs Information about the numbers of processes in various states.
procs Information about the numbers of processes in various states. r in run queue b blocked for resources (I/O, paging, etc.) w runnable or short sleeper (< 20 secs) but swapped memory Information about the usage of virtual and real memory. Virtual pages (reported in units of 1024 bytes) are considered active if they belong to processes which are running or have run in the last 20 seconds. avm active virtual pages fre size of the free list page Information about page faults and paging activity. These are averaged each five seconds, and given in units per second. flt page faults re page reclaims (simulating reference bits) at pages attached (found in free list) pi pages paged in po pages paged out fr pages freed sr pages scanned by clock algorithm disks Disk transfers per second. Typically paging will be split across the available drives. The header of the field is the first character of the disk name and the unit number. If more than two disk drives are configured in the system, vmstat displays only the first two drives. To force vmstat to display specific drives, their names may be supplied on the command line. traps Trap/interrupt rate averages per second over last 5 seconds. in device interrupts per interval (including clock interrupts) sy system calls per interval cs CPU context switch rate (switches/interval) cpu Breakdown of percentage usage of CPU time. us user time for normal and low priority processes sy system time id CPU idle
To monitor the virtual memory activity on your system, it is best to use vmstat with a delay. A delay is the number of seconds between updates. If you do not provide a delay, vmstat will report the averages from the last boot and quit. Five seconds is the recommended delay interval.
The command has to be issued from the shell, as shown below:
>start shell
To run vmstat with a five second delay, type:
vmstat 5 % vmstat 5 procs memory page disks faults cpu faults cpu r b w avm fre flt re pi po fr sr da0 da1 in sy cs us sy id 0 0 0 1152944 1570444 73 0 2 0 37 0 0 0 297 1259 1052 0 1 99 1 0 0 1152944 1570444 2 0 0 0 0 0 0 0 292 1247 1040 0 1 99 ^C
To stop the vmstat process, use the break character (^C or Control+C), as shown above.
You can specify a count, which indicates how many updates should be printed; before vmstat quits. If the count is not explicitly mentioned, the count defaults to infinity; but the same can be terminated with Ctrl-C.
To run vmstat with ten updates, five seconds apart, type:
vmstat 5 10 % vmstat 5 10 procs memory page disks faults cpu faults cpu r b w avm fre flt re pi po fr sr da0 da1 in sy cs us sy id 0 0 0 1152944 1570444 73 0 2 0 37 0 0 0 297 1259 1052 0 1 99 1 0 0 1152944 1570444 5 0 0 0 0 0 0 0 287 1062 988 0 1 99 0 0 0 1152944 1570444 1 0 0 0 0 0 0 0 291 1240 1038 0 1 99 0 0 0 1152944 1570444 8 0 0 0 0 0 0 0 292 1056 976 0 0 99 0 0 0 1152944 1570444 4 0 0 0 1 0 0 0 295 1299 984 0 1 99 0 0 0 1152944 1570444 1 0 0 0 0 0 0 0 290 1110 1082 0 1 99 0 0 0 1152944 1570444 8 0 0 0 0 0 0 0 291 1225 980 0 1 99 0 0 0 1152944 1570444 4 0 0 0 0 0 0 0 295 1081 986 0 0 100 0 0 0 1152944 1570444 1 0 0 0 2 0 0 0 305 1257 1051 0 1 99 0 0 0 1152944 1570444 4 0 0 0 0 0 0 0 290 1053 996 0 1 99 % vmstat -s
The summary option (-s) sends a summary report in the standard output, starting from system initialization expressed in absolute counts; rather than on an interval basis.
% vmstat -s 12903099 cpu context switches 3665631 device interrupts 72097 software interrupts 16026455 traps 15281783 system calls 69 kernel threads created 1491 fork() calls 170 vfork() calls 0 rfork() calls 0 swap pager pageins 0 swap pager pages paged in 0 swap pager pageouts 0 swap pager pages paged out 22351 vnode pager pageins 22412 vnode pager pages paged in 776 vnode pager pageouts 6208 vnode pager pages paged out 0 page daemon wakeups 0 pages examined by the page daemon 4814 pages reactivated 108232 copy-on-write faults 5 copy-on-write optimized faults 135800 zero fill pages zeroed 128705 zero fill pages prezeroed 150 intransit blocking page faults 746748 total VM faults taken 0 pages affected by kernel thread creation 287160 pages affected by fork() 33669 pages affected by vfork() 0 pages affected by rfork() 376397 pages freed 0 pages freed by daemon 164165 pages freed by exiting processes 83678 pages active 14643 pages inactive 19115 pages in VM cache 15894 pages wired down 375457 pages free 4096 bytes per page 0 swap pages used 0 peak swap pages used 897154 total name lookups cache hits (94% pos + 4% neg) system 0% per-directory deletions 0%, falsehits 0%, toolong 0% %
The recommended way to use these statistics is to run this command before a workload, save the output, run it again after the workload, and save the output. The next step is to determine the difference between the two sets of output.