Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was having 768 MB RAM. In a general day MySQL was using 100-180 mb of RAM and MySQL was swapping 80-120 mb. I was having 50-60 mb free RAM.

So I thought I should upgrade. Then I upgraded my RAM to 1 GB. After that, I have 200-350 mb free RAM. But MySQL uses same amount of RAM but still swaps 40-60 mb.

That is my free -m result.

             total       used       free     shared    buffers     cached
Mem:           996        796        200          0         73         97
-/+ buffers/cache:        625        371
Swap:         2047         92       1955

This is my top result

top - 22:11:23 up 13:35,  1 user,  load average: 0.26, 0.33, 0.35
Tasks: 143 total,   1 running, 142 sleeping,   0 stopped,   0 zombie
Cpu(s): 20.2%us,  1.8%sy,  0.0%ni, 77.8%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1020564k total,   809836k used,   210728k free,    77808k buffers
Swap:  2097144k total,    94880k used,  2002264k free,   102596k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP COMMAND
 2484 mysql     20   0 1845m 165m 4356 S 25.9 16.6 151:33.45  63m mysqld
13777 myuser  20   0  201m  22m 9836 S  0.0  2.3   0:00.42    0 php-cgi
13780 myuser  20   0  200m  21m 9820 S  3.3  2.2   0:00.47    0 php-cgi
13773 myuser  20   0  200m  21m 9820 S  0.0  2.2   0:00.70    0 php-cgi
13775 myuser  20   0  200m  21m 9812 S  5.3  2.2   0:00.42    0 php-cgi
13779 myuser  20   0  200m  21m 9812 S  3.0  2.2   0:00.31    0 php-cgi
13778 myuser  20   0  200m  21m 9812 S  3.6  2.2   0:00.31    0 php-cgi
13776 myuser  20   0  200m  21m 9812 S  3.0  2.2   0:00.31    0 php-cgi
13774 myuser  20   0  199m  20m 9812 S  0.0  2.1   0:00.23    0 php-cgi
 2619 named     20   0  233m 9.8m 1388 S  0.0  1.0   0:04.57 5288 named
 2689 root      20   0  328m 7528 6316 S  0.0  0.7   0:05.14 9648 httpd
13735 root      20   0  106m 4840 3756 S  0.0  0.5   0:00.26    0 sshd
12772 apache    20   0  328m 3932 2040 S  0.0  0.4   0:01.08 9392 httpd
13163 apache    20   0  328m 3916 2036 S  0.0  0.4   0:00.65 9400 httpd
13425 apache    20   0  328m 3912 2036 S  0.0  0.4   0:00.32 9404 httpd
13417 apache    20   0  328m 3908 2036 S  0.0  0.4   0:00.35 9412 httpd
13420 apache    20   0  328m 3908 2036 S  0.0  0.4   0:00.37 9412 httpd

Although I have 371 mb free RAM, my CentOS 6.3 system still swaps. Now swapping is 90 mb.

My question is although I have much free RAM, why Linux still swaps? If it was a bad situation how can I diagnose more? Or shouldn't I care about it?

share|improve this question
    
You can't say "MySQL is swapping this much memory", it is the whole system which is using swap. There is no clearcut "this process uses this much memory" number, as much is shared among processes. But yes, MySQL is swapping vigourously. –  vonbrand Feb 9 '13 at 21:05
add comment

2 Answers 2

Your mysqld is configured to use 1,8 GB of RAM - propably due to your settings in /etc/my.cnf. This is much more than is physically available.

Now in some point of time (you might install sysstat and ask sar about that) you seem to get memory requests (might be PHP, too) that use more RAM than is available - so the systems starts to swap.

At the end of this the memory is not used any more, but there is also no access to it. So the system has no reason to put that swap-space back into RAM.

You can tune the "swappiness" of Linux to change this behaviour.

There is a good question/answer on "Ask Ubuntu" here.

share|improve this answer
add comment

I see you ran apache with 1G ram, i had a vps last year and had your problem. apache need about 300-400 K ram and this is very bad for a VPS, i removed apache and installed lighthttpd. you do it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.