linux查看缓存的文件,linux – 如何查看缓冲和缓存的数据

免费中由“buffers / cache”表示的内存分别是您的磁盘和文件系统缓存,Linux缓存以加速从磁盘读取数据,因为访问磁盘通常是一种反复访问数据的相当慢的方式.因此,它们被缓存在内存中,如果可用的话,从那里透明地提供服务.

您可以使用fincore查看缓存中当前有哪些块.以下是项目页面中的示例:

# fincore --pages=false --summarize --only-cached *

stats for CLUSTER_LOG_2010_05_21.MYI: file size=93840384 , total pages=22910 , cached pages=1 , cached size=4096, cached perc=0.004365

stats for CLUSTER_LOG_2010_05_22.MYI: file size=417792 , total pages=102 , cached pages=1 , cached size=4096, cached perc=0.980392

stats for CLUSTER_LOG_2010_05_23.MYI: file size=826368 , total pages=201 , cached pages=1 , cached size=4096, cached perc=0.497512

stats for CLUSTER_LOG_2010_05_24.MYI: file size=192512 , total pages=47 , cached pages=1 , cached size=4096, cached perc=2.127660

stats for CLUSTER_LOG_2010_06_03.MYI: file size=345088 , total pages=84 , cached pages=43 , cached size=176128, cached perc=51.190476

至于如何清除它们,从man 5 proc:

/proc/sys/vm/drop_caches (since Linux 2.6.16)

Writing to this file causes the kernel to drop clean caches, dentries, and inodes from memory, causing that memory to become free. This can be useful for memory management testing and performing reproducible filesystem benchmarks. Because writing to this file causes the benefits of caching to be lost, it can degrade overall system performance.

To free pagecache, use: echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes, use: echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes, use: echo 3 > /proc/sys/vm/drop_caches

Because writing to this file is a nondestructive operation and dirty objects are not freeable, the user should run sync(8) first.

您通常不希望刷新缓存,因为它的整个目的是提高性能,但出于调试目的,您可以使用drop_caches这样做(注意:您必须是root用户才能使用drop_caches,但同步可以完成任何用户):

# sync && echo 3 > /proc/sys/vm/drop_caches

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值