Linux Memory: Buffer vs Cache

Do you really understand the differences between buffer and cache?

Tony
Geek Culture

--

Assuming you already know the definitions of “Buffer” and “Cache”:

  • Buffers are temporary storage for raw disk blocks, that is, cache data write to disks, usually not very large (about 20MB). In this way, the kernel can centralize scattered writes and optimize disk writes uniformly. For example, multiple small writes can be merged into a single large write, etc.
  • Cache is a page cache for reading files from disk, which is used to cache data read from files. This way, the next time these file data is accessed, it can be quickly fetched directly from memory without having to access the slow disk again.

But let me ask you, since Buffer is just a cache for data that will be written to disk. In turn, will it also cache data read from disk? Or Cache is a cache for reading data from files, so does it also cache data for writing files?

If you are able to answer the above two questions, you can skip this article, I think you already have a good understanding of “buffer” and “cache”. But if you can’t, please stay and let me explain further.

“free” Command

To check system memory usage, the first command that comes in your mind is…

--

--