Understanding “Buffers” and “Cached” from free command

前端 未结 5 1187
独厮守ぢ
独厮守ぢ 2021-01-30 11:47

This has been asked earlier but don\'t want to update the same thread again as it was a old thread .

Want to clarify myself on the \"buffers\" and \"cache\" column from

相关标签:
5条回答
  • 2021-01-30 12:08

    This is my understanding: the buffers tells you how much memory is reserved for maintaining block devices, but cache tells you how many memory is used for file contents.

    0 讨论(0)
  • 2021-01-30 12:12

    Linux vm sub-system treats any free or unused or non-allocated memory as buffers/cache

    Therefore, running echo 1 > /proc/sys/vm/drop_caches instructs the kernel to drop or clean the page caches (page-cache), dentries (slab-cache), and inodes (in the slab-cache) and causing the memory to become reclaimed and available.

    Clean data cache pages are not freed by design. They can be easily reclaimed by the kernel if or when extra memory is to be allocated (malloc/calloc/brk/sbrk and friends), while they contain useful data from disks that if needed again saves doing a disk I/O.

    sync command only commits any dirty pages in the memory to the disk, it does not free the buffers/cache. The only way to drop buffers/cache is by using echo "1" > /proc/sys/vm/drop_caches or the kernel reclaims the data pages for new allocated requested by applications

    pdflush has been replaced by using flushing threads per backing device info (BDI).

    0 讨论(0)
  • 2021-01-30 12:12

    Quoting from RHEL:

    Linux always tries to use RAM to speed up disk operations by using available memory for buffers (file system metadata) and cache (pages with actual contents of files or block devices).


    Quoting from serverFault

    shared / buffers / cached: This shows memory usage for specific purposes, these values are included in the value for used.

    The second line gives first-line values adjusted. It gives the original value for used minus the sum buffers+cached and the original value for free plus the sum buffers+cached, hence its title. These new values are often more meaningful than those of the first line.

    The last line Swap gives information about swap space usage. For example memory contents that have been temporarily moved to disk.

    0 讨论(0)
  • 2021-01-30 12:18

    The column headers in the free command are somewhat mislabeled, at least from the point of view of a linux user (as opposed to developer). Below is a clarification of what the headings mean:

    total: Yes, this is total ram.

    used: This is probably the most confused column. This is a mix of application used memory and other 'temporarily' (buffer + cache) used memory that is actually available if needed. So technically the memory is truly being used, but much of this memory is available if an application needs it. The 'temporarily' used memory is borrowed if available by the linux system to help speed up system performance, otherwise the system would have read from disk more often. Much of this type of memory is shown under the 'cached' column. This memory is given up by the linux system if an application need memory.

    free: Yes, this pure free and untouched memory.

    shared: Memory specifically allocated for use by multiple processes

    buffers: Temporary memory that is set aside to help some processes

    cache: Memory that is available and 'borrowed' by the operating system to help speed up many linux OS operations. This memory is given up by the system if an application need it.

    The line that starts with -/+ buffers/cache is typically more helpful than the first Mem line. The intersection of free and -/+ buffers/cache is essentially what you have for 'available' memory.

    0 讨论(0)
  • 2021-01-30 12:22

    The way I've always understood it is that the buffer area of memory is for temporary storage of data being read from or written to devices (including disks), while the cache area of memory is for speeding up future reads from a device.

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