Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] A Swap Question



On Monday 05 November 2007 10:47, burlingk@example.com wrote:
>I have seen some places that suggest using a swap partition equal
> to the size of your physical memory, and other places that
>say to use a swap partition equal to about twice the size of physical
>memory.
>
>Is there any reason that it would be bad, or less efficient to use a
>larger partition for swap?

How much swap is appropriate really depends on how much RAM a machine 
has and what it is used for. I think the recommendation for swap to be 
2x RAM is somewhat outdated for most applications on new hardware.

For new installs on new hardware (with 1GB or more RAM), i usually 
allocate 1/2 GB swap. My rationale is that on a server if the swap is 
being hit even that much than the battle is already lost; the machine 
will be so busy swapping (rather than serving) that it is effectively 
offline. Same for desktop machines; if massive amounts of swap are 
being used then the machine will be so slow that it will be difficult 
to even start killing off some processes to free up resources. If 
something has run away to the point that the machine is chewing through 
RAM and swap, i'd rather hit the hard limit of no more RAM+swap sooner 
rather than later.

So why not just get rid of swap entirely? The answer i have seen 
repeated most often is to allow the system to free up RAM by swapping 
out unused daemons. The RAM that is freed can then be used for more 
cache, which will often result in faster performance. My machine right 
now has 1 GB RAM of which roughly 40% is in use by actual programs, 100 
MB is free, and the other half is cache. And i'm using 50 MB of swap, 
even though some RAM is free. I haven't looked into Linux' swapping 
algorithms in great detail recently, but my guess is that Linux does 
preemptive swapping; it can write pages of memory to the swap file that 
haven't been used recently but doesn't actually dump them from memory. 
However, since they are already in the swap file, if the system 
suddenly needs more RAM it can use those pages without spending time to 
write them first. The result is better performance in situations where 
an application requests a lot of memory on short notice.

For machines with 512 MB RAM or less, i usually allocate swap equal to 
RAM for a desktop machine. For a server, it depends. I have a DHCP and 
DNS server at home with little memory and no swap at all. But if all it 
is doing is DHCP and DNS (and the occasional SSH session for 
maintenance) it doesn't really need to swap.

I guess that really doesn't answer your direct question though. Using a 
large swap partition shouldn't hurt anything (other than wasting disk 
space, but disk is cheap). It would not surprise me if some (old) 
versions of the kernel do not take advantage of all of the swap if you 
allocate more than a 2^x boundary, where x is some number. I think at 
one time there was a 128 MB limit per swap file (but that time was a 
rather long time ago). On new kernels the limit is probably so high 
that it would require a very specialized situation to justify hitting 
that limit.

------------------------------------------------------------------------
Dan Ramaley                            Dial Center 118, Drake University
Network Programmer/Analyst             2407 Carpenter Ave
+1 515 271-4540                        Des Moines IA 50311 USA


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links