Linux buffer differs from cache

Source: Internet
Author: User

A buffer is something that have yet to being "written" to disk. A cache is something that have been "read" from the disk and stored for later use.

For a more detailed explanation reference: difference between Buffer and Cache

The difference between cache and buffer:
Cache:

1, cache hardware, is located between the CPU and main memory of a small but high-speed memory. Because the CPU speed is much higher than the main memory, the CPU accesses the data directly from the memory to wait for a certain period of time, the cache holds the CPU just used or recycled part of the data, when the CPU re-use the part of the data can be directly called from the cache, which reduces the CPU waiting time, Improve the efficiency of the system.

The cache is not a cache file, but rather a buffer block (block is the smallest unit of I/O reading and writing), the cache is generally used on I/O requests, if more than one process to access a file, you can read this file into the cache, This allows the next process to gain CPU control and access this file directly from the cache to improve system performance.

The cache is also divided into one-level cache (L1 cache) and level two cache (L2 cache), L1 cache is integrated within the CPU, L2 cache is usually soldered to the motherboard, and is now integrated into the CPU, with a common capacity of 256KB or 512KB L2 Cache.

2. In-memory cache, such as OS-managed file system cache.

Buffer:

Buffer, only in memory. An area that is used to transfer data between devices that are not synchronized, or devices with different priority levels. Through the buffer, you can make the process of mutual wait less, so that the slow device reading data, the speed of the operation of the device is not interrupted (do not wait, you can do other things, to a certain extent, then read the buffer data).

Buffer is typically used to write to disk, for example: a process requires multiple fields to be read in, and fields that have been read before all required fields are read into buffer are first placed.

Buffer and cache in free:
They all occupy the system memory.

Cache: As the page cache memory, is the file system cache, the file is cached, the data at the file level is cached to page cache. The logical layer of the file needs to be mapped to the actual physical disk, and this mapping is done by the file system. When the page cache's data needs to be refreshed, the data in the page cache is given to buffer cache, but this processing is simple after the 2.6 kernel, with no real cache operation.

Buffer: Memory as buffer cache, is the read and write buffer of the block device. Buffer cache is a caching of disk blocks that, in the absence of a filesystem, caches data directly into the buffer cache, for example, the file system's metadata is cached in buffer cache.

In the case of a file system, the data is cached to the page cache, and if the disk is read and written directly using tools such as DD, the data is cached to buffer cache.

If the cache has a large value, it indicates that the cache has a high number of files. If frequently accessed files can be cache, then the disk read IO will be very small.

Reference: http://bbs.chinaunix.net/archiver/tid-478109.htmlhttp://bbs.chinaunix.net/archiver/tid-478109.html

Other:

To say what I understand:
Cache, which is a way to speed up reading. The goal is to speed up reading. Physically, there is CPU-managed L1 cache, L2 cache (both data cache and instruction cache) and memory cache (such as OS managed file system cache).

Access to the cache is divided into cache hit or cache miss. Usually the larger the cache, the higher the cache hit rate and the faster the access. The visitor does not know whether the data is in the cache.

Buffer, which refers only to the memory area where the software is used to hold specific information. Buffer on demand, enough to save the data on the line, do not seek maximum. The software has the appropriate mechanism to know the data in buffer.

To add, a Def_blk_ops file operation method is assigned to each device at the filesystem level, which is how the device operates. There will be a radix tree under each device's inode, and the radix tree will place the page that caches the data. The page number will be displayed in the buffer column of the top program.

If the device makes a file system, it generates an inode that allocates operations such as Ext3_ops, which are methods of the file system. There is also a radix tree under the file system Inode, which caches the page page of the file, and the number of cached pages is counted in the cache column of the top program.

As can be seen from the above analysis, the buffer cache and page cache in the 2.6 kernel are consistent in processing, but there is a conceptual difference between the page cache Cache,buffer for the file is the cache for the disk block data, that's all.

Linux buffer differs from cache

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.