近日發現swap告警。。。
[root@hs-72 mysql]# free -h
total used free shared buff/cache available
Mem: 62G 39G 20G 1.5G 2.9G 20G
Swap: 63G 19G 44G
如上 swap 使用了 19g
此刻 如果我想知道 swap主要是被哪個經常占用。。。
因為 我這是一臺mysql服務器。。如果不是被mysql占用 我理論上 可以不去處理這個swap
使用命令
for i in $( cd /proc;ls |grep "^[0-9]"|awk ' $0 >100') ;do awk '/Swap:/{a=a+$2}END{print '"$i"',a/1024"M"}' /proc/$i/smaps 2>/dev/null ; done | sort -k2nr | head -10
輸出如下值 第一列是pid
head -10
18906 12385.2M
3755 431.055M
38125 400.004M
37271 63.0781M
37852 60.9492M
37661 38.0156M
37088 28.1953M
1997 18.4219M
73344 11.8711M
73331 10.2852M
可以看到pid=18906的這個經常 占用了最多的swap
然后 我們查找 這個pid具體是哪個進程
使用命令
ps -ef|grep 18906
輸出如下值
mysql 18906 18682 4 2017 ? 28-07:00:18 /usr/local/mysql-5.1.73/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysql/mysql_error.log --open-files-limit=30000 --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
root 165972 82503 0 14:51 pts/0 00:00:00 grep --color=auto 18906
發現18906這個進程 剛好是mysql進程。。。
好的 到此為止 就發現了 到底哪個進程在使用swap
之后就是如何取處理這個swap 此處不做介紹
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。