View examples of virtual memory vmstat-

Virtual Memory operating principle

Each process running on the system require the use of memory, but not all the time each process requires the use of system memory allocation. When the desired memory than the actual physical memory to run the system, the kernel will release some processes some or all of physical memory occupied but not used, this part of the data stored until the next time the process of calling on the disk, and the release of memory there is a need to provide a process to use.

In the Linux memory management, primarily to the completion of the above-mentioned memory scheduling by "paging Paging" and "swap Swapping". Paging algorithm is the most recent pages in memory do not use the change to disk, the process is reserved for the active page in memory use. Switching technology is the whole process, rather than part of the page, all swap to disk.

Process tab (Page) written to disk is referred Page-Out, tab (Page) back to memory from disk process called Page-In. When the kernel needs a tab, but this was found not in the paged physical memory (as it has been the Page-Out), an error page (Page Fault) occurs at this time.

When found to be operating system kernel memory becomes small, it will be part of the physical memory is released by the Page-Out. Page-Out administered not happen often, but if Page-out frequently occurs constantly, until when the kernel manages paging for longer than the time to run the program, system performance would drop dramatically. Then the system has been running very slow or enter a suspended state, this state was also known as thrashing (bumps).

Use vmstat

1. Usage

vmstat [-a] [-n] [-S unit] [delay [ count]]

vmstat [-s] [-n] [-S unit]

vmstat [-m] [-n] [delay [ count]]

vmstat [-d] [-n] [delay [ count]]

vmstat [-p disk partition] [-n] [delay [ count]]

vmstat [-f]

vmstat [-V]

-a: display active and inactive memory

-f: display the number of fork has started from the system.

-m: display slabinfo

-n: display only once at the beginning of each field name.

-s: display memory-related statistics and the number of a variety of system activity.

delay: refresh interval. If not specified, displays only a result.

count: refreshes. If you do not specify refresh times, but specifies the refresh interval, then refresh the number is infinite.

-d: show disk-related statistics.

-p: display the specified disk partition statistics

-S: display the specified units. Parameters k, K, m, M, representing 1000,1024,1000000,1048576 bytes (byte). The default unit is K (1024 bytes)

-V: vmstat display version information.

Examples

     Example 1 : 2 each output a second result

 

Field Description:

Procs (processes):

r: the number of running and wait (CPU time slice) process running, this value needs to be increased may be determined whether CPU (long greater than 1)

b: the number of IO waiting process, the number of processes in uninterruptible state, a common situation is caused by the IO

Memory (RAM):

swpd: using virtual memory size, the memory switch to swap memory (in KB default)

If the value is not 0 swpd, or relatively large, such as more than 100M, but the value si, so long as 0, in which case we can not worry about, without affecting system performance.

free: free physical memory

buff: a buffer memory size as

cache: cache memory size, the file system is used as a cache, if the value of the cache of the big time, indicating that the file cache to live a few more, if frequently accessed files to the cache can be live, so the disk read IO bi will be very small

Swap

si: writes per second from the swap memory size, swap memory usage, disk into memory by the

so: write memory size per second swap, swap memory usage, disk transferred from the memory

When enough memory, these two values ​​are 0, if these two long-term value greater than 0, the system performance will be affected. Disk IO and CPU resources will be consumed.

Often when people see the free memory (free) little or close to zero, it is considered not enough memory, and in fact can not look at this point, but also with si, so, very few if free, but si, so also very few (most of the time is 0), then do not worry, then the system performance will not be affected.

IO :( Linux is now the size of the version of the block is 1024 bytes )

bi: number of blocks read per second, the amount of data from the block device read (Read Disk) (KB / s)

bo: number of blocks per second write data is written to a block device Prime (write to disk) (KB / s)

When random disk reads and writes, the two larger value (e.g., beyond 1M), the CPU can see the value IO wait will be greater

system

in: the number of interrupts per second, including the clock interrupts.

cs: the number of context switches per second.

The larger the above two values, see CPU time consumed by the kernel will be more

The CPU (expressed as a percentage):

us: user process consumes percentage of CPU time, the value of us is relatively high, indicating that the user process consumes CPU time and more, but if more than 50% of long-term use, then we should consider the optimization algorithm or program to accelerate the

sy: kernel process consumes CPU time percentage of high value sy, indicating more CPU resources consumed by the system kernel, this is not healthy performance, we should examine the reasons.

id: CPU percentage of time in idle state (including latency IO)

wa: IO wait CPU time consumed percentage of high value wa, indicating more serious IO wait, this may be due for a large number of random disk access caused, there may be a disk bottleneck bandwidth (block operation).

Example 2 : Display active and inactive memory

    

When you use the -a option to display active and inactive memory, what is displayed in addition to the increase inact and active, the same as other display content example 1.

Field Description:

Memory (RAM):

inact: Inactive memory size (displayed when using the -a option)

active: active memory size (displayed when using the -a option)

NOTE: If r is often greater than 4, often less than 40 and id, denotes the cpu load is heavy, if bi, bo long not equal to 0, indicates insufficient memory, if the disk is often not equal to 0, and b is in the queue is greater than 3 indicating poor io performance.

CPU Description:

1) If the running processes in sequence (process r) is continuously greater than the CPU in the system represents the number of the system is now running more slowly, a majority of processes waiting CPU.

