Linux Performance monitoring: Memory

Source: Internet
Author: User

In the operating system, the virtual memory is divided into pages, and the size of each page on the x86 system is 4KB. The Linux kernel reads and writes virtual memory on a "page" basis, transferring memory to the hard disk swap space (swap) and reading from the swap space to memory, both read and write. Virtual memory management is the most complex part of the Linux kernel.

The "Memory" here includes physical memory and virtual memory, which extends the computer's memory space to the hard disk, the physical memory (RAM) and a portion of the hard disk space (SWAP) together as virtual memory provides a consistent virtual memory space for the computer. The advantage is that we have "more" memory, you can run more and larger programs, the disadvantage is that some hard disk when the overall performance of memory, hard disk read and write slower than memory several orders of magnitude, and the exchange between RAM and swap increased the burden of the system.

In the operating system, the virtual memory is divided into pages, and the size of each page on the x86 system is 4KB. The Linux kernel reads and writes virtual memory on a "page" basis, transferring memory to the hard disk swap space (swap) and reading from the swap space to memory, both read and write. This exchange process of memory and swap is called page switching (Paging), it is noteworthy that Paging and swapping are two completely different concepts, many domestic reference books confuse these two concepts, swapping also translated into Exchange, In the operating system refers to the full exchange of a program to the hard disk to free up memory for the new program to use, and paging only the part of the Exchange Program (page) is a two different concepts. Pure swapping is hard to see in modern operating systems, because it is time-consuming and laborious and unnecessary for the entire program to be switched to a hard disk, and the modern operating system is basically paging or paging/swapping mixed, swapping originally in Unix Implemented on system V.

Virtual memory management is the most complex part of the Linux kernel, and it may take a whole book to understand this part of the content. Vpsee Here only describes the two kernel processes related to performance monitoring: KSWAPD and Pdflush.

    • The KSWAPD daemon is used to check Pages_high and Pages_low, if the available memory is less than PAGES_LOW,KSWAPD, start scanning and attempt to free up to 32 pages, and repeat the scan release process until the available memory is greater than pages_high. Check 3 things when 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, the page content is written to disk, 3) if the page has been modified, but not by the file system modification, the page is written to swap space.
    • Pdflush daemon is used to synchronize the file-related memory pages and synchronize the memory pages to the hard disk in time. For example, open a file, the file is imported into memory, the file has been modified and saved, the kernel does not immediately save the file to the hard disk, by Pdflush decide when to write the corresponding page to the hard disk, which is controlled by a kernel parameter vm.dirty_background_ratio, For example, the following parameter shows that the dirty page (dirty pages) starts writing to the hard disk when it reaches all memory page 10%.
#/sbin/sysctl-n Vm.dirty_background_ratio10
Vmstat

Continue to vmstat the introduction of some parameters, the previous Linux performance monitoring: The CPU introduced the vmstat part of the parameters, the other part of the introduction. The following data comes from a 256MB ram,512mb SWAP Xen VPS in Vpsee:

# 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 2  616 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 0 0 (0 2 1 262140 2964) 5852 24912 17304 24952 17304 4737 2341 0 0 4 
    • SWPD, the size of the SWAP space used, in kilobytes;
    • Free, the available physical memory size, in kilobytes;
    • Buff, the buffer size of the physical memory used to cache read and write operations, in kilobytes;
    • The cache size, in kilobytes, that the physical memory uses to buffer the process address space;
    • Si, the size of the data read from swap to RAM (swap in), KB units;
    • So, the size of the data from RAM to swap (swap out), in kilobytes;
    • Bi, disk blocks from the file system or SWAP read to the size of RAM (blocks in), block units;
    • Bo, disk blocks from RAM written to file system or SWAP (blocks out) size, block units;

The above is an example of a frequent read/write Exchange area, which can be observed as follows:

    • Physical available memory free Basic no significant changes, SWAPD gradually increased, indicating that the minimum available memory is always maintained at 256MB X 10% = 2.56MB, when the Dirty page reached 10% (Vm.dirty_background_ratio = 10) began a large number of Use swap;
    • Buff steadily reduces the system knows that the memory is not enough, KWAPD is borrowing some of the memory from the buff;
    • KSWAPD continues to write dirty pages to the swap area (so), and from a gradual increase in SWAPD, it does. According to the above-mentioned KSWAPD scan when the three things, if the page was modified, but not by the file system modification, the page is written to swap, so here SWAPD continues to increase

Linux Performance monitoring: Memory

Related Article

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.