Linux system eat "memory" phenomenon

And when we use the free command to view the Linux system when memory usage, memory usage has been found to be at a higher level, even if the system does not run much software. This is the Windows and Linux memory management differences, at first glance, eat our Linux system memory (Linux ate my ram), but in fact this is precisely the characteristics of its memory management.
Linux system eat "memory" phenomenon Linux system to eat "memory" phenomenon

free command

File server memory below to see results obtained in our laboratory to use the free command, -m option indicates use in MB:
The second line represents the output of system memory usage:
Mem: Total (total) = 31405MB, used (already use) = 30254MB, free (idle) = 1150MB, shared (shared memory) = 12514MB, buffers = 1122MB, cached = 25424MB
Note: the preceding four are better understood, the difference is that the cache and buffer:
a buffer that has something iS bE to yet "written" to disk.
a cache iS something that has been "read" and from the disk stored for later use.
That buffer for storing data to be output to disk, while the cache memory is read out from the storage disk the data to be used in the future. They were introduced to provide the IO performance.
The third line represents the output on the basis of the second row - / + buffers / cache obtained:
- buffers / Mem = Cache Used Used - buffers - cached = 30524MB - 1122MB - 3708MB = 25424MB + buffers / Mem = Free Free Cache + buffers + cached = 1150MB + 1122MB + 25424MB = 27696MB
third output line shows the case of using the swap:
swap: total (total) = 15775MBused (use) = 596MBfree (idle) = 4095MB

Memory classification

Here the memory is divided into three categories, from the perspective of the user and the operating system for its use have different names:
Linux system eat "memory" phenomenon Linux system to eat "memory" phenomenon
the representatives of something on the table is the free command "buffers / cached" memory, since this memory from the operating system indeed angles are used, but if the user wants to use, this memory can be recovered quickly by using the user program, and thus from a user perspective this memory should be assigned to the idle state.
Back to results again free command output, the result of the third line of the output should be able to understand, this line of digital representation from the user point of view of system memory usage. So, if you view the system with the top or left in how much free memory command, in fact, you should free memory plus buffer / cached memory, that is the actual system of free memory.

buffers / cached benefits

Linux memory management do a lot of careful design, in addition to the dentry cache (for VFS, accelerated file pathname to inode conversion), Cache also taken two main ways: Buffer Cache and Page Cache, the purpose is to enhance the disk the IO performance. Block read from the low-speed device data temporarily stored in the memory, even when the data is no longer needed at the time, but the time to access the data in the application, it can be read directly from memory, thereby bypassing the low speed block device, thereby improving overall system performance.
And Linux can take advantage of these free memory, design memory is not as good as idle bring multi-cache some data, such as access to the program again next time these data speed is fast, but if you want to use the system memory and the memory is inadequate , then instead of using a swap partition, but quickly recovered part of the cache, they are left to the user program.
Therefore, it can be seen, buffers / cached is really everything to gain and no harm, real harm could allow users to produce an illusion --Linux memory consumption! In actual fact, Linux did not eat your memory, as long as not been used to the swap partition.

Experimental test: has read a large file, compare two read time
1. First generate a large file of 1G

Linux system eat "memory" phenomenon Linux system to eat "memory" phenomenon
dd if=/dev/zero of=bigfile bs=1M count=1000

2. Empty the cache

Linux system eat "memory" phenomenon Linux system to eat "memory" phenomenon
Here was changed after 3 must be changed back to 0, or else the following test results are not accurate.

3. To read this file, time consuming test

It takes 24 seconds
Linux system eat "memory" phenomenon Linux system to eat "memory" phenomenon

4. read the file again, time consuming test

Took 17 seconds
Linux system eat "memory" phenomenon Linux system to eat "memory" phenomenon
from the above seen, first read the 1G file takes approximately 24s, while the second re-read, only time-consuming 17s, declined.

Original from: http://www.360kuai.com/pc/96d710a562bab2bb9?cota=3&kuai_so=1&sign=360_e39369d1&refer_scene=so_3

This article addresses: https://www.linuxprobe.com/linux-eatsup-memory.html Editor: deceptive goblins, auditor: Zhang Wenxiang

Linux command Daquan: https://www.linuxcool.com/

REVIEW In the case of Windows Explorer to view memory usage, if the usage of more than 80%, and then run large programs can feel the system is not smooth, because the use of swap in memory shortage situation, frequently changing from disk into the swapped out greatly affect the performance of the system will page.

Guess you like

Origin www.cnblogs.com/probemark/p/11450610.html