What is the difference between buffer and cache memory in Linux?

后端 未结 12 1252
慢半拍i
慢半拍i 2020-12-02 03:33

To me it\'s not clear what\'s the difference between the two Linux memory concepts : buffer and cache. I\'ve read through this post and it seems to

相关标签:
12条回答
  • 2020-12-02 04:00

    Cache: This is a place acquired by kernel on physical RAM to store pages in caches. Now we need some sort of index to get the address of pages from caches. Here we need the buffer for page caches which keeps metadata of page cache.

    0 讨论(0)
  • 2020-12-02 04:08

    "Buffers" represent how much portion of RAM is dedicated to cache disk blocks. "Cached" is similar like "Buffers", only this time it caches pages from file reading.

    quote from:

    • https://web.archive.org/web/20110207101856/http://www.linuxforums.org/articles/using-top-more-efficiently_89.html
    0 讨论(0)
  • 2020-12-02 04:08

    Seth Robertson's Link 2 said "For thorough understanding of those terms, refer to Linux kernel book like Linux Kernel Development by Robert M. Love."

    I found some contents about 'buffer' in the 2nd edition of the book.

    Although the physical device itself is addressable at the sector level, the kernel performs all disk operations in terms of blocks.

    When a block is stored in memory (say, after a read or pending a write), it is stored in a 'buffer'. Each 'buffer' is associated with exactly one block. The 'buffer' serves as the object that represents a disk block in memory.

    A 'buffer' is the in-memory representation of a single physical disk block.

    Block I/O operations manipulate a single disk block at a time. A common block I/O operation is reading and writing inodes. The kernel provides the bread() function to perform a low-level read of a single block from disk. Via 'buffers', disk blocks are mapped to their associated in-memory pages. "

    0 讨论(0)
  • 2020-12-02 04:12

    Buffer is an area of memory used to temporarily store data while it's being moved from one place to another.

    Cache is a temporary storage area used to store frequently accessed data for rapid access. Once the data is stored in the cache, future use can be done by accessing the cached copy rather than re-fetching the original data, so that the average access time is shorter.

    Note: buffer and cache can be allocated on disk as well

    0 讨论(0)
  • 2020-12-02 04:15

    Quote from the book: Introduction to Information Retrieval

    Cache

    We want to keep as much data as possible in memory, especially those data that we need to access frequently. We call the technique of keeping frequently used disk data in main memory caching.

    Buffer

    Operating systems generally read and write entire blocks. Thus, reading a single byte from disk can take as much time as reading the entire block. Block sizes of 8, 16, 32, and 64 kilobytes (KB) are common. We call the part of main memory where a block being read or written is stored a buffer.

    0 讨论(0)
  • 2020-12-02 04:16

    Buffers are associated with a specific block device, and cover caching of filesystem metadata as well as tracking in-flight pages. The cache only contains parked file data. That is, the buffers remember what's in directories, what file permissions are, and keep track of what memory is being written from or read to for a particular block device. The cache only contains the contents of the files themselves.

    quote link

    0 讨论(0)
提交回复
热议问题