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.
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.
: Differences between active memory 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.