Buffer and Cache

Source: Internet
Author: User

Buffer (buffered)

Buffer is designed to increase the speed of data exchange between memory and the hard disk (or other I/O devices). Based on the read/write design of the disk. Centralize the scattered write operations, reducing disk fragmentation and hard disk re-seeking, improving performance.

The main purpose of traffic shaping, the sudden large number of small-scale I/O organized into a smooth small number of large-scale I/O, to * Reduce the number of responses *, usually the data in the operation after the completion of the buffer will not be continued to use; (for example, from the online movie, you can not write a little bit of data, But to accumulate a certain amount of data after a whole piece of writing together, or the hard disk will be you play bad to mitigate the impact. For example, you have to write 100 times a second hard disk, the system is a big shock, wasting a lot of time busy processing began to write and finish writing these two things. Use a buffer to temporarily save, turn into every 10 seconds to write the hard disk, the impact on the system is very small, writing efficiency is high, the days are cool. Greatly eased the impact. Linux has a daemon that periodically empties the buffered content (that is, writes to disk) or manually empties the cache via the Sync command.

Cache (Cached)

The cache is designed to increase the speed of data exchange between the CPU and the memory. This is the usual one, tertiary cache. CPU in the execution of the program's instructions and read data are for memory, faster than the memory block, the cost is high, and the CPU can not integrate too many integrated circuits, so the general cache will be relatively small. In order to increase the speed and increase the tertiary cache, according to the local principle of the program design, is the CPU execution of instructions and access to the data is often in the concentration of a piece, so put this piece of content into the cache, the CPU will not have to access the memory. If the cache does not have the content required by the CPU, it also accesses memory.

The main function is to make better use of the principle of locality, reduce unnecessary I/O and avoid the cost. speed up the fetch. For example, you have a very complex calculation done, the next time you have to use the results, the results will be a good place to hold, next time don't forget. Speed up data access.

Contrast

If you care about the storage system, you will find the hard disk read/write buffer/cache name is not the same, called Write-buffer and Read-cache. It is clear that the difference between the two.

But most of the time, the macro is probably mixed. For example, in fact memcached a lot of people are used to read and write. Many times the Non-sql database is also. Strictly speaking, the L2 and L3 caches in the CPU are both read and write-because you can't simply define how the CPU is used to read or write. The hard drive is also a typical example, buffer and cache are in a space, whether it is buffer or cache?

Do not be imprisoned by this kind of idea, take the cache to do buffer use OK? Of course, as long as you can control the cache elimination logic there is no problem. What about using buffer for the cache? It seems that in very special circumstances, it is possible to determine the order of access. Just think about it and understand--buffer by definition, do you need to store it randomly? It is not required in general. But the cache must be. So most of the time with the cache instead of buffer can be, the opposite is more limited. This is also technically the key difference between cache and buffer.

Conclusion

Buffer and cache are just relative concepts.

Do not misunderstand that buffer is used to write, the cache is used to read. Reading of course can also use buffer, for example, you want to deal with a batch of read instead of what to deal with, you can read buffer. Writing can also use the cache, for example, when your writing has a high randomness. Specifically what scenario to use buffer what scene with the cache to decide according to the specific needs of the scene.

The cache or buffer is not necessarily memory or anything on the high-speed medium. As long as the relatively high speed. I can save the cache on my hard drive, for example, some games will build pre-compiled shader at run time, which is essentially a cache, which exists on a slow hard disk, because reading the hard disk is still faster than recompiling. Buffer is the same.

This article is from the "Ink" blog, please be sure to keep this source http://jinyudong.blog.51cto.com/10990408/1901001

Buffer and 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.