免费中由“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