on Tue, Dec 16, 2003 at 10:23:50PM +0100, Magnus von Koeller (magnus@vonkoeller.de) wrote:
Content-Description: signed data
> On Tuesday 16 December 2003 22:12, Karsten M. Self wrote:
> > > SWAP - 1.5GB
> >
> > Rule of thumb: ?1-2x RAM.
>
> I never understood that rule... In what way does it make sense that I
> need more swap because I have more RAM? Seriously, I'd really like to
> understand this.
As several people have pointed out:
- Executables themselves aren't swapped. They're mapped to disk (that
is, the on-disk binary image is the same as what's in RAM, no need
for another image in swap). What's swapped is...
- Data segment. Any information that the program holds in memory.
Your Squid cache. Browser data. Wordprocessing documents.
Anything that's not the executable and/or libs themselves.
- Swapping is slow. Or more specifically: *paging* is slow. Reading
or writing to swap. However...
- The state of being swapped *doesn't* impact performance, _so long
as_ that state doesn't change. E.g.: you launch program foo, which
loads, but doesn't do much. Later you launch bar and baz. Foo
swaps out to make room for baz. There's a slight performance hit as
foo is written to disk. But there's _no_ ongoing hit _so long as
foo stays swapped_. You can monitor this with 'iostat'.
Swap as a memory management strategy works well if:
- You have one or more applications which use large amounts of
data-segement memory, in aggregate.
- These programs don't change active state often. That is: they go
into swap and stay there. Say, a word processor you hack on a bit
at a time, but leave idle for many minutes, or hours.
Swap works poorly if you have little memory on your system, many
programs, with data-intensive use, and they move in and out of swap
frequently. This is known as "thrashing", and is what most people
allude to when they say "swap is bad".
There are a few additional twists:
- Linux, unlike some OSs, *doesn't need* swap to function, though you
almost always are better off with than without at least some. That
is: you can run the system with no swap at all. Of course, this
means that when you're out of memory, you're out of memory. Swap is
a buffer, insurance. There's no need to balance swap and memory as
for some other OSs.
- (Possibly supersceded) Too much swap can be detrimental. Or at
least this was the case with older kernels. Because memory was
necessary to address memory, allocating too much swap actually cut
into available real memory.
- You can add swap in an emergency either by creating a swapfile, or
by activating a previously unused swap partition.
Think of swap as a place to put stuff you're not currently working on.
If your computer is an office, and your CPU is a desk, then memory is
the active desktop where current tasks sit, while the credenza across
the room is swap, and the filing cabinet is memory. You can file up the
credenza with current projects that you're not actively working on, if
your desk gets cluttered. It's not the amount of stuff on the credenza,
but the trips back and forth that slow you down. The advantage is you
don't have to file everything and start all over next time you want to
work on the project.
Peace.
--
Karsten M. Self <kmself@ix.netcom.com> http://kmself.home.netcom.com/
What Part of "Gestalt" don't you understand?
Reject EU Software Patents! http://swpat.ffii.org/
Attachment:
pgpTo9uEBm0ne.pgp
Description: PGP signature