RHCA442 Learning notes-unit11 Memory Recycling

Source: Internet
Author: User
Tags valgrind

Unit Memory Reclamation Memory Recycling             Learning Goals: A. Understanding and adjusting memory recycling B. Adjusting memory overflow C. Adjusting the use of virtual memory (swap) 12.1 Characterizing page Status features of various page states           a. Free pages                 pages can be assigned to a process immediately            b inactive Clean Page                 A. Page content has been written to disk, or                 B. Data is not modified from disk after it is read into memory                 c. This page can be assigned            c. Inactive dirty  Dirty Page               A.   Page not in use, and               b.  Page content has been updated but not yet written to disk           D. active  activity Page               a. The page is being used by the process and cannot be assigned.   12.2 calculating Dirty and clean memory calculating dirty pages and clean pagesA. Calculations using awk: Cat/proc/1/smaps | awk ' BEGIN {print ' Execute before processing input ';} /* Process input *//shared_clean/{clean + = $;}                  /shared_dirty/{Dirty + = $;}                       END {/* Execute after processing input */Print "Shared_clean:" clean;                 Print "Shared_dirty:" Dirty; }’ 12.3 Reclaiming Dirty pages Recycle dirty pagesa.       the memory cache requires control over the collection of pages. a.        because the in-memory data is constantly changing, dirty page data that is not written to disk in memory is likely to be lost. b.        dirty pages need to write content back to disk c.        To free memory pages for use by other processes. b.       the work of recycling dirty pages is handled by kernel thread pdflush. a.        default minimum of two threads to complete:bdflush,kupdated  (Ps–aux|grep pdflush) b.  The        system automatically adds and deletes the number of Pdflush threads based on the active state of I/O. C.       vm.nr_pdflush_threads represents the current number of pdflush threads. The default value is 2. ps:* in order to avoid blocking, Pdflush is solved by multithreading, and each thread can flush the dirty page and write back to disk independently. Different Pdflush threads can handle different device queues. * Thread (kupdated) is a buffer-based (I/O operation), it writes dirty buffers back to disk, Pdflush is page-based, it writes the entire page back to disk, actually the IO operation is based on the page, not the block, so the management page is simpler than the management block, Bdflush, Kupdated has been replaced by Pdflush after Linux kernel 2.6 .                  Note: When the following two cases occur, dirty pages are written back to disk:                     1) When free memory falls below a specific threshold, the kernel must write the dirty page back to disk to free up memory. &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2) When a dirty page resides in memory longer than a specific threshold, the kernel must write back the dirty page that is timed out to disk. To ensure that dirty pages do not reside in memory indefinitely.    12.4 Tuning Pdflush Adjustment PdflushA. Adjusting the size and length of dirty pages in memory Vm.dirty_background_ratio: The total memory percentage, when the dirty page reaches this threshold, write back the dirty page vm.dirty_ratio B.      Adjust the wait time vm.dirty_expire_centisecs C. Adjust the monitoring period (between Pdflush wakeups) vm.dirty_writeback_centisecs 12.5 Reclaiming Clean pages Recycle clean pagesA. Write all dirty page buffers and pages back to disk.                 A. Sync command: Tell the kernel to write the dirty page back to disk immediately.      B. Fsync system call: C. Write data to disk when the system is not functioning properly: echo s >/proc/sysrq-trigger c.       Recycle clean page echo 3>/proc/sys/vm/drop_cachesa.       Clears the corrupted data in the cache to B. Recycle the clean pages in memory before the laptop sleeps to reduce the in-memory data. C. Test the clean page condition of the subsystem. 12.6 Out-of-memory Killer Memory OverflowA. The process is killed when the following conditions occur: A.       All memory (including swap) has been exhausted B.       The Zone_normal area page also runs out of c.      No available memory is mapped to page Table B.       Some interactive processes are to be retained by a.       Interactive process B that is sleeping.      To see the chance of a process being killed: Cat/proc/pid/oom_scorec.       Manual kill Process echo F >/proc/sysrq-trigger simulation kills Process A.       Do not kill process B if there is still memory available. The/var/log/messages can see detailed memory information. 12.7 Tuning OOM Policy Adjustment OOM StrategyA. Protect daemons from Oom-kill to avoid process being killed echo n >/proc/pid/oom_adja.   The value of Oom_score is 2^n, -17~+15, the smaller the value, the less likely it is to be killed.                  B. The child process inherits the Oom_adj value of the parent process C. The update package must be installed on RHEL5.1 to support this feature.      Selinux-policy-targeted-*b.      Disable the Oom-kill function vm.panic_on_oom=1c in/etc/sysctl.conf. oom-kill resolves memory overflow issues, but does not resolve memory leaks. 12.8 Detecting Memory leaks Detecting Memory leaksA. Two types of memory leaks: a.       Virtual Memory: There is no virtual address space (VSZ) b that can be used when the process requests the page. Actual memory: No free memory space causes the process to fail. B. Use the SAR command to observe the memory usage of the system. Sar-r 1 C. Use the watch PS pmap command to view the memory usage of the process WATCH–N1 ' PS Axo pid,comm.,rss,vsi Ze |     grep httpd ' D. Use the Valgrind command to see if a process has memory leaks and memory allocations and releases. Valgrind--tool=memcheck cat/proc/$$/maps 12.9 What is swap? Swap is what ?A. Virtual memory is the use of hard disk to extend the physical memory, so the increase in available memory is relative to a valid range. The kernel writes the contents of the current unused memory block to the hard disk, at which point the memory is used for other purposes. When the original content is needed again, it is then read back into memory. This is for the user is completely transparent; programs running under Linux can see that it is only a large amount of available memory, and it is not noticed that occasionally there are parts that reside on disk. Of course, reading and writing on the hard drive are slow (about to be thousands of times slower), relative to the use of real memory, So the program can't run faster. Using a portion of the hard drive as virtual Memory, this is called "Swap space".       A. SWAP-OUT:RAM--ÀSWAPB.      Swap-in:swap-àramb. Which pages will be put into swap?       A. Inactive pages:dirty pagesb.      Anonymous Pagesc.       Swap Cachea.       Include write to swap unmodified page B. Avoid contention when multiple processes access shared memory. 12.10 Improving Swap performance Ascension Swap PerformanceA. Reasons for the large swap delay: a. Swap space small B.      Anonymous pages read and write frequently B.       Reduce the number of times a swap is accessed.       In the virtual machine master try to use a separate virtual block device (VBD) as the SWAPB.       The swap partition can be distributed up to 32 LUNs in the maximum number of C. Multiple swap partitions are set to the same high priority as possible.       D. The kernel will prioritize the use of high-priority swap partition E. The kernel accesses swap partitions of the same priority using a round robin approach.       C. Reduced service time A. Using partitions, do not use files as swap partitions. B. Try to put swap on the fast LUN. 12.11 Tuning swappinessA. Finding inactive pages consumes CPU resources A. In a large memory range, finding and clearing inactive pages consumes more disk and CPU resources than writing anonymous pages to disk.       B. Increase the value of anonymous pages Vm.swappinessa.      Linux prefers to use swap anonymous pagesanonymous pages +vm.swappiness >=100100 for propensity values, no units, larger values tend to use swap, smaller and more inclined to use CACHEC.       Summary improve swap performance can be: A.       Reduce CPU Utilization B. Reduce disk throughput 12.12 Tuning Swap Size Adjustment Swap sizea.       the:a.        kernel to consider before tuning is used Zone_ 2 bytes in normal to track swap page Exchange. b.        If storage bandwidth does not keep up with RAM, it can cause swaplockc.         If memory is low, the kernel kills the user process b.       adjustment scheme one:a.         Batch processing compute server:4*ramb.        database server: <=1GiBc.         Application Server (middleware):>=0.5*ramc.       summary a.         to avoid swaplock scenario two:ram                   SWAP---------------------------------------------1GB ~2gb              1.5*ram2gb~8gb                  ram>8gb        & nbsp;        0.75*ram----------------------------------------------  12.13 Tuning swap for think time swap time to thinkA. Number of swap vm.page-cluster pages of one-time write and swap, default is 3, value is 2^NB.      Prevents the current process from paging OUTC.       Summary A.       Filter swap behavior B. Allows the current process to write data to disk as much as possible. 12.14 Tuning Swap Visit Count Adjustment Swap Number of visitsA. You can create more than 32 swap device B.      Hit Swap tab mkswap–l myswap/dev/sdb1c. Set swap device priority in/etc/fstab file/dev/sda1 swap pri=3 0 0label=myswap swap pri=3 0 0/DEV/SDC1 swap S     WAP pri=3 0 0/var/swapfile swap swap pri=3 0 0D. Activate Swapswapoff-aswapon-aswapon–s view swap status/proc/swaps 12.15 Monitoring Memory Usage View Memory UsageA. Viewing memory activity status Vmstat-n 1 30sar-r 1 30B.      View memory Changes Sar-r 1 30C.     Swap Active State Sar-w 1 30D. View IO status Sar-b 1 30

This article is from "Alan's blog" blog, please be sure to keep this source http://alansky.blog.51cto.com/634963/657691

RHCA442 Learning notes-unit11 Memory Recycling

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.