Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

linux内存占用越来越高

image.png
image.png

mysql占用内存越来越高,但也就16G*34%=5.44G,为什么上面Mem的used达到15G多。
请问上面的Mem use、free、buffers和swap怎么解释?现在可用的内存到底剩下多少呢?如果使用了15G,那么被什么进程占用了呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1、 free -m 命令看下是否 cache 内存很多
2、手动执行下下面的 sh 脚本,把 cache 的内存释放下,之后可以把这个脚本放到 crontab 中执行,每天定时清理下,目前设置可用内存小于4G, 执行释放脚本,你可以看着修改下,符合自己内存需求的值

#! /bin/sh
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
log_path=/tmp/mem.log
echo "===========================" >> $log_path
date >> $log_path
echo "Memory usage before | [Use:${used}MB][Free:${free}MB]" >> $log_path
if [ $free -le 4000 ] ; then
                sync && echo 1 > /proc/sys/vm/drop_caches
                sync && echo 2 > /proc/sys/vm/drop_caches
                sync && echo 3 > /proc/sys/vm/drop_caches
                                used_ok=`free -m | awk 'NR==2' | awk '{print $3}'`
                                free_ok=`free -m | awk 'NR==2' | awk '{print $4}'`
                                echo "Memory usage after | [Use:${used_ok}MB][Free:${free_ok}MB]" >> $log_path
                echo "OK" >> $log_path
else
                echo "Not required" >> $log_path
fi
exit 1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...