Free up memory ?

Hello Everyone,

I have a server with a total of 48Gb of RAM, but every 2 -3 weeks ,its gets full, and when ever i try to clear up the memory using this command :-

sync; echo 3 > /proc/sys/vm/drop_caches

It does NOT free up any memory at all.

My current usage is as follows :-

[root@Newdbsrv ~]# free -g
total used free shared buffers cached
Mem: 47 42 4 0 0 0
-/+ buffers/cache: 42 4
Swap: 50 0 50

Now, probably by the end of this week, The server will run out of free memory and it may hang and may have to be booted.

Can anybody suggest, how can i clear or free up memory ?

Thank you

Does the system actually hang when it says the memory is all used up? It is not uncommon to see that all of the memory is being used, as MySQL will eventually grab it all sooner than later. But that does not mean it is actively using every bit of it, so generally there is no issue there. Normally you should not need to worry unless the system starts using swap memory (bottom row in your “free -g” command). If it starts using up much of the swap memory then that means it is attempting to use more memory than is available.

If your system does actually crash, I’d take a look to see what other services are running on the server (i.e. a web server of FTP server or something?) that may be using up resources. Then you’d need to look to see what was actually happening at the time in MySQL, as it could just be the problem you’ve had before where you get queries backed up and it eventually kills the system.

Hello Scott,

Thank you for your revert :slight_smile:

Not really, Infact when things go bad, we aren’t logged into the server or not in the office et all :frowning:

The server is now up for 20 days, But every time it has booted was because of excessive CPU usage, as this is what the owner of the server says, But for the last 20 days i have been monitoring it and it is pretty much normal.

I guess, when the server starts to run out of RAM it affects the CPU and then it crashes or has to be rebooted to free up memory , and that is what my concern is, coz now i see the free memory is 4GB…and hence i posted here to see if i can find a way to clear up memory …

Thank you,

Given that description it sounds like MySQL is getting backed up like you have seen in the past, which then uses up all available memory, which causes the work load to hit the disk, which then backs up the I/O and causes the CPU to spike and eventually crumble.

Were you ever able to get that monitoring bash script setup to write the processlist and InnoDB stats out to a file when the MySQL connections spiked up? That is still your best bet to see what is going on when things go sideways.

Regardless of what your free memory says, if the server gets slammed it will end up in the same situation. Meaning if memory is at 50%, and MySQL gets swamped like you are saying, then it is going to use up all the memory anyway. So if it’s at 50% or 100%, it really does not matter in this case as the only difference may be a slightly longer ramp up period before the server crashes.

So the first step (as it has always been) is still to find out what queries (and their source) are causing MySQL to get backed up. One temporary thing you could do would be to setup a script and / or use pt-kill to kill long running queries, which may stop MySQL from getting backed up by killing any queries that are blocked or simply taking too long. But you would of course lose any work the query was attempting to do (how bad this is would depend on how smart the application is as far as handling rollbacks), and would just be a band-aid until you find the source of the problem.