Help - Search - Members - Calendar
Full Version: Turning off Swap?
The Planet Forums > System Administration > Web Hosting
JJ
I've got a LAMP server with 2GB of RAM. Lately the server has been using swap, which I clear and reset with the following commands:

swapoff /dev/hda2
swapon /dev/hda2

This works for a while (hours to days) and then the server starts utlizing swap again, slowing it down.

Today I tried just leaving swap off, by running:
swapoff /dev/hda2

Is there any benefit to doing this? Any harm?

Thanks
Blue|Fusion
Short answer: yes.

You want swap because if there comes a point where you actually need all that RAM, and there's no more addressable memory, the server will crash with a kernel panic. In all actuality, swap being used is not a sign of slow performance or anything bad. If information is in swap, than that's because it hasn't been used in a while, if even needed anymore, and to make room for more important things on RAM, it puts it in swap, instead of doing the Windows thing and removing it from RAM/pagefile no questions asked.

If you really want to prevent the use of swap, find out what's using most of the memory and correct the problem.
jamesn
QUOTE (JJ)
Any harm?


Your system is swapping because it's running out of ram. If you run out of ram with swap turned off, bad things will happen. Things like processes dieing, or the system crashing.

There's a difference between, "there is some data in swap" and "actively swapping." If a process is idle and has not been used for quite some time, most operating systems will page them out to free up memory for other uses like disk block caching and other, active, processes. Use top(1) or something to monitor how much used swap changes. If you can see the size of swap change, then you're actively swapping. If you can't see the size of swap change, or it doesn't change very often then there's probably no real problem.

If you are actively swapping (it seems that you are, as you've stated that the system gets slow), there is a reason for it. Since you've disclosed that this is a "LAMP" system, check for very large php or apache processes. I've found that php will grow to be very large and not release it's memory back to the operating system under certain conditions. If you have very large apache processes, try setting the httpd.conf 'MaxRequestsPerChild' setting to something sane (like 100 requests or so). This will force apache to kill it's child processes before they grow to be to large.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.