查看系统内存占用

free命令(可以使用free -m,表示以MB作为单位):

屏幕快照 2016-12-05 上午10.18.06.png

系统真实使用的内存是:used-buffers-cached

buffers和cached对于应用程序来说是可用的,因为这两种内存是为了提升文件读取性能而设置的,当应用程序需要内存时,这两种内存能很快被回收。

通过top命令查看进程内存占用:
top -d 10 -p $pid

屏幕快照 2016-12-05 上午11.56.43.png

每隔十秒刷新一次,%MEM为进程内存占用百分比。

cached用于缓存打开的文件,频繁文件访问会导致系统cached增大,可以通过linux命令释放掉这块儿内存,
首先运行sync将dirty的内容写回硬盘:
$sync
然后通过修改proc系统的drop_caches清理free的cache:
$echo 3 > /proc/sys/vm/drop_caches

drop_caches的详细文档如下:
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容