free命令出自 procps util 包,根据源码free命令其各项输出意义与/proc/meminfo对应关系,其中:
total = MemTotal
free = MemFree
used = MemTotal - MemFree - Cached - Slab - Buffers
shared = Shmem
buffers = Buffers
cache = Cached + Slab
available 有三种情况:
- kernel>3.14,直接使用MemAvailabe
- 2.6.27 <= kernel <? 3.14 通过计算得出,该部分与MemAvailabe稍有差别,但统计思路是一致的。计算方法如下
MemFree - watermark_low +
‘Inactive(file)’ + ‘Active(file)’ - MIN((‘Inactive(file)’ + ‘Active(file)’) / 2, watermark_low) +
SReclaimable - MIN(SReclaimable / 2, watermark_low) - kernel < 2.6.27,直接使用MemFree
对于1在内核态(4.15.0-58)MemAvailabe计算方式为:
MemAvailable = MemFree - totalreserve_pages +
‘Inactive(file)’ + ‘Active(file)’ - MIN((‘Inactive(file)’ + ‘Active(file)’) / 2, watermark_low) +
SReclaimable - MIN(SReclaimable / 2, watermark_low) +
global_node_page_state(NR_INDIRECTLY_RECLAIMABLE_BYTES) >> PAGE_SHIFT (内存压力大时可释放部分内存)
totalreserve_pages为内核reserve内存
watermark_low为各zone的watermark内存低水位线之和,也即达到该水位线,内核将不再主动回收内存