本文主要是介绍关于 Free 的 buffers / cached,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;
这篇关于关于 Free 的 buffers / cached的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!