Details the differences between Buffer and Cache

Source: Internet
Author: User
Article Title: details the differences between Buffer and Cache. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Cached stores the read data. When you read the data again, you do not need to read the hard disk if it hits (find the required data). If it does not hit the hard disk. The data is organized according to the read frequency, and the most frequently read content is placed in the most easily located location. The unread content is arranged until it is deleted.

Cache is not actually a buffer for files, but a buffer block. It is the smallest unit for disk I/O operations (in Linux, they are usually 1 kb ). In this way, the directory, the super block, the note data of other file systems, and the disk data of non-file systems can be buffered.

If the cache has a fixed size, the cache is too large or not, because it will make the idle memory too small and lead to swap operations (this is also slow ). To make the most effective use of the actual memory, Linux automatically uses all idle memory as the high-speed buffer. When the program requires more memory, it will automatically reduce the buffer size.

Buffers is designed based on disk read/write. Distributed write operations are performed in a centralized manner to reduce disk fragments and repeated seek paths on the hard disk, thus improving system performance. In linux, a daemon regularly clears the buffer content (that is, writes to the disk). You can also use the sync command to manually clear the buffer. For example, I have an ext2 USB flash drive. I cp A 3 m MP3 file, but the USB flash drive does not beat. After a while (or manually enter sync) the USB flash drive is beating. The buffer is cleared when the device is detached, so it takes several seconds to detach the device.

Both are data in RAM. In short, the buffer is about to be written to the disk, and the cache is read from the disk.

Buffer is allocated by various processes and managed by processes and systems. it is used in the field of input queue. For example, a process requires multiple fields to be read. Before all fields are fully read, the process stores previously read fields in the buffer.

The cache is often used in disk I/O requests. If multiple processes need to access a file, the file is made into a cache to facilitate next access, this provides system performance.

In summary, it can be understood as the cache system management. The buffer is managed by the process and the system.

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.