Free, vmstat monitoring of memory usage

Source: Internet
Author: User

9. Free Query available memory

The free tool is used to view the system's available memory:

/opt/app/tdev1$free       Total used       free     shared    buffers     cachedmem:       8175320    6159248    2016072          0     310208    5243680-/+ buffers/cache:     605360    7569960Swap:      6881272      16196    6865076

Explain the output of the free command on Linux.

Here is the result of the free run, with a total of 4 rows. For convenience, I added a column number. This can be seen as a two-dimensional array fo (free output). For example:

FO[2][1] = 24677460fo[3][2] = 10321516                   1          2          3          4          5          all       used     free Shared    buffers     cached2 Mem:      24677460   23276064    1401396          0     870540   120840083-/+ buffers/cache:   10321516   143559444 Swap:     25151484     224188   24927296

The output of free has a total of four lines, the fourth behavior Swap area information, which is the total amount of the exchange, the amount of usage (used), and the number of idle swap areas, which are relatively clear, not too much.

The second and third rows in the free output are confusing. Both of these lines describe memory usage. The first column is total, the second column is the usage (used), and the third column is the available amount (free).

The first line of output is viewed from the operating system (OS). That is, from the OS point of view, the computer has a total of:

24677460KB (the default is KB of free) physical memory, or fo[2][1]; 23276064KB (i.e. fo[2][2]) is used in these physical memory, and 1401396KB (that is, fo[2][3]) is available;

Here we get the first equation:

FO[2][1] = fo[2][2] + fo[2][3]

FO[2][4] indicates that the memory that is shared by several processes is now deprecated, and its value is always 0 (it may not be 0 on some systems, depending on how the free command is implemented).

FO[2][5] represents the memory that is trapped by the OS buffer. FO[2][6] Indicates the memory of the OS cache. In some cases, the two words buffer and cache are often mixed. But in some low-level software is to distinguish between the two words, look at the foreigner's Foreign Language:

A buffer is something that have yet to being "written" to disk. A cache is something that have been "read" from the disk and stored for later use.

That is, buffer is used to store the data to be output to disk (block device), and the cache is to store the data read from disk. Both are designed to improve IO performance and are managed by the OS.

Linux and other mature operating systems (such as Windows), in order to improve the performance of IO read, always have to cache some data, which is why Fo[2][6] (cached memory) is relatively large, and fo[2][3] relatively small reason. We can do a simple test:

Release the data that was consumed by the system cache:

Echo 3>/proc/sys/vm/drop_caches
    1. Read a large file and record the time;
    2. Close the file;
    3. Reread the large file and record the time;

The second reading should be much faster than the first time. Originally I did a berkeleydb read operation, about to read 5G files, tens of millions of records. In my environment, the second reading is about 9 times times faster than the first time.

The second line of the free output is the use of system memory from an application perspective.

    • For fo[3][2], or-buffers/cache, indicates how much memory an application thinks the system is using;
    • For fo[3][3], or +buffers/cache, indicates how much memory an application thinks the system has;

Because the memory consumed by the system cache and buffer can be quickly recycled, fo[3][3] is usually much larger than fo[2][3].

It also uses two equations:

FO[3][2]=FO[2][2]-fo[2][5 Span class= "o" >-fo[2][6]fo[3][3 ] = fo[2][3 + fo[2 ][5 + fo[2][6]         

Both are not difficult to understand.

The free command is provided by PROCPS.*.RPM (on the OS of the Redhat series). All output values of the free command are read from the/proc/meminfo.

There may be meminfo (2) This function on the system, it is to parse/proc/meminfo. Procps This package itself implements the Meminfo () function. You can download a Procps tar package to see the specific implementation, now the latest layout 3.2.8.





vmstat Monitoring of memory usage

Vmstat is an abbreviation for virtual meomory Statistics (dummy memory statistics) that dynamically monitors the operating system's virtual memory, processes, and CPU activity in real time.

10.1. Vmstat's Syntax

Vmstat [-v] [-n] [delay [count]]

  • -V indicates that the version information is printed;
  • -n means that the output header information is displayed only once during cyclic output;
  • Delay is the lag time between two outputs;
  • Count refers to the number of times that are counted at this interval.
/root$vmstat 5 5procs-----------memory-------------Swap-------io------System-------CPU-----r  B   swpd   Free   buff  cache   si   so    bi    bo   in   CS US sy ID wa st6  0      0 27900472 204216 28188356    0    0     0     9    1    2      each of 0, 0 0 27900380 204228 28188360    0    0     0    33312 126221  0      0 0 27900340 204240 28188364    0    0     0    32755 125566  0  0
10.2. Field Description
Procs (Process):
  • R: Number of processes in the running queue
  • B: Number of processes waiting for IO
Memory (RAM):
  • SWPD: Using virtual memory size
  • Free: Available memory size
  • Buff: The amount of memory used as a buffer
  • Cache: The amount of memory used as a buffer
Swap:
  • Si: Write to memory size per second from swap area
  • So: The amount of memory written to the swap area per second
IO: (now the size of the Linux version block is 1024bytes)
  • BI: Number of blocks read per second
  • Bo: Number of blocks written per second
System
  • In: Number of interrupts per second, including clock interrupts
  • CS: Number of context switches per second
CPU (expressed as a percentage)
  • US: User Process Execution Time
  • SY: System Process Execution time
  • ID: Idle time (including IO wait time)
  • WA: Waiting for IO time




Free, vmstat monitoring of memory usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.