Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I have a server (P4, 512 mb DDR2 RAM), and LAMP (Debian Lenny) installed on it. The free memory reduces very fast, and I have to restart apache & mysql to fix it. In top I see a lot of IDLE apache processes, which eats a lot of memory. How I can configure the server to fix it? (already added restart script to cron, but it's not a solution, I think) Thank you, sorry for my bad English.

Output of free:

ax-host:~# free 
     total  used   free  shared buffers cached
Mem: 516048 115356 400692 0     20732   54752 
-/+ buffers/cache: 39872 476176 
Swap: 1515512 17568 1497944
share|improve this question
Is it leading to performance issues? Why are you worried about the memory usage? – jgoldschrafe Nov 4 '10 at 12:31
What's the issue? Apache and MySQL both "take" free memory and use it as cache. If you're not seeing any performance issues, this is par for the course. – Chris S Nov 4 '10 at 12:35

My guess is that most of your memory is getting used for disk cache - this is a good thing, and not something that you need to be concerned about, as the kernel will allocate that RAM to applications that need it immediately when requested. See here for more explanation on this. Post the output of free to confirm what's using your memory if you'd like.

share|improve this answer
I'm looking to htop output, and see, which application uses memory (in percent). Most memory is being used by apache and mysql – user59178 Nov 4 '10 at 13:27
As suggested, post the output of free above. – EEAA Nov 4 '10 at 13:47
ax-host:~# free total used free shared buffers cached Mem: 516048 115356 400692 0 20732 54752 -/+ buffers/cache: 39872 476176 Swap: 1515512 17568 1497944 – user59178 Nov 4 '10 at 13:51
Now htop says, that 39 mb of RAM is used – user59178 Nov 4 '10 at 13:51
Your memory situation is just fine. As free shows, you have over 400MB RAM available for use. Please read the link I posted in my answer for a clear explanation of what's going on. – EEAA Nov 4 '10 at 13:55

Either remove all unnecessary apache modules, or consider using a smaller httpd like nginx or lighttpd. For MySQL, check your my.cnf to see what buffers/caches you might be able to lower.

share|improve this answer

what you are looking for is some tune-up configuration, here are some tips:

Apache tune-up tips:

  1. Upgrade Apache! The newest version contains several performance enhancements.

  2. In httpd.conf, set “HostNameLookups off” which avoids doing a reverse DNS lookup on every visitor who hits your web site.

  3. In httpd.conf, set “MaxClients 230″ or higher for busier web sites. This allows more httpd daemons to run simultaneously and avoids clogging up the process queue.
  4. Serve web graphics (such as GIF files) from another machine.

  5. Make sure your web pages and CGI pages are browser cache friendly. See the “Caching Tutorial for Web Authors and Webmasters” at http://

  6. Keep your Apache lean and mean. Compile Apache with as few modules as needed. Before compiling (before your run make), edit the /apache_1.x.x/src/Configuration file put a # in front of any AddModule lines you don’t need.
  7. If you don’t need traffic logs (such as a site that only serves graphics) then use the TransferLog directive in httpd.conf to redirect log entries to /dev/null/
  8. Unless you insist on using .htaccess files to control access to certain directories (there are other ways to do that), in access.conf (or httpd.conf in newer versions of Apache) in the section, set “AllowOverride None” so that Apache will not bother looking for an .htaccess file in each directory with each request.
  9. DO NOT leave unnecessary background processes running. Removing extraneous background tasks not only improves performance but security as well. In the /etc/rc.d/rc3.d/ directory [on other systems, this may be different, for example, with Debian, it is /etc/rc2.d/. -D.], delete symlinks to processes you don’t need to run. For a plain vanilla local disk web server in Linux, you should only need routed, network, inet, httpd, and local symlinks in your /etc/rc.d/rc3.d/ directory. Reboot the machine if you change the contents of that directory.
  10. DO NOT serve web pages or write web traffic logs on a networked disk drive (ie. NFS networked disks) — read and write to local disk drives only. NFS I/O operations incure huge overhead.
  11. DO NOT run Apache (httpd) via the tcpd wrapper in /etc/inetd.conf. Apache can be started when the machine boots by either adding the startup command to your rc.local file or by placing the httpd startup script to your /etc/rc.d/rc3.d/ directory. If you want some mechanism to block requests by IP address then use the “deny from” directive in the Apache’s conf files or in a .htacess file.
  12. DO NOT leave X Windows running on your web server if you’re not using it — just be sure to Ctrl-Alt-Backspace to close the X session when you’re done using it.
  13. Avoid using SSI tags.
  14. In CGI scripts:
    • File I/O: Open as few files as possible. Be sure to explicetly close each opened file. Stop reading the file as soon as you found the data you need. Consider structuring data files into fixed-length fields and using read() function to skip ahead to just the part of the file you need to read.
    • Shell Commands: Call shell commands via their full path: eg. use ‘/bin/date’ instead of just date in a perl script.
    • If your site is mostly CGI driven, by all means use mod_perl. See http://
    • Perl programmers should study “Effective Perl Programming” by Joseph N. Hall (an Addison Wesley book) and “The Perl Cookbook” by Tom Christiansen (an O’Reilly book) — two good texts for optimizing perl code. For example, you can preallocate the memory for a hash that will contain 256 items like so: keys(%names) = 256;
    • Avoid having more than 1000 files in your web page directory. Organize your web page files into subdirectories. The more files there are in a directory, the longer it takes to locate that file during a request.
  15. Put as few graphics in your web pages as possible. Make sure each image is run through an image compressor.
  16. Stress test your web site. Run Apache Benchmark program (called “ab”) in Apache’s /bin or /sbin directory. The ab program will simulate heavy traffic by running multiple simultaneous requests on any web page you want for as long as you want then measures the load and response times. Very useful for measuring the effects of your tuning efforts.
  17. For best performance, unplug the network cable from your web server — the load will drop down to zero almost instantly!
share|improve this answer
This is boilerplate crap full of outdated recommendations and bad advice and only a tiny fraction of it even addresses the posted question. – jgoldschrafe Nov 4 '10 at 12:43
Nice copy/paste from here: – EEAA Nov 4 '10 at 12:52
I never said i wrote that, but you are wrigth, i forgto to mention the link., – Hugo Garcia Nov 4 '10 at 13:56
regarding what jgoldschafe says, dont take me wrong, but there are several useful tips there. if you feel superior to other people, that is another issue. – Hugo Garcia Nov 4 '10 at 13:58

Your Answer


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.