2.) If the number of output r of more than 4 times the number of available CPU system, then the system CPU problem facing a shortage or a low rate of the CPU, the system waits for a majority of the CPU process, resulting in the system the process is running too slow.

3.) If the idle time (cpu id) continued to zero and the system time (cpu sy) is twice the user time (cpu us) systems are faced with a shortage of CPU resources.

Solution:

When these problems occur, please adjust the application of the CPU occupancy. Allows the application to more efficient use of CPU. At the same time consider adding more CPU. On CPU usage can also be combined mpstat, ps aux top prstat -a so some of the appropriate commands to consider regarding the use of a specific CPU, and those processes consume a lot of CPU time. under normal circumstances, the question of the application will be relatively large number, such as some SQL statements unreasonable and so on It will cause such a phenomenon.

Memory Problems phenomenon:

Memory bottleneck is .scan rate by the scan rate (sr) is carried out to determine the page scanning algorithm by always per second. If the scan rate (sr) is greater than 200 per second continuously indicates the presence of possible defects in the memory. Also If the page entry of both pi and po columns indicate the number of pages per second transferred to the page and bring up the pages per second. If the value is often a non-zero value, it is also possible bottlenecks of memory, of course, if when the individual is not 0, then the page is a normal scheduling this is the main principle of virtual memory.

Solution:

1. Adjust applications & servers so that the use of cache memory and more effective.

2. Increase the memory system.

3. Implement priority paging in s in pre solaris 8 versions by adding line "set priority paging=1" in

/etc/system. Remove this line if upgrading from Solaris 7 to 8 & retaining old /etc/system file.

About memory usage may also bear ps aux top prstat -a so some of the appropriate commands to consider with regard to the specific memory usage, and those processes consume a lot of memory. In general, if the memory usage comparison high, however, very low CPU occupancy, they can consider there are many applications that take up memory is not released, however, it did not take up CPU time, consider an application for CPU time and some of the background unoccupied program, release the memory occupied

Case

     Case study:

1: In this example, the system is underutilized

# vmstat 1

procs                      memory      swap          io     system         cpu

r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy wa id

3  0 206564  15092  80336 176080    0    0     0     0  718    26 81 19  0  0

2  0 206564  14772  80336 176120    0    0     0     0  758    23 96  4  0  0

1  0 206564  14208  80336 176136    0    0     0     0  820    20 96  4  0  0

1  0 206956  13884  79180 175964    0  412     0  2680 1008    80 93  7  0  0

2  0 207348  14448  78800 175576    0  412     0   412  763    70 84 16  0  0

2  0 207348  15756  78800 175424    0    0     0     0  874    25 89 11  0  0

1  0 207348  16368  78800 175596    0    0     0     0  940    24 86 14  0  0

1  0 207348  16600  78800 175604    0    0     0     0  929    27 95  3  0  2

3  0 207348  16976  78548 175876    0    0     0  2508  969    35 93  7  0  0

4  0 207348  16216  78548 175704    0    0     0     0  874    36 93  6  0  1

4  0 207348  16424  78548 175776    0    0     0     0  850    26 77 23  0  0

2  0 207348  17496  78556 175840    0    0     0     0  736    23 83 17  0  0

0  0 207348  17680  78556 175868    0    0     0     0  861    21 91  8  0  1

According to the observations, we can get the following conclusions:

1. There are a large number of interrupts (in) and fewer context switches (cs). This means that a single process to generate requests for hardware devices.

2 further shows a single application, user time (us) often 85% or more. Considering fewer context switches, the application will be processed by the processor also.

3. Run queue still within an acceptable range of properties, including two places, is outside the allowable limits.

2: In this example, the context switching in the kernel scheduler at saturation

# vmstat 1

procs                      memory      swap          io     system         cpu

r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy wa id

2  1 207740  98476  81344 180972    0    0  2496     0  900  2883  4 12 57 27

0  1 207740  96448  83304 180984    0    0  1968   328  810  2559  8  9 83  0

0  1 207740  94404  85348 180984    0    0  2044     0  829  2879  9  6 78  7

0  1 207740  92576  87176 180984    0    0  1828     0  689  2088  3  9 78 10

2  0 207740  91300  88452 180984    0    0  1276     0  565  2182  7  6 83  4

3  1 207740  90124  89628 180984    0    0  1176     0  551  2219  2  7 91  0

4  2 207740  89240  90512 180984    0    0   880   520  443   907 22 10 67  0

5  3 207740  88056  91680 180984    0    0  1168     0  628  1248 12 11 77  0

4  2 207740  86852  92880 180984    0    0  1200     0  654  1505  6  7 87  0

6  1 207740  85736  93996 180984    0    0  1116     0  526  1512  5 10 85  0

0  1 207740  84844  94888 180984    0    0   892     0  438  1556  6  4 90  0

According to the observations, we can get the following conclusions:

1. The number of context switches than the number of interrupts, indicating a considerable amount of time kernel are thread context switching overhead.

2. A large number of context switches causes the CPU utilization rate category are not balanced. Obvious percentage actually wait (wa) io request is very high, and very low percentage of user time (US).

3. Because the CPU is blocked on IO requests, so the run queue where there are a significant number of runnable threads waiting to execute.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11108990.html