Linux performance monitoring: Memory

Source: Internet
Author: User

The "Memory" mentioned here includes physical Memory and Virtual Memory, Virtual Memory) to extend the computer's Memory space to the hard disk, physical Memory RAM) and a part of the hard disk space SWAP) the combination of virtual memory provides a consistent virtual memory space for the computer. The advantage is that the memory we have is "more" and can run more and more programs, the disadvantage is that when the memory usage of some hard disks is affected, the read/write speed of the hard disks is several orders of magnitude slower than that of the memory, and the exchange between RAM and SWAP increases the burden on the system.

In the operating system, the virtual memory is divided into pages. On the x86 system, the size of each page is 4 kb. Linux Kernel read/write virtual memory is operated in the unit of "page", the memory is transferred to the hard disk SWAP space SWAP) and read from the SWAP space to the memory are read and written by page. This switching process between memory and SWAP is called page switching Paging. It is worth noting that paging and swapping are two completely different concepts. Many domestic reference books confuse these two concepts, swapping is also translated as swap. in the operating system, a program is fully switched to the hard disk to free up memory for use by new programs, and only partial pages of the program are exchanged with paging) is two different concepts. Pure swapping is hard to see in modern operating systems, because it is time-consuming, laborious, and unnecessary to switch the entire program to the hard disk, modern Operating Systems are basically a mix of paging, paging, and swapping. swapping was initially implemented on Unix system V.

Virtual Memory Management is the most complex part of the Linux kernel. It may take a whole book to understand this part. VPSee only describes two kernel processes related to performance monitoring: kswapd and pdflush.

  • Kswapd daemon is used to check pages_high and pages_low. If the available memory is less than pages_low, kswapd starts scanning and tries to release 32 pages, and rescans the release process until the available memory is greater than pages_high. Check three items during scanning: 1) if the page is not modified, put the page in the available memory list; 2) if the page is modified by the file system, write the page content to the disk; 3) if the page is modified but not modified by the file system, write the page to the swap space.
  • Pdflush daemon is used to synchronize memory pages related to files and synchronize memory pages to hard disks in a timely manner. For example, when a file is opened and imported into the memory, the file is modified and saved, and the kernel does not immediately save the file to the hard disk, pdflush determines when the corresponding page is written to the hard disk, which is determined by a Kernel Parameter vm. dirty_background_ratio to control, for example, the following parameter shows the dirty page dirty pages) to write data to the hard disk when it reaches 10% of all memory pages.
# /sbin/sysctl -n vm.dirty_background_ratio10
Vmstat

Let's continue with the introduction of some vmstat parameters. Last Linux performance monitoring: CPU introduced some vmstat parameters. Here we will introduce another part. The following data comes from VPSee's 256 mb ram and 512 mb swap Xen VPS:

# vmstat 1procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 0  3 252696   2432    268   7148 3604 2368  3608  2372  288  288  0  0 21 78  1 0  2 253484   2216    228   7104 5368 2976  5372  3036  930  519  0  0  0 100  0 0  1 259252   2616    128   6148 19784 18712 19784 18712 3821 1853  0  1  3 95  1 1  2 260008   2188    144   6824 11824 2584 12664  2584 1347 1174 14  0  0 86  0 2  1 262140   2964    128   5852 24912 17304 24952 17304 4737 2341 86 10  0  0  4
  • Swpd: The used SWAP space, in KB;
  • Free, available physical memory size, in KB;
  • Buff, the buffer size of the physical memory used to cache read/write operations, in KB;
  • Cache, physical memory used to cache the cache size of the process address space, in KB;
  • Si, the size of data read from SWAP to RAMswap in), in KB;
  • So, the size of data written from RAM to SWAPswap out), in KB;
  • Bi: the size of the disk block that is read from the file system or SWAP to RAMblocks in. The block is measured in units;
  • Bo: the size of the disk block written from RAM to the file system or SWAPblocks out). The block is measured in units;

The above is an example of frequent read/write swap areas. The following points can be observed:

  • The physical available memory free is basically no significant change. swapd is gradually increased, indicating that the minimum available memory is always around 256 mb x 10% = 2.56 MB. When the dirty page reaches 10%, the vm. dirty_background_ratio = 10) swap is used in large quantities;
  • The steady decrease in buff indicates that the system knows that the memory is insufficient and kwapd is borrowing some memory from the buff;
  • Kswapd keeps writing dirty pages to the swap zone so), and it is seen from the increase of swapd. According to the preceding three items checked during kswapd scan, if the page is modified but not modified by the file system, the page is written to swap, so swapd continues to increase.

Original article: http://www.vpsee.com/2009/11/linux-system-performance-monitoring-memory/

Series Navigation:

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.