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

The use of Centos memory and its optimization skills

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

Share

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

This article introduces the relevant knowledge of "the use of Centos memory and optimization skills". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The Linux server allocates real and virtual memory to the processor and manages memory usage through swapping. Understanding the Linux memory type and how processors share memory can help optimize memory usage.

Allocating memory from the start-up executor process of the Linux kernel requires the sum of virtual memory. The virtual memory on the Linux is unlimited, and the processor can allocate memory at startup. Linux kernel mapping allocates virtual memory to real memory through swapping.

Unlike Windows, memory swapping slows down the program, and Linux memory swapping is beneficial, thanks to the way the memory pages allocated by the Linux analysis process are used. The Linux kernel runs a recently used algorithm to determine which memory pages need to be entered into RAM and which are not. In some cases, making Linux kernel swapping faster can improve memory performance.

The process of a program usually requires more virtual memory than it actually needs. In Linux's top-level programs, virtual memory requirements appear in VIRT and resident memory (RAA) volumes. When the process starts doing things with the assigned memory page, the page is moved to RAM and displayed as RSS. Monitoring Linux kernel memory usage allows administrators to keep only these frequently used memory pages. Infrequently used access pages can be discarded through the kernel or swap.

Processes on the Linux server use anonymous memory and file memory associated with code and data. Anonymous memory must be available directly, so pages marked as anonymous memory should be swapped if memory resources are under pressure.

Data memory is another matter. When a process reads data from disk, it remains in the cache, allowing the process to provide data quickly the next time it is needed. Under memory pressure, the kernel can discard data memory. Moving unused file memory to swap has no performance benefit, and discarding is a better option.

When deciding to discard or swap memory, the Linux kernel distinguishes between active and inactive memory. If inactive memory is not used recently, it is obviously not harmful to move it to swap or simply discard it. The / proc/meminfo file shows the difference between anonymous and active and inactive file memory, as shown in figure 1 below.

Figure 1: the difference between active and inactive memory from the 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 125MB's inactive anonymous memory to swap. 1.6GB memory marked as active page memory should not be swapped, because memory pages often need to be moved between RAM and disk, which degrades performance. If the amount of swapping is greater than the amount of inactive (anonymous) memory, you should add more RAM optimized Linux memory pages.

For ideal Linux memory pages, the total amount of swap actually used should not exceed the number of inactive (anonymous) memory pages. The amount of active memory is equal to the amount of cache memory required by the kernel. Otherwise, server performance cannot be improved.

When the kernel needs more memory, file memory marked as inactive will be discarded. Because the Linux kernel cannot handle it better, the memory of inactive files remains in the cache. It won't matter if the data is discarded.

This is the end of the content of "Centos memory use and optimization techniques". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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