Linux上free命令的输出

时间:2023-03-09 13:29:14
Linux上free命令的输出

一、明确概念

    • A buffer is something that has yet to be "written" to disk. 
    • A cache is something that has been "read" from the disk and stored for later use.

也就是说buffer是用于存放要输出到disk(块设备)的数据的,而cache是存放从disk上读出的数据。

从应用场景上看:Buffer 更多的(场景)是减小写操作的冲击,而 Cache 主要用于减小读 I/O 的重复开销。

The terms "buffer" and "cache" tend to be used interchangeably,  note however they represent different things.

(1)A buffer is used traditionally as an intermediate temporary store for data between a fast and a slow entity.

As one party would have to wait for the other affecting performance, the buffer alleviates this by allowing entire

blocks of data to move at once rather then in small chunks. The data is written and read only once from the buffer.

Furthermore, the buffers are visible to at least one party which is aware of it.

(2)A cache on the other hand by definition is hidden and neither party is aware that caching occurs. It as well

improves performance but does that by allowing the same data to be read multiple times in a fast fashion.

A further explanation of the differences between two can be found here.

二、命令输出

             total       used       free     shared    buffers     cached
Mem: 498 154 343 0 23 65
-/+ buffers/cache: 65 433
Swap: 1023 0 1023

Men:total = Men:used + Men:free

已使用     -buffers/cache = Mem:used - Men:buffers - Men:cached  = 154-23-65 = 154-88 = 66  (1024byte = 1M )

还剩余     +buffers/cache = Men:free  + Men:buffers + Men:cached  = 343+23+65 = 343+88 = 431

参考

spring-cache

java.nio.buffer

美团:磁盘I/O那些事