2

I am suspecting some swap actitivies in my MySQL box. I ran the "top" utility it gave me only 51MB of swap took place.

However, when I enabled the "Swap" column in top utility, it showed that there were actually 12g of swap used by mysqld.

Can you tell me which is the accurate information? Is there any swap taking place?

enter image description here

Luca Angioloni
  • 2,243
  • 2
  • 19
  • 28
Haans
  • 73
  • 1
  • 1
  • 7

1 Answers1

2

Edit: From what I've read, SWAP column in the output of top is really just VIRT - RES. It's an assumption that part of the process has been swapped out. It's difficult or impossible to get an accurate measure of how much swap a given process is using.

If you're on Linux or one of the UNIX flavors that support /proc, you can use this to get the actual usage:

cat /proc/18810/status

(Where 18810 is the PID of your mysqld process.)

It'll show you a bunch of fields for actual memory usage. Here's an except from the mysqld process in my development VM:

VmPeak:  3258116 kB
VmSize:  3258116 kB
VmLck:   1416344 kB
VmHWM:   1180788 kB
VmRSS:   1180780 kB
VmData:  3189940 kB
VmStk:        88 kB
VmExe:     11608 kB
VmLib:      7312 kB
VmPTE:      2540 kB
VmSwap:        0 kB

The VmSwap of 0 indicates that it is not currently using any swap.

See http://man7.org/linux/man-pages/man5/proc.5.html or just man 5 proc for information on the other fields. The manual says in part:

  • VmSwap: Swapped-out virtual memory size by anonymous private pages; shmem swap usage is not included (since Linux 2.6.34).

Re your comment:

Apparently you use a version of Linux too old to include the VmSwap field in per-process status.

You can read /proc/meminfo and find out the total swap space in use on the server, but this doesn't tell you per process.

You can also run vmstat to watch for swap activity. If the "si" and "so" fields are zero, you're okay.

See https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/sect-Oracle_9i_and_10g_Tuning_Guide-Swap_Space-Checking_Swap_Space_Size_and_Usage.html

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • I ran the proc in RedHat linux but couldn't find the VmSwap output. `cat /proc/18810/status Name: mysqld State: S (sleeping) SleepAVG: 92% Tgid: 18810 Pid: 18810 PPid: 18780 TracerPid: 0 Uid: 501 501 501 501 Gid: 501 501 501 501 FDSize: 16384 Groups: 501 VmSize: 101891248 kB VmLck: 0 kB VmRSS: 88391188 kB VmData: 101868740 kB VmStk: 56 kB VmExe: 6257 kB VmLib: 2223 kB ...` – Haans Jan 24 '17 at 01:32
  • "The SWAP column in the output of top shows how much swap it would use if it had to swap" --- this really need further elaboration: why is it 12g not 84g, for example? – zerkms Jan 24 '17 at 07:04
  • Another explanation: SWAP is a fake number, it's simply `VIRT - RES`. As described here: http://stackoverflow.com/questions/479953/how-to-find-out-which-processes-are-swapping-in-linux – Bill Karwin Jan 24 '17 at 16:27
  • I have edited my answer and changed the first paragraph. – Bill Karwin Jan 25 '17 at 15:00