The difference between memory buffer and cache in Linux operating system

  
 

We started with the Free command. The free command provides a more concise view of system memory usage relative to top: $ freetotal used free shared buffers cachedMem: 255268 238332 16936 0 85540 126384

-/+ buffers/cache: 26408 228860

Swap: 265000 0 265000

Mem: indicates physical memory statistics - /+ buffers /cached: indicates the cache statistics of physical memory Swap: indicates the use of swap partitions on the hard disk, here we do not care. The total physical memory of the system: 255268Kb (256M), but the currently available memory b of the system is not the 16936Kb of the first line free tag, it only represents the unallocated memory. We use the names total1, used1, free1, used2, and free2 to represent the values ​​of the above statistics, and 1, 2 represent the data of the first row and the second row, respectively. Total1: indicates the total amount of physical memory. Used1: Indicates the total amount allocated to the cache (including buffers and caches), but some of them may not be actually used. Free1: Unallocated memory. Shared1: shared memory, the general system will not be used, not discussed here. Buffers1: The number of buffers allocated by the system but not used. Cached1: The number of caches allocated by the system but not used. The difference between buffer and cache is shown later. Used2: The total amount of buffers and caches actually used, and the total amount of memory actually used. Free2: The sum of unused buffers and cache and unallocated memory. This is the current available memory of the system. You can sort out the following equation: total1 = used1 + free1total1 = used2 + free2used1 = buffers1 + cached1 + used2free2 = buffers1 + cached1 + free1buffer The difference between cache and cache A buffer is something that has yet to be "written" to disk. A cache For something that has been "read" from the disk and stored for later use. More detailed explanation: Difference Between Buffer and Cache for shared memory (Shared memory), mainly used to share data between different processes in the UNIX environment Is a method of inter-process communication. The general application does not apply for shared memory. I have not verified the effect 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 small but high-speed memory located between the CPU and main memory. [/b] Because the speed of the CPU is much higher than the main memory, the CPU directly waits for a certain period of time to access the data from the memory. The Cache stores a part of the data that the CPU has just used or recycled. When the CPU uses the part of the 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. The Cache is further divided into a Level 1 Cache (L1 Cache) and a Level 2 Cache (L2 Cache). The L1 Cache is integrated inside the CPU. The L2 Cache is generally soldered on the motherboard at the early stage. Now it is also integrated in the CPU. The common capacity is 256 KB. Or 512KB L2 Cache.

Buffer: A buffer for storing data between devices that are not synchronized or devices with different priorities. [/b] Through the buffer, you can make the mutual waiting between processes less, so that when reading data from a slow device, the operation process of the fast device does not interrupt. Free buffer and cache: (they are all occupied memory): buffer: as the buffer cache memory, is the block device's read and write buffer cache: as the page cache memory, file system cache

if The value of cache is very large, indicating that the number of files in the cache is large. If frequently accessed files can be cached, the read IO of the disk must be very small.

Copyright © Windows knowledge All Rights Reserved