0
点赞
收藏
分享

微信扫一扫

关于 Free 的 buffers / cached

残北 2023-05-04 阅读 48


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:


cached = global_page_state(NR_FILE_PAGES) -
			total_swapcache_pages - i.bufferram;




举报

相关推荐

0 条评论