Memory for Linux performance monitoring

Source: Internet
Author: User
Tags snmp

First, we understand the virtual memory and physical memory: the virtual memory is to use the hard disk to expand the physical memory, write unused memory pages to the hard disk to free up more physical memory for use by processes in need. When these memory pages require pi, they are read back from the hard disk. All this is transparent to users. In Linux, virtual memory is a swap partition. On X86 systems, the virtual memory is divided into 4 K pages.

Memory

Linux performance monitoring each process will apply for Virtual Memory VSZ from the system at startup), the kernel agrees or rejects the request. When the program actually uses the memory, the system maps it to the physical memory. RSS indicates the size of the physical memory occupied by the program. Run the ps command to view the VSZ and RSS used by the process.

# Ps-aux

User pid % CPU % MEM VSZ RSS TTY STAT START TIME COMMAND

Daemon 2177 0.0 0.2 3352 648? Ss/usr/sbin/atd

Listen 2196 0.0 0.5 13180 1320? Ssl dbus-daemon-1 -- sys

Root 2210 0.0 0.4 2740 1044? Ss cups-config-daemon

Root 2221 0.3 1.5 6108 4036? Ss hald

Root 2231 0.0 0.1 2464 408 tty1 Ss +/sbin/mingetty tty1

The kernel regularly synchronizes data in the Memory to the hard disk. This process is called Memory Paging. At the same time, the kernel is also responsible for recycling unused memory and assigning them to other required processes. PFRA algorithm Page Frame reclaim algorithm) is used to reclaim idle memory. The algorithm determines the memory page to be released based on the Memory Page type. There are four types:

1. Unreclaimable-the page on which the kernel is retained;

2. Swappable-Anonymous memory page;

3. Syncable-Memory Page backed up by hard disk files;

4. Discardable-static pages and discarded pages.

Other than the first Unreclaimable) can be recycled by PFRA. The associated process is kswapd. In kswapd, there are two thresholds: pages_hige and pages_low. When the number of idle memory pages is lower than pages_low, The kswapd process will scan the memory and release 32 free pages each time until the number of free pages reaches pages_high. How does kswapd reclaim memory? There are the following principles:

1. If the page has not been changed, it will be put into the idle queue;

2. If the page has been changed and can be backed up back to the file system, you can write the content of the Memory Page back to the disk;

3. If the page has been changed but there is no backup on the disk, write it to the swap partition.

# Ps-ef | grep kswapd

Root 30 1 0 23:01? 00:00:00 [kswapd0]

Linux performance monitoring also has two important methods in memory recovery: LMRLow on Memory reclaiming and OMK (Out of memory Killer ). When the memory allocation fails, LMR will take effect. The cause of the failure is that kswapd cannot provide enough idle memory. At this time, LMR will release 1024 junk pages each time to know that the memory allocation is successful. When LMR cannot quickly release the memory, OMK starts to function. OMK uses a selection algorithm to decide to kill some processes. When a process is selected, the SIGKILL signal is sent, which immediately releases the memory. The OMK process selection method is as follows:

1. Process occupies a large amount of memory;

2. The process will only lose a small amount of work;

3. The process has a low static priority;

4. The process does not belong to the root user.

Another program in Linux performance monitoring process management, pdflush, is used to synchronize the content in the memory with the file system. For example, when a file is modified in the memory, pdflush writes it back to the hard disk.

# Ps-ef | grep pdflush

Root 28 3 0 23:01? 00:00:00 [pdflush]

Root 29 3 0 23:01? 00:00:00 [pdflush]

When the size of the junk pages in the memory exceeds 10%, pdflush backs up these pages back to the hard disk. This ratio can be adjusted through the vm. dirty_background_ratio parameter.

# Sysctl-n vm. dirty_background_ratio

Pdflush and PFRA run independently. When the kernel calls LMR, LMR triggers pdflush to write junk pages back to the hard disk.

  1. About Swap space management in Linux
  2. Partition Rules for swap in linux
  3. 2 GB virtual memory Linux swap restrictions
  4. In-depth exploration of Linux SNMP-Managed Devices
  5. There are two methods for collecting data in Linux SNMP:

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.