Saving memory

From PrgmrWiki

The main area of contention on my Xen instances has been RAM. Here's a selection of random tips on how to keep memory usage down.

Stop unwanted services

Test out changes with "service <service name> stop", and once happy disable them permanently with "chkconfig <service name> off" or "update-rc.d <service name> disable".

  • On CentOS, if SELinux is disabled ("selinux=disabled" on the kernel boot line) you may be able to disable the audit daemons. You may want to consider disabling the setroubleshootd daemon if not required (regardless of whether SELinux is on or off).
  • You may want to switch off and/or switch to a lighter replacement for sendmail/exim. You need to be aware that doing so may affect things that send email on your server, causing them to stop working or the emails may get stuck in the queue.


  • Look for the "my-small.cnf" in the MySQL documentation (often packaged to places like /usr/share/doc/mysql*). It will help turn down buffer sizes.
  • Could SQLite do what you need?


  • Consider switching to lighttpd or nginx instead of Apache.



Compiling large programs

If you're doing anything that requires a lot of memory (such as compiling GHC), you may want to create a swapfile as your system is running. You can add additional swap files as necessary. Keep in mind that if your system is constantly swapping out memory, any web servers running will be significantly slower to respond to requests.


  • Replace the system getty with mingetty saving a few hundred KB.
  • If you must run inetd services, use tiny-tcpd.
  • Substitute tmux for GNU Screen when keeping persistent sessions. Smaller yet, use dtach if all you really do is background a few terminal processes.