[20160902]linux命令free的buffers与cached表示什么.txt
--简单探究linux的free命令。
$ free
total used free shared buffers cached
Mem: 132261196 29620656 102640540 0 174340 24209712
-/+ buffers/cache: 5236604 127024592
Swap: 31455264 10592 31444672
-/+ buffers/cache的used: used - buffers - cached
29620656- 174340-24209712=5236604
-/+ buffers/cache的free: free + buffers + cached
102640540+ 174340+24209712=127024592
--而buffers和cached表示什么呢?
下面是关于buffers和cached的英文资料:
Buffers are associated with a specific block device, and cover caching of filesystem metadata as well as tracking
in-flight pages. The cache only contains parked file data. That is, the buffers remember what's in directories, what
file permissions are, and keep track of what memory is being written from or read to for a particular block device. The
cache only contains the contents of the files themselves.
-- buffers 缓存,主要用于块设备缓存,例如用户目录、inode值等(ls大目录可以看到这个值增加)
-- cached 缓存,主要用于缓存文件。
--所以讲free memory很少,不用担心,用来缓存文件了,另外可以如下命令来释放相关内存。
--To free pagecache:
# echo 2 >| /proc/sys/vm/drop_caches
$ free
total used free shared buffers cached
Mem: 132261196 7420620 124840576 0 174368 2662916
-/+ buffers/cache: 4583336 127677860
Swap: 31455264 10592 31444672
--//你可以对比上面buffers几乎不变。而cached减少了不少。
--To free dentries and inodes:
# echo 1 >| /proc/sys/vm/drop_caches
# free
total used free shared buffers cached
Mem: 132261196 6709548 125551648 0 1008 2228344
-/+ buffers/cache: 4480196 127781000
Swap: 31455264 10592 31444672
--//对比上面buffers减少很多,cached几乎不变,再次验证文档的内容。如果执行
--# To free pagecache, dentries and inodes:
--# echo 3 >| /proc/sys/vm/drop_caches
--这个测试大家可以自己测试。
--可以在反向验证这个判断。
# cd /
# ls -lR > /dev/null
--然后打开另外的窗口观察:
# free
total used free shared buffers cached
Mem: 132261196 6798588 125462608 0 15512 2232348
-/+ buffers/cache: 4550728 127710468
Swap: 31455264 10592 31444672
# sleep 5
# free
total used free shared buffers cached
Mem: 132261196 6969776 125291420 0 66568 2232716
-/+ buffers/cache: 4670492 127590704
Swap: 31455264 10592 31444672
# sleep 5
# free
total used free shared buffers cached
Mem: 132261196 7347624 124913572 0 117412 2458840
-/+ buffers/cache: 4771372 127489824
Swap: 31455264 10592 31444672
--增加主要的是buffers,也就是缓存用户目录、inode值等。希望通过这个简单的测试理解linux命令free的内容。