|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
Softpanorama Search
|
| News | Recommended Books | Recommended Links | Linux | Solaris | Linux Performance Tuning | |
| netstat | iostat | uptime command | sar | Unix top command | Etc |
The first tool to use for locating performance bottlenecks is the vmstat command. It provides compact table-based snapshort of various system resources utilization. These reports are intended to help identify system bottlenecks. vmstat does not count itself as a running process. For analysis of long intervals output from sar might be a good alternative. In both cases one can pipe output into Perl script to produce alerts. For example if a Linux 2.6 server demonstrated strange behavior with uptime averages above 7 (case that happened to the author): this threshold can trigger collecting vmstat or sar information and piping it into Perl script for detailed analysis.
If the vmstat command is used without any options, it reports the current set of statistics and exits. If a single numeric argument T is supplied it is assumed to be an interval (in seconds) between iterations of the report and vmstat runs in a loop outputting the statistics each T seconds. Optionally the second numerical parameter can be specified which provides the number of iterations of the time loop. For example vmstat 2 10 means output statistics each 2 sec and make 10 iterations before existing.
vmstat reports virtual memory statistics regarding kernel thread, virtual memory, disk, trap, and CPU activity. Traditionally those parts of the table have headers
On MP (multi-processor) systems, vmstat averages the number of CPUs into the output. For per-processor statistics, see mpstat(1M). vmstat only supports statistics for certain devices. For more general system statistics, you can also use e sar and iostat. command.
Without options, vmstat displays a one-line summary of the virtual memory activity since the system was booted.
vmstat [-cipqsS] [disks] [interval[count]]
The output from the Solaris vmstat command without options is:
procs memory page disk faults cpu r b w swap free re mf pi po fr de sr f0 s1 s2 s3 in sy cs us sy id 0 0 0 15020 4304 9 58 198 228 220 0 3 0 16 1 1 86 1173 46 24 30 46
procs reports on process states. r is the number of processes in the run queue. b is the number of processes blocked and waiting for resources such as disk or terminal input. w is the number of runnable processes, or processes swapped but in a sleep state of less than twenty seconds.
Under the memory heading statistics are given on the usage of real and virtual memory. swap reports the available swap space in Kilobytes. free gives the size of the free list.
Under the page heading, page faults and page activity is reported in units per second. Page faulting occurs when the system attempts to access an unmapped page. Statistics are reported as follows:
disk lists the number of disk operations per second and can show data for up to four disks at a time. Which disks to report can be passed to the vmstat command.
faults reports the trap or interrupt rate per second. in is the number if device interrupts per second. sy is the number of system calls and cs is the CPU context switch rate.
The last group of statistics pertain to CPU usage. The amount of time spent in user mode, kernel mode and idle are reported.
vmstat can also report on swapping and cache flushing. The -S adds two fields to the beginning of the paging statistics. These are si, which lists the number of pages swapped in per second, and so, which gives the number of entire processes swapped out.
vmstat -c displays cache flushing statistics for a virtual cache. The number of cache flushes since the last reboot are listed. The output of this command looks like:
flush statistics: (totals)
usr ctx rgn seg pag par
0 0 0 0 0 0
The cache types listed are:
vmstat -i displays the number of interrupts per device. The output looks like:
interrupt total rate -------------------------------- clock 98080370 100 fdc0 14 0 -------------------------------- Total 98080384 100
Linux novices often find virtual memory mysterious, but with a grasp of the fundamental concepts, it's easy to understand. With this knowledge, you can monitor your system's memory utilization using vmstat and detect problems that can adversely affect system performance.
How Virtual Memory Works
Physical memory—the actual RAM installed—is a finite resource on any system. The Linux memory handler manages the allocation of that limited resource by freeing portions of physical memory when possible.
All processes use memory, of course, but each process doesn't need all its allocated memory all the time. Taking advantage of this fact, the kernel frees up physical memory by writing some or all of a process' memory to disk until it's needed again.
The kernel uses paging and swapping to perform this memory management. Paging refers to writing portions, termed pages, of a process' memory to disk. Swapping, strictly speaking, refers to writing the entire process, not just part, to disk. In Linux, true swapping is exceedingly rare, but the terms paging and swapping often are used interchangeably.
When pages are written to disk, the event is called a page-out, and when pages are returned to physical memory, the event is called a page-in. A page fault occurs when the kernel needs a page, finds it doesn't exist in physical memory because it has been paged-out, and re-reads it in from disk.
Page-ins are common, normal and are not a cause for concern. For example, when an application first starts up, its executable image and data are paged-in. This is normal behavior.
Page-outs, however, can be a sign of trouble. When the kernel detects that memory is running low, it attempts to free up memory by paging out. Though this may happen briefly from time to time, if page-outs are plentiful and constant, the kernel can reach a point where it's actually spending more time managing paging activity than running the applications, and system performance suffers. This woeful state is referred to as thrashing.
Using swap space is not inherently bad. Rather, it's intense paging activity that's problematic. For instance, if your most-memory-intensive application is idle, it's fine for portions of it to be set aside when another large job is active. Memory pages belonging to an idle application are better set aside so the kernel can use physical memory for disk buffering.
Using vmstat
vmstat, as its name suggests, reports virtual memory statistics. It shows how much virtual memory there is, how much is free and paging activity. Most important, you can observe page-ins and page-outs as they happen. This is extremely useful.
To monitor the virtual memory activity on your system, it's best to use vmstat with a delay. A delay is the number of seconds between updates. If you don't supply a delay, vmstat reports the averages since the last boot and quit. Five seconds is the recommended delay interval.
To run vmstat with a five-second delay, type:
vmstat 5You also can specify a count, which indicates how many updates you want to see before vmstat quits. If you don't specify a count, the count defaults to infinity, but you can stop output with Ctrl-C.
To run vmstat with ten updates, five seconds apart, type:
vmstat 5 10Here's an example of a system free of paging activity:
procs memory swap io system cpu r b w swpd free buff cache si so bi bo in cs us sy id 0 0 0 29232 116972 4524 244900 0 0 0 0 0 0 0 0 0 0 0 0 29232 116972 4524 244900 0 0 0 0 2560 6 0 1 99 0 0 0 29232 116972 4524 244900 0 0 0 0 2574 10 0 2 98All fields are explained in the vmstat man page, but the most important columns for this article are free, si and so. The free column shows the amount of free memory, si shows page-ins and so shows page-outs. In this example, the so column is zero consistently, indicating there are no page-outs.
The abbreviations so and si are used instead of the more accurate po and pi for historical reasons.
Here's an example of a system with paging activity:
procs memory swap io system --- cpu --- r b w swpd free buff cache si so bi bo in cs us sy id . . . 1 0 0 13344 1444 1308 19692 0 168 129 42 1505 713 20 11 69 1 0 0 13856 1640 1308 18524 64 516 379 129 4341 646 24 34 42 3 0 0 13856 1084 1308 18316 56 64 14 0 320 1022 84 9 8Notice the nonzero so values indicating there is not enough physical memory and the kernel is paging out. You can use top and ps to identify the processes that are using the most memory.
You also can use top to show memory and swap statistics. Here is an example of the uppermost portion of a typical top report:
14:23:19 up 348 days, 3:02, 1 user, load average: 0.00, 0.00, 0.00 55 processes: 54 sleeping, 1 running, 0 zombie, 0 stopped CPU states: 0.0% user, 2.4% system, 0.0% nice, 97.6% idle Mem: 481076K total, 367508K used, 113568K free, 4712K buffers Swap: 1004052K total, 29852K used, 974200K free, 244396K cached
vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.
The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case.
Options
Procs
Memory
Swap
IO
System
CPU (These are percentages of total CPU time).
Prior to Linux 2.5.41, this includes IO-wait time. wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle. st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
Reads
total: Total reads completed successfully merged: grouped reads (resulting in one I/O) sectors: Sectors read successfully ms: milliseconds spent reading
Writes
total: Total writes completed successfully merged: grouped writes (resulting in one I/O) sectors: Sectors written successfully ms: milliseconds spent writing
IO
cur: I/O in progress s: seconds spent for I/O
reads: Total number of reads issued to this partition read sectors: Total read sectors for partition writes : Total number of writes issued to this partition requested writes: Total number of write requests made for partition
cache: Cache name num: Number of currently active objects total: Total number of available objects size: Size of each object pages: Number of pages with at least one active object totpages: Total number of allocated pages pslab: Number of pages per slab
vmstat does not require special permissions.
These reports are intended to help identify system bottlenecks. Linux vmstat does not count itself as a running process.
All linux blocks are currently 1024 bytes. Old kernels may report blocks as 512 bytes, 2048 bytes, or 4096 bytes.
Since procps 3.1.9, vmstat lets you choose units (k, K, m, M) default is K (1024 bytes) in the default mode
vmstat uses slabinfo 1.1 FIXME
/proc/meminfo /proc/stat /proc/*/stat
iostat(1), sar(1), mpstat(1), ps(1), top(1), free(1)
See System Administration Guide: Advanced Administration for device naming conventions for disks.
The following options are supported:
When executed in a zone and if the pools facility is active, all of the above only report actitivity on the processors in the processor set of the zone's pool.
The following operands are supported:
The following command displays a summary of what the system is doing every five seconds.
example% vmstat 5 kthr memory page disk faults cpu r b w swap free re mf pi p fr de sr s0 s1 s2 s3 in sy cs us sy id 0 0 0 11456 4120 1 41 19 1 3 0 2 0 4 0 0 48 112 130 4 14 82 0 0 1 10132 4280 0 4 44 0 0 0 0 0 23 0 0 211 230 144 3 35 62 0 0 1 10132 4616 0 0 20 0 0 0 0 0 19 0 0 150 172 146 3 33 64 0 0 1 10132 5292 0 0 9 0 0 0 0 0 21 0 0 165 105 130 1 21 78 1 1 1 10132 5496 0 0 5 0 0 0 0 0 23 0 0 183 92 134 1 20 79 1 0 1 10132 5564 0 0 25 0 0 0 0 0 18 0 0 131 231 116 4 34 62 1 0 1 10124 5412 0 0 37 0 0 0 0 0 22 0 0 166 179 118 1 33 67 1 0 1 10124 5236 0 0 24 0 0 0 0 0 14 0 0 109 243 113 4 56 39 ‸Cexample%
The fields of vmstat's display are
swap
When executed in a zone and if the pools facility is active, all of the above (except for “de”) only report activity on the processors in the processor set of the zone's pool.
When executed in a zone and if the pools facility is active, all of the above only report actitivity on the processors in the processor set of the zone's pool.
When executed in a zone and if the pools facility is active, all of the above only report actitivity on the processors in the processor set of the zone's pool.
See attributes(5) for descriptions of the following attributes:
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|---|---|
| Availability | SUNWcsu |
| Interface Stability | See below. |
Invocation is evolving. Human readable output is unstable.
sar(1), iostat(1M), mpstat(1M), sar(1M), attributes(5)
The sum of CPU utilization might vary slightly from 100 because of rounding errors in the production of a percentage figure.
The -c option (Report cache flushing statistics) is not supported in this release.
Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Disclaimer:
Last modified: August 08, 2009