Linux memory management mechanism buffer and cache the difference
to understand linux memory management, you need to understand the meaning and rules of various parameters in linux Memory. The following describes the differences between memory buffer and cache in Linux operating systems.
Compared with top, Free free Command provides a simpler view of system memory usage:
mem: indicates physical memory statistics-/+ buffers/cached: indicates cache statistics of physical memory Swap: indicates the usage of Swap partitions on the hard disk.
The total physical memory of the system: 3886MB, but the currently available memory B is not 26MB marked free in the first line, it only represents the unallocated memory.
We use names such as total1, used1, free1, used2, and free2 to represent the values of the above statistics. 1 and 2 respectively represent the data in the first and second rows.
total1: indicates the total physical memory. used1: indicates the total number of caches (including buffers and caches) allocated, but some of the caches may not be actually used. free1: the unallocated memory. shared1: Shared Memory, which is generally not used by the system, and is not discussed here. buffers1: the number of buffers allocated by the system but not used. cached1: the number of unused caches allocated by the system. For more information about the differences between buffer and cache, see. used2: the total number of buffers and cache used, which is also the total memory used. free2: the sum of unused buffers, cache, and unallocated memory, which is the actual available memory of the system.
The following equation can be sorted out: total1 = used1 + free1total1 = used2 + free2used1 = buffers1 + cached1 + used2free2 = buffers1 + cached1 + free1
the difference between buffer and cache A buffer is something that has yet to be "written" to disk. A cache is something that has been "read" from the disk and stored for later use.
For more information, see Difference Between Buffer and Cache.
Shared memory (Shared memory) is mainly used to share data between different processes in a UNIX environment. It is a method of inter-process communication. Common applications do not apply for Shared memory, the author did not verify the impact of shared memory on the above equation. If you are interested, please refer to: What is Shared Memory?
The difference between cache and buffer: Cache: cache is a memory with small capacity but high speed between CPU and main memory. Because the CPU speed is much higher than that of the main memory, it takes a certain period of time for the CPU to directly access data from the memory. Some data that has just been used or recycled by the CPU is stored in the Cache, when the CPU uses this part of data again, it can be called directly from the Cache, which reduces the waiting time of the CPU and improves the efficiency of the system. Cache is divided into Level -1 Cache(L1 Cache) and level -2 Cache(L2 Cache). L1 Cache is integrated inside the CPU, and L2 Cache is usually welded on the motherboard in the early stage, now it is also integrated into the CPU, and the common capacity is 256kB or 512kB L2 Cache.
Buffer: a Buffer used to store data between devices with different speeds or with different priorities. Through the buffer, the mutual waiting between processes can be reduced, so that when data is read from a slow device, the operation process of the fast device is not interrupted.
buffer and cache in Free: (both of them occupy memory):
This article is transferred from naive Huayu 51CTO blog, original link: http://blog.51cto.com/caibird/684057 , if you need to reprint, please contact the original author.