Free 命令事实上是读取 /proc/meminfo 里的 Buffers 和 Cached 来表示 buffers / cached。
参考:
内核的 Documentation/filesystems/proc.txt:
Buffers: Relatively temporary storage for raw disk blocks
shouldn't get tremendously large (20MB or so)
Cached: in-memory cache for files read from the disk (the
pagecache). Doesn't include SwapCached
这里可以看到 Buffers 是指磁盘块设备的元数据(不应该太大)
而 Cached 是指 page cache。
代码可以参考:
Buffers:
long nr_blockdev_pages(void)
{
struct block_device *bdev;
long ret = 0;
spin_lock(&bdev_lock);
list_for_each_entry(bdev, &all_bdevs, bd_list) {
ret += bdev->bd_inode->i_mapping->nrpages;
}
spin_unlock(&bdev_lock);
return ret;
}
cached = global_page_state(NR_FILE_PAGES) -
total_swapcache_pages - i.bufferram;