Centos memory usage and optimization skills

Source: Internet
Author: User

The Linux server allocates real and virtual memory to the processor and manages memory usage through swap. Understanding the Linux memory type and how the processor shares memory helps optimize memory usage.

Memory is allocated from the Linux kernel start-up execution process. The total virtual memory is required. The virtual memory on Linux is infinite, and the processor can allocate memory at startup. Linux Kernel ing allocates virtual memory to the actual memory through swap.

Unlike Windows, memory switching slows down the program, while Linux memory switching is helpful. Thanks to the Memory Page allocated by the Linux analysis process. The Linux kernel runs recently used algorithms to determine which memory pages need to enter RAM and which do not need them. In some cases, faster Linux kernel switching can improve memory performance.

The process of a program usually requires more virtual memory than the actual requirement. In Linux top-level programs, virtual memory requirements appear in VIRT and permanent memory (RAA) volumes. When a process starts to use the Memory Page allocated to work, the page is moved to RAM and displayed as RSS. Monitors Linux kernel memory usage so that administrators can only keep these frequently used memory pages. Infrequently used access pages can be discarded through the kernel or exchange.

Processes on Linux servers use anonymous memory and file memory related to code and data. Anonymous memory must be available directly. Therefore, if memory resources are under pressure, pages labeled as anonymous memory should be exchanged.

Data Memory is another thing. When a process reads data from a disk, it is stored in the cache, allowing the process to quickly provide data when the data is needed next time. Under memory pressure, the kernel can discard the data memory. Moving unused File Memory to swap has no performance benefit, and discarding is a better choice.

When deciding to discard or swap memory, the Linux kernel distinguishes between active and inactive memory. If the inactive memory is not used recently, it is obviously harmless to move it to swap or directly discard it. The/proc/meminfo file displays the differences between the anonymity and the active and inactive memory of the file, as shown in 1.

Figure 1: differences between active and inactive memory in Linux Kernel

[Root @ IAD ~] # Less/proc/meminfo

MemTotal: 7971636 kB

MemFree: 2653648 kB

Buffers': 250868 kB

Cached: 2974052 kB

SwapCached: 0 kB

Active: 2530380 kB

Inactive: 2323604 kB

Active (anon): 1633532 kB

Inactive (anon): 125712 kB

Active (file): 896848 kB

Inactive (file): 2197892 kB

Unevictable: 0 kB

Mlocked: 0 kB

SwapTotal: 10059772 kB

SwapFree: 10059772 kB

Dirty: 132 kB

Writeback: 0 kB

AnonPages: 1629052 kB

Mapped: 162396 kB

Shmem: 130192 kB

Slab: 296332 kB

SReclaimable: 233344 kB

SUnreclaim: 62988 kB

In this example, there is a large amount of active anonymous memory and a small amount of inactive anonymous memory. If the system is under memory pressure, the kernel will move MB of inactive anonymous memory to swap. The swap flag should not be GB of active page memory, because memory pages often need to move between RAM and disk, which will reduce performance. If the swap volume is larger than the inactive (anonymous) memory, you should add more RAM-optimized Linux memory pages.

For Ideal Linux memory pages, the actual amount of swap used should not be redundant (anonymous) memory pages. The amount of active (File) memory is equal to the amount of cache memory required by the kernel. Otherwise, the server performance cannot be improved.

When the kernel requires more memory, the File Memory marked as inactive will be discarded. Because the Linux kernel cannot be better processed, the memory of inactive files is kept in the cache. If the data is discarded, it will not be affected.

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.