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:

I'm running Ubuntu 9.10 on my server. It works fine, it's just that over time (usually a couple of days) the memory usage just grows and grows until it invariably runs out and needs to be rebooted.

It's running Apache, Samba, ProFTPd, Postfix, Munin & Webmin.

Is there anything that can be done to free up the memory that it doesn't need anymore?

share|improve this question

marked as duplicate by Michael Hampton Aug 6 '14 at 3:59

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.

up vote 5 down vote accepted

Depends on how you are counting used memory. If you are looking at "free", make sure to discount the cached and buffers used.

Linux tries to cache as much disk activity as it can so that subsequent accesses to those files is much faster than having to go to the disk again. If memory is required, cache memory will be released to satisfy the new request.


# free
         total       used       free     shared    buffers     cached
Mem:       3973040    3944864      28176          0     433448    3123468
-/+ buffers/cache:     387948    3585092
Swap:      2040244      72080    1968164

In this case, while the system is reporting almost all 4G of memory as used, closer examination shows that 3G of it is "cached", meaning that there is actually plenty of memory available. The second line of the free output represents that calculation -- excluding buffers and cache, there is 3.5G available memory.

share|improve this answer
That's something I hadn't thought of...I was assuming he was getting out of memory errors or some kind of lockup. Is that the case? – Bart Silverstrim May 5 '10 at 14:42

You don't need to reboot your server to free up memory. Use the top command to identify which process uses the memory and restart it and try to diagnose what causes the abnormal memory consumption.

For the probable cause of your problem, this is kind of a shot in the dark but there is a well-known memory leak in console-kit-daemon, an Ubuntu-specific daemon which you can just kill and remove from rcX.d.

share|improve this answer

Google information on resource quotas on Linux. I'd also look to see what process is ballooning up to take up all that memory. You don't mention how much memory you have on that system, either; is it just a case where you need to get more memory for the server? Without watching the resource usage and seeing what is hitting what process, you don't know if it's just gradual memory usage taking it up or if there's a resource leak/application issue causing it.

How many users are hitting that server? What is the workload? How much memory does it have in it already? What errors, if any, are in the log just before, during, and after the memory issues?

I'd also point out that using resource limits/quotas will mean setting up a process to act as a watchdog to restart processes that are killed, and it's not very clean to do so, as it may force-kill processes and things that rely on disk i/o or databases probably won't like being killed off quite suddenly. You might want instead to focus on finding which process is the troublemaker and fix or isolate it. Worse, you may have an attack going on that is causing the memory usage to balloon, or an out of control cron job, something like that. Killing the processes or rebooting isn't fixing the problem, it's helping hide the problem.

share|improve this answer

If the problem is only with the the buffers and caches you can always force the kernel to drop them. Just do:

echo 1 > /proc/sys/vm/drop_caches (to free pagecache)

echo 2 > /proc/sys/vm/drop_caches (to free dentries and inodes)

echo 3 > /proc/sys/vm/drop_caches (to free pagecache, dentries and inodes)

share|improve this answer