首页 > 技术文章 > 清理linux 系统内存缓存的方法

wzh19820101 2019-12-02 10:27 原文

1、  现象最近一次外呼的时候,发现内存占用比率特别高,有95%左右,以前外呼的时候,内存不会有这么大的占用比率,停止外呼了,占用还是这么高,所以就查看了一下

   

发现是内存的缓存占用比率高,需要清除一下

清除方法

 

[root@guanli1 ~]# cat /proc/sys/vm/drop_caches   查看

0

[root@guanli1 ~]# echo 1 > /proc/sys/vm/drop_caches   清除缓存

[root@guanli1 ~]# top    用top实时查看,发现内存已经下来了

top - 09:54:32 up 77 days, 22:24,  1 user,  load average: 0.14, 0.18, 5.92

Tasks: 596 total,   1 running, 595 sleeping,   0 stopped,   0 zombie

Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:  32629208k total1461396k used, 31167812k free,     2696k buffers

Swap: 33554424k total,        0k used, 33554424k free,    22772k cached

 

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                      

 53012 root      20   0 15432 1636  944 R  0.7  0.0   0:00.04 top                                           

   166 root      20   0     0    0    0 S  0.3  0.0   2:01.10 events/3                                      

 36124 root      20   0 19.5g  57m 2004 S  0.3  0.2   4223:01 ppx_softswitch                                

127602 root      20   0 28.5g 220m  11m S  0.3  0.7  26209:36 java                                           

     1 root      20   0 19356 1540 1228 S  0.0  0.0   0:03.50 init                                          

     2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                      

     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.68 migration/0                                   

     4 root      20   0     0    0    0 S  0.0  0.0   0:04.66 ksoftirqd/0                                   

     5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                   

     6 root      RT   0     0    0    0 S  0.0  0.0   0:01.18 watchdog/0                                    

     7 root      RT   0     0    0    0 S  0.0  0.0   0:01.59 migration/1                                   

     8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1

 

再次查看,已经清理了缓存,ok了

 

 

2、  也可以添加计划任务,定期进行缓存清理

先看crond服务是否启动

/etc/init.d/crond status

/etc/init.d/crond start

 

添加计划任务

crontab -e

 

10  5  *  *  6   echo 1 > /proc/sys/vm/drop_caches    每周六5:10 进行缓存清理

 

查看计划任务列表

 

crontab -l

推荐阅读