linux的内存查看:
[root@localhost 0.1.0]# free -m
total used free shared buffers cached
Mem: 4032 694 3337 0 0 25
需要说明的是,mem的used=free+buffers+cached,有些情况是cached占用很多资源,算起来数值就是不对,其实不影响实际使用,下面转载部分有说明如何清除cached的占用(实际上可以不清除,不会影响实际使用)
当在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching。这个问题,貌似有不少人在问,不过都没有看到有什么很好解决的办法。那么我来谈谈这个问题。
引用/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.
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.