Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Memory for Linux performance Monitoring

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the Memory of Linux performance monitoring example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Linux performance monitoring requests virtual memory (VSZ) from the system when each process starts, and the kernel agrees or rejects the request. When the program actually uses memory, the system maps it to physical memory. RSS represents the amount of physical memory occupied by the program. With the ps command, we can see the VSZ and RSS consumed 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 23:03 0:00 / usr/sbin/atd

Dbus 2196 0.0 0.5 13180 1320? Ssl 23:03 0:00 dbus-daemon-1-sys

Root 2210 0.0 0.4 2740 1044? Ss 23:03 0:00 cups-config-daemon

Root 2221 0.3 1.5 6108 4036? Ss 23:03 0:02 hald

Root 2231 0.0 0.1 2464 408 tty1 Ss+ 23:03 0:00 / sbin/mingetty tty1

The kernel periodically synchronizes data in memory to the hard disk, a process called Memory Paging. At the same time, the kernel is also responsible for reclaiming unused memory and allocating it to other needed processes. The PFRA algorithm (Page Frame reclaim algorithm) is responsible for reclaiming free memory. The algorithm determines which memory page to release according to the type of memory page. There are four types:

1. Unreclaimable-locked, kernel-reserved page

2. Swappable-Anonymous memory page

3. Syncable-memory pages backed up by hard disk files

4. Discardable-static and discarded pages.

All but Unreclaimable can be recycled by PFRA. The process associated with it is kswapd. In kswapd, there are two thresholds, pages_hige and pages_low. When the number of free memory pages is lower than pages_low, the kswapd process scans memory and releases 32 free pages at a time until the number of free page reaches pages_high. How exactly does kswapd reclaim memory? There are the following principles:

1. Put the page in the idle queue if it has not been changed

two。 If the page has been changed and can be backed back to the file system, it is understood to write the contents of the memory page back to disk

3. If the page has changed but there are no backups on disk, write it to the swap partition.

# ps-ef | grep kswapd

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

There are two important ways to monitor Linux performance in the process of memory recovery, one is LMR (Low on memory reclaiming), and the other is OMK (Out of Memory Killer). When LMR fails to allocate memory, it will work because kswapd does not provide enough free memory, and LMR will release 1024 junk pages at a time to know that memory allocation is successful. When LMR cannot release memory quickly, OMK begins its role, and OMK uses a selection algorithm to decide to kill certain processes. When a process is selected, a signal SIGKILL is sent, which immediately frees memory. OMK selects a process as follows:

1. The process takes up a lot of memory

two。 The process loses only a small amount of work

3. Processes have low static priority

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

Pdflush, another program in Linux performance monitoring process management, is used to synchronize the contents of memory with the file system. For example, when a file is modified in memory, pdflush is responsible for writing 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]

Whenever the dirty page in memory exceeds 10%, pdflush backs up the pages back to the hard drive. This ratio is adjustable through the parameter vm.dirty_background_ratio.

# sysctl-n vm.dirty_background_ratio

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

The above is all the contents of the article "sample Analysis of Memory for Linux performance Monitoring". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report