linux释放内存

0 Problem

跑实验的时候,ctrl+c中断后free -m发现used占用太多,64G内存占用了50多G,其中有48G的cached,cached占用太大,久久不消。

(Cache,译作“缓存”,指 CPU 和内存之间高速缓存。Buffer,译作“缓冲区”,指在写入磁盘前的存储再内存中的内容)

 

1 Solution

清理caches

sync # 强制被改变的内容写入磁盘。通常不需sync,系统会自动写入。

echo
3 > /proc/sys/vm/drop_caches # 释放cache。

 

2 Explanation

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
As this is a non-destructive operation, and dirty objects are notfreeable, the user should run "sync" first in order to make sure allcached objects are freed. This tunable was added in 2.6.16.

 

posted @ 2017-10-18 11:00  PilgrimHui  阅读(957)  评论(0编辑  收藏  举报