这些cache起来的内容可以增加文件以及的读写速度。
先说下free命令怎么看内存
[root@yuyii proc]# free
total used free shared buffers cached
Mem: 515588 295452 220136 0 2060 64040
-/+ buffers/cache: 229352 286236
Swap: 682720 112 682608
其中第一行用全局角度描述系统使用的内存状况:
total——总物理内存
used——已使用内存,一般情况这个值会比较大,因为这个值包括了cache+应用程序使用的内存
free——完全未被使用的内存
shared——应用程序共享内存
buffers——缓存,主要用于目录方面,inode值等(ls大目录可看到这个值增加)
cached——缓存,用于已打开的文件
note:
total=used+free
used=buffers+cached (maybe add shared also)
第二行描述应用程序的内存使用:
前个值表示-buffers/cache——应用程序使用的内存大小,used减去缓存值
后个值表示+buffers/cache——所有可供应用程序使用的内存大小,free加上缓存值
note:
-buffers/cache=used-buffers-cached
+buffers/cache=free+buffers+cached
第三行表示swap的使用:
used——已使用
free——未使用
cache释放:
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
说明,释放前最好sync一下,防止丢数据。
If you mean the difference between the "cache" and "buff" columns in vmstat I believe the "cache" is file contents being cached in memory and "buff" is things like "inodes".
When writing a hugh file I see usage of both go up. When I use O_DIRECT, which is supposed to bypass the page cache, I only see "buff" go up".
Not being a Linux Guru I spent some quality grep time in the kernel source tree and tracked back what vmstat prints with data structure members in the kernel which seemed to comfirm that certain types of pages were cached in "buff" and the one type I believe I saw was inodes(or the equivalent thereof).
沒有留言:
張貼留言