ITZone

Differences between Buffers and Cached

Cached The size of the page cache. Buffers are the size of in-memory block I / O buffers. 2. Long answer: Both Cached and Buffers are meant to be temporary storage areas, but the purpose is different, the overview has some points: The purpose of cached is …

1. Short answer

  • Cached is the size of the page cache.
  • Buffers are the size of in-memory block I / O buffers.

2. Long answer

Both Cached and Buffers are meant to be temporary storage areas, but the purpose is different, the overview has some points:

  • The purpose of cached is to create a high-speed memory area to speed up the read / write process to disk, while the buffers are creating a normal speed cache, the purpose of collecting data or keeping data to for some purpose.
  • Cached is created from static RAM (SRAM) so it is faster than dynamic RAM (DRAM) used to create buffers.
  • Buffers are often used for input / output processes, while cached is mainly used for file read / write operations to disk.
  • Cached can be part of a disk (high-speed disk) or RAM while buffers are only part of RAM (disk cannot be used to create buffers)

2.1 Cached

Cached is the size of the Linux page cache, not including swap cached internal memory called SwapCached (so the page cache size is Cached + SwapCached). Linux executes all I / O files via the page cache. This device is used to speed up the reading and writing process as described below.

Excellent: Use the cache to speed up the system
Session, Cookie and Cache, did you really understand them?

Write is very simple to implement, if the page cache page is dirty (dirty corresponding pages), thread flushers will periodically write to any dirty page. See the following example to understand the recording mechanism

Explain as follows:

  • The first command writes a file of 10MB size
  • As we can see, the data of the file is marked as dirty in the page cached by checking in the command number 2, here is 712 kB marked as dirty.
  • The command number 3 helps to force sync data from page cached to disk
  • The number 4 command checks the page cached to see if any data is marked dirty or not, as we see, it is no longer possible (note that it can be> 0 kB due to other processes).

The linux kernel has a flush process to periodically write data from the cached page to the disk, which can be checked as follows

Read is implemented by returning page cached data, if that data is not available in cached, that data will be migrated for the first time from the disk to the page cache. On modern Linux systems, cached can easily be up to GB, and it will scale to meet memory pressure. The system will “delete” the page cache along with the swap data from the page cache to disk to free up more memory if needed.

2.2 Buffers

Buffers are buffer pools of purpose to organize and hold data in a certain memory area until this data is transferred elsewhere. Usually buffers are used in input / output processes that speed and receive data differently (CPU and printer).

For example

  • Text printing: CPU is a high speed device, while the printer is a slow processing device. When a person issues a print job, the printed data will be pushed into the buffers area (the difference with cached is that the area does not need high speed). The printer can then access that buffers area at a crawling speed while the CPU has been freed to do other tasks.
  • CD burning operation: the process is similar to a printer, but the point is that if the data is small, when it is inserted into the buffers area, these data will be grouped into blocks of the size of the size block. .

Before Linux kernel 2.4, there were two separate cached types, the file was in the page cache, the disk block was in the cache buffers. This is a simple way to implement, it is quite obvious but inefficient. From version 2.4, the contents of these two types of cache are merged.

As we can see, the line – / + bufferss / cached has been merged, if adding the buffers and cached columns in the first line and the free column of the first line, it will be equal to the total column number 3 lines number 3

1179 + 248 + 10306 = 11733

Next-step: find out the algorithm applied to page cache and buffers (the ability is LRU with page cache and FIFO with buffers, so we see buffers quite like queues)

3. Ref

  • https://www.quora.com/What-is-the-difference-between-Buffers-and-Cached-columns-in-proc-meminfo-output
  • http://www.differencebetween.net/technology/hardware-technology/difference-between-cache-and-buffer/
What is memoization? What is LRU cache?
What is memcached? Use memcached to speed up the server system
Share the news now