快速回收linux缓存
内存告急:
free -m
total used free shared buffers cached
Mem: 15928 15774 154 0 298 1103
-/+ buffers/cache: 14371 1556
Swap: 7983 0 7983
grep Pss /proc/[1-9]*/smaps | awk '{total+=$2}; END {print total/1024}'
3591.84
cat /proc/slabinfo |awk 'BEGIN{sum=0;}{sum=sum+$3*$4;}END{print sum/1024/1024}'
9985.24 #slab占用较多
cat /proc/meminfo
Slab: 10894564 kB
SReclaimable: 10860552 kB
SUnreclaim: 34012 kB
echo 2 > /proc/sys/vm/drop_caches
Slab: 130720 kB
SReclaimable: 96948 kB
SUnreclaim: 33772 kB
已回收:
free -m
total used free shared buffers cached
Mem: 15928 4279 11648 0 296 138
-/+ buffers/cache: 3844 12083
Swap: 7983 0 7983
drop_caches接受以下三种值:
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches