Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

my webserver is running apache 1.3.x for a PHP application, along with mysql on the same machine. Most of the time it runs fine, CPU usage still with nice margin, but somehow memory usage keeps growing throughout uptime.

While it looks like it is chunked from time to time, I've had moments my server going down because it's out of memory. Restarting apache or mysql only reduced memusage by 100M.

Attached is an overview of monthly memory usage. The 2 massive drops are server restarts after out-of-memory situations.

Any explanations for his behaviour or how I could solve this?

Thanks! Steven

share|improve this question

marked as duplicate by Michael Hampton Aug 6 '14 at 4:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

The blue section at the top of the graph is "unused" memory according to the legend and does not appear that it ever goes below 150MB free. What exactly is leading you to believe that you ran out of RAM? Was the OOM killer triggered? – DerfK Jun 29 '11 at 1:27

The linux memory management basically tries to employ all possible memory. The "free" space is continually used up as buffer caches in an attempt to be efficient. This grows over time BUT as new process need more memory and as the free pool dwindles, the memory manager will return the buffer cache as needed. Thus you see perhaps a fraction of the memory being released when you terminate some processes. This buffer caching does not lead to an out of memory condition however.

Question: are you using a 32-bit or a 64-bit linux version. If you are using a 32-bit version, then it is possible that one of the apache processes of mysql bumped into the 2GB process memory limit and thus reported out of memory. This is just a guess however.

Are you running other things other than apache and mysql that could be taking memory. Some badly coded java apps have been leakers as well. It is not clear again that any of your other process could be causing a memory problem.

Some investigation into the system, mix of processes, mysql configuration parameters could be in order.

BTW, I understand that you can flush the buffer cache using the following command (as root):

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

However, this is not really something I'd recommend you do in a production situation but might be interesting in a testing or benchmark environment.

Hope this helps.

share|improve this answer
32 bit Linux allows 3GB virtual memory address space for user space for each process. HugeMem kernels allow 4GB virtual memory user space for each process. To access memory some software (like Oracle DB) are using mmap (similar results as AWE in Windows). – Mircea Vutcovici Jun 29 '11 at 1:40

The behavior shown by your graph is normal for linux/unix as it will use all available memory all the time in order to better manage itself - there are countless articles discussing this behavior if you feel like knowing more. This is why restarting mysql or apache only results in a small "gain."

Since you cannot "solve" this particular behavior, you need to examine what is happening to cause the out-of-memory problem. It's not difficult for Apache + php to create a race condition, either from a spike in traffic or a bug in the app(s) you are running.

Adjusting the limits in your apache config, adjusting the connection and memory limits for mysql, installing an opcode cache for php are all ways to get more performance out of your existing setup.

Feel free to post more details or another question to get additional assistance.

Good luck!

share|improve this answer

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