How to check which swap often takes up swap when the swap is too high?
Recently, a swap alarm was found.
[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
As above, swap uses 19g.
At the moment, if I want to know which swap is mainly occupied by.
Because this is a mysql server. If it wasn't occupied by mysql, I wouldn't have to deal with this swap in theory.
Use the command
For i in $(cd / proc;ls | grep "^ [0-9]" | awk'$0 > 100'); do awk'/ Swap:/ {a=a+$2} END {print'"$I", a proc/$i/smaps 1024 "M"}'/ proc/$i/smaps 2 > / dev/null; done | sort-k2nr | head-10
The output is as follows. The first column is 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
You can see that pid=18906 often takes up the most swap.
Then we find out which process the pid is.
Use the command
Ps-ef | grep 18906
The output is as follows
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
It is found that 18906 this process happens to be a mysql process.
Okay, so far, we've found out which process is using swap.
After that, how to take and deal with this swap is not discussed here.