3

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?

4 Answers4

5

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.

Eg:

# 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.

David Mackintosh
  • 14,223
  • 6
  • 46
  • 77
  • 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 05 '10 at 14:42
2

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.

François Feugeas
  • 1,393
  • 9
  • 17
1

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.

Bart Silverstrim
  • 31,092
  • 9
  • 65
  • 87
-1

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)

mndo
  • 170
  • 2