
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [tlug] A Swap Question
On Tue, 6 Nov 2007, burlingk@example.com wrote:
On Mon, 5 Nov 2007, Daniel A. Ramaley wrote:
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
<snip>
That may not always be true. The comments equating swap usage to bad
performance assume all the swap is being eaten up by one overzealous
process. In that case, you're likely going to feel the pain.
But it really
does depend on exactly what you plan to do with the machine.
So, it is more a matter of how the programs utilize swap,
than a matter of how much swap there is?
Is that accurate?
No... programs don't have any control over swap -- they just eat up memory.
The O/S then uses swap to give the programs the impression that they each 
have a near-infinite memory space (at least to the extent of the physical 
RAM). In other words, if you have 2GB each program can pretend that the 
2GB is completely allocated to that program exclusively and the problems 
of sharing the physical memory among multiple programs running at the same 
time is handled by the O/S.
If you have multiple memory-hog programs but only one is really running at 
any one time (that is, the others are idle waiting on, maybe, a mouse 
click), the O/S will send the memory data used by the idle programs to 
swap, thus freeing up real RAM for the programs that are really doing 
something. When the idle programs start up again, there may be a momentary 
pause but for the most part, they will be re-loaded into RAM and continue 
as if nothing happened.
Performance only suffers if: (a) one running program tries to use more 
memory than you have physical RAM, or (b) multiple programs whose process 
space adds up to more than your physical RAM are all trying to run at the 
same time. In other words, so long as the total memory of the running 
programs is less than your physical RAM and the total memory of the idle 
AND the running programs is less than the swap, you're cool. It really 
depends on how often you intend to leave idle (non-running) programs with 
huge memory footprints loaded. My guess is that a server would seldom do 
that -- thus the low estimates when it comes to swap space. But a desktop 
machine could have a very different usage pattern.
For example, I have 2GB of RAM in my desktop machine. Right now, the top 
three memory hogs are these three processes:
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
16513 larabell  15   0 1143m 228m  33m S  0.0 11.4   1:10.56 java
18542 larabell  15   0  582m 332m  13m S  0.0 16.6   3:11.73 gimp
 9388 larabell  15   0  577m 241m  22m S  0.0 12.0  28:35.68 firefox-bin
Between the three, they think they have about 2.3GB allocated (VIRT). My 
machine could not run these three processes together without crashing if 
it were not for my swap space. Because these processes are mostly swapped 
out, only about 800Mb is of RAM is really being used (RES). Since all 
three of these processes are idle at the moment, there is no real problem 
with performance. If all three suddenly started accessing the swapped out 
memory, the machine would almost certainly slow to a crawl.
A larger swap allows idle processes to eat up more memory before you start 
to feel the pinch. It is very true that multiple active processes eating 
that same amount of memory can easily bring your machine to its knees. For 
that reason, a server is not likely to benefit from a large swap, since it 
seldom runs huge processes and the ones it does run are not likely to be 
idle for very long. A desktop is an entirely different matter and your use 
pattern is probably an important factor.
BTW, I've always used at least RAM-times-two for my desktop -- sometimes 
more. This machine has about 20GB. I could run 1.1GB java/gimp images till 
I turn blue without running out of memory ;-)...
---
Joseph L (Joe) Larabell            Never fight with a dragon
http://larabell.org                     for thou art crunchy
                                  and goest well with cheese.
Home |
Main Index |
Thread Index