Differences between Linux memory buffer and cache

Source: Internet
Author: User
Memory usage instructions the Free Command provides a more concise view of system memory usage than the top command [root @ rac1 ~] # FreetotalusedfreesharedbufferscachedMem: 10351081008984261240124212413000-/+ buffers/cache: 4...

 

Memory usage instructions

Compared with top, the Free Command provides a more concise view of system memory usage.

 

 

[Root @ rac1 ~] # Free

 

 

Total used free shared buffers cached

 

 

Mem: 1035108100898426124 0 124212 413000

 

 

-/+ Buffers/cache: 471772 563336

 

 

Swap: 2096472 842320 1254152

 

 

The unit shown here is KB.

 

 

In linux's memory allocation mechanism, physical memory is preferred. when physical memory is idle (enough), it will not be released, even if the program that uses the memory has been disabled, the memory occupied by this program is used for caching. it is faster for an opened program or reading data that has just been accessed. For details about Linux memory mechanism, refer:

 

 

Linux memory mechanism

 

 

Mem: physical memory statistics.
-/+ Buffers/cached: indicates the cache statistics of physical memory.
Swap: indicates the usage of Swap partitions on the hard disk. Swap is used only when mem is occupied by the current process, that is, no buffers or cache is available.

 

 

Mem row (first line) data description:

 

 

Total: 103520.kb. Total physical memory size.

 

 

Used: 1008984KB. Indicates the total quantity allocated to the cache (including buffers and cache), but some of them may not be actually used.

 

 

Free: 26124KB. Indicates unallocated memory.

 

 

Shared: 0 KB. Shared Memory, which is generally not used by the system.

 

 

Buffers: 124212KB. The number of buffers allocated by the system but not used.

 

 

Cached: 413000KB. The number of cache allocated by the system but not used.

 

 

-/+ Buffers/cache row (second row) data description:

 

 

Used: 471772kb. The total amount of buffers and cache actually Used is also the total amount of memory actually Used.

 

 

Free: 563336kb. the sum of unused buffers and cache and unallocated memory is the actual available memory of the system.

 

 

Based on the above analysis, we can draw a conclusion:

 

 

1. actual available memory size:

 

 

Free (-/+ buffers/cache row) = Free (Mem) + buffers (Mem) + Cached (Mem );

 

 

563336 = 26124 + 124212 + 413000

 

 

2. allocated memory size:

 

 

Used (Mem) = Used (-/+ buffers/cache) + buffers (Mem) + Cached (Mem)

 

 

1008984kb = 471772 + 124212 + 413000

 

 

3. total physical memory size

 

 

Total (Mem) = used (-/+ buffers/cache) + free (-/+ buffers/cache)

 

 

1035108 = 471772 + 563336

 

 

II. differences 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.

 

 

2.1 Cache

 

 

Cache: high-speed Cache is a memory with a small capacity but high speed located between the CPU and the main memory.

 

 

Because the CPU speed is much higher than the master memory, it takes a certain period of time for the CPU to directly access data from the memory. the Cache stores part of the data that has just been used by the CPU or is used cyclically, when the CPU uses this part of data again, it can be called directly from the Cache, which reduces the CPU wait time and improves the system efficiency.

 

 

Cache is divided into Level 1 Cache (L1 Cache) and Level 2 Cache (L2 Cache). L1 Cache is integrated into the CPU, and L2 Cache is usually soldered to the motherboard in the early stages, it is also integrated into the CPU. the common capacity is 256KB or 512KB L2 Cache.

 

2.2 Buffer

 

 

Buffer: a Buffer used to transmit data between devices with different storage speeds or between devices with different priorities. Through the buffer zone, mutual waits between processes can be reduced, so that when reading data from a slow device, the operation process of the fast device will not interrupt.

 

 

The buffer and cache displayed in the Free command occupy the memory:

 

 

Buffer: as the buffer cache memory, it is the block device's read and write buffer, closer to the storage device, or directly the disk's buffer.

 

 

Cache: the page cache memory. the file system cache is the memory buffer zone.

 

 

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

 

From ERDP technical architecture

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.