Differences between buffer and cache in Linux Memory management mechanism-Alibaba Cloud Developer Community

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):

buffer: the memory used as the buffer cache, which is the read/write buffer cache of the block device. buffer: the memory used as the page cache, which is the cache of the file system.

If the cache value is large, the number of cached files is large. If frequently accessed files can be cached, the read IO bi of the disk is very small.

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.

Please read this disclaimer carefully before you start to use the service. By using the service, you acknowledge that you have agreed to and accepted the content of this disclaimer in full. You may choose not to use the service if you do not agree to this disclaimer. This document is automatically generated based on public content on the Internet captured by Machine Learning Platform for AI. The copyright of the information in this document, such as web pages, images, and data, belongs to their respective author and publisher. Such automatically generated content does not reflect the views or opinions of Alibaba Cloud. It is your responsibility to determine the legality, accuracy, authenticity, practicality, and completeness of the content. We recommend that you consult a professional if you have any doubt in this regard. Alibaba Cloud accepts no responsibility for any consequences on account of your use of the content without verification. If you have feedback or you find that this document uses some content in which you have rights and interests, please contact us through this link: https://www.alibabacloud.com/campaign/contact-us-feedback. We will handle the matter according to relevant regulations.
Selected, One-Stop Store for Enterprise Applications
Support various scenarios to meet companies' needs at different stages of development

Start Building Today with a Free Trial to 50+ Products

Learn and experience the power of Alibaba Cloud.

Sign Up Now