Linux 清理 cache 内存
2023-01-15 本文已影响0人
偷油考拉
一、如下所示,内存cache大
ubuntu@VM-10-13-ubuntu:~$ free -m
total used free shared buffers cached
Mem: 15881 15441 439 2 157 8161
-/+ buffers/cache: 7122 8758
Swap: 0 0 0
二、清理cache
1. 执行同步
sudo sync
2. 清理cache
ubuntu@VM-10-13-ubuntu:~$ cat /proc/sys/vm/drop_caches
0
ubuntu@VM-10-13-ubuntu:~$ sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
ubuntu@VM-10-13-ubuntu:~$ cat /proc/sys/vm/drop_caches
3
3. 观察结果
ubuntu@VM-10-13-ubuntu:~$ free -m
total used free shared buffers cached
Mem: 15881 6697 9183 2 4 73
-/+ buffers/cache: 6618 9262
Swap: 0 0 0
附
ubuntu@VM-4-13-ubuntu:~$ free -m
total used free shared buffers cached
Mem: 15881 15453 427 1 141 13421
-/+ buffers/cache: 1889 13991
Swap: 0 0 0
ubuntu@VM-4-13-ubuntu:~$ sudo sync
ubuntu@VM-4-13-ubuntu:~$ sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
ubuntu@VM-4-13-ubuntu:~$ free -m
total used free shared buffers cached
Mem: 15881 1746 14134 1 4 57
-/+ buffers/cache: 1684 14196
Swap: 0 0 0
ubuntu@work1:~$ free -m
total used free shared buffers cached
Mem: 15881 15423 457 2 138 8184
-/+ buffers/cache: 7100 8780
Swap: 0 0 0
ubuntu@work1:~$ sudo sync
ubuntu@work1:~$ sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
ubuntu@work1:~$ free -m
total used free shared buffers cached
Mem: 15881 6643 9237 2 1 53
-/+ buffers/cache: 6589 9292
Swap: 0 0 0
参考文档
https://zhuanlan.zhihu.com/p/95813254
https://www.cnblogs.com/hellokitty2/p/10088042.html