| Tom Pohl on Tue, 5 Mar 2002 14:01:23 -0600 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| [Cialug] Re: Swapfiles (was Kernel panic) |
I've got a webserver that's been up for 144 days running mysql, apache, and
tomcat. It serves up ~1GB/day with ~40% of the hits being processed through
tomcat or talks to the database. It hasn't ever used the swap space for
anything.
total used free shared buffers cached
Mem: 257240 251172 6068 85760 61412 138956
-/+ buffers/cache: 50804 206436
Swap: 257032 0 257032
It hasn't touched the swap space to cache out anything yet. Maybe
everything is just a little too busy to be considered idle, I dunno.
-Tom
-----Original Message-----
From: lug-admins@cialug.org [mailto:lug-admins@cialug.org]On Behalf Of
Softwre Janitor
Sent: Tuesday, March 05, 2002 1:25 PM
To: lug@cialug.org
Subject: [Cialug] Re: Swapfiles (was Kernel panic)
--- "Nathan E. Pralle" <npralle@creativesolutionsunlimited.com> wrote:
> At 08:27 AM 3/5/2002 -0800, you wrote:
> >Running swap off a file does decrease performance, and is not
> >normally recommended unless you have a temporary need for
> >more virtual memory.
>
> This may be the case, but I've always balanced the benefits of being
> able to modify my swapfile very easily vs. a better but
> more-difficult-to-change swap partition, and the swapfile almost
> always wins out (unless I happen to have a spare 500MB drive for
> each of my 14 running machines, which I don't.) I'd rather just 'rm
> /swapfile' and recreate it than having to reinstall the whole system
> because I didn't have enough foresight to make my swap partition
> large enough.
I almost never need to modify a swap partition, but part of
that is because I always make them bigger than I think I'm
ever likely to need. If for some reason I have a temporary
need for additional swap space I can always create a swap
file temporarily as you outlined and use it in addition to
my permanent swap partition.
For that matter, there is no reason why I can't carve a chunk
off another partition or whatever to add a second swap
partition if I find the need for increased swap on a long
term basis.
> >Running a swap partition does not normally
> >have a negative impact on performance, unless you are low enough
> >on physical RAM that it is being used.
>
> Depends on how you view "negative impact on performance." Read on.
I'm just saying that I've never seen any measurable impact to
performance having swap enabled on a machine which isn't actually
swapping.
> >In fact, it can actually
> >improve overall performance because processes that are idle
> >long enough to eventually get swapped out free up more available
> >memory for things like disk caching.
>
> Of course, if you have low RAM. But that's not the point. The point
> is, if you have enough RAM for 99% of the time you are running
> things, you *shouldn't* be running swap, period. (I'm talking
> non-mission-critical servers, of course)
>
> >While there is no doubt
> >that hitting disk is slower than physical RAM, turning off
> >swap isn't the best answer, adding more RAM is.
>
> Indeed. Buy that RAM, folks! It's cheaper than waiting for your
> machine to grind.
>
> >I'd much rather let
> >my OS take care of things for me than worry about whether I am
> >getting close to using up physical RAM and having to scramble
> >around to activate a swap file before processes start dying...
>
> The problem with this is this: Linux is smart, very smart. It knows
> that if it has swap, it will (as you said above) swap out long-idle
> programs to disk to free up physical RAM for use in other programs.
> Now, if you're low on RAM anyway, this is a fine-and-dandy approach
> to things, very smart. However, Linux's intelligence runs out after
> awhile. If it has 512MB of RAM, 300MB of which is free, and a swap
> partition and senses some long-idle processes, it will *still* swap
> out those processes to disk, regardless of the fact that it still
> has 300MB of free RAM. *This* seems to me to be something to avoid.
It would be, if Linux didn't aggressively use "free" RAM for things
like disk caching. If a process is idle for so long that it gets
swapped out, I'd rather use that memory for something else. If
you have a lot of RAM, Linux won't start swapping idle processes
out until it has used up all "free" memory with disk cache or
whatever, so it really isn't something that happens often enough
for it to be something to avoid. Linux's intelligence is going to
do the right thing for you in overall performance most of the time,
so why not let it?
> If you rarely get anywhere needing all 512MB of RAM, why run swap?
The question should be why not? If you don't need it, it just
isn't going to make a difference. If you do need it, then it is
there, ready and waiting.
> You're just asking for performance decreases.
It just doesn't seem to happen that way in practice. The cost
for swapping out some obscure stuff occasionally is so low you
probably won't notice it, and is offset by the use of that memory
for things like disk caching that you will notice.
> I didn't buy a Gig of RAM to run a swapfile, ya know. :)
If you are purchasing a gig of RAM, why are you worrying about
allocating a couple gigs of space for a swap partition? Disk is
much cheaper than RAM these days. Any machine with a gig of RAM
probably has at least two 30+ gig hard drives in it.
> As for worrying about seeing processes run out of RAM, the first time
> you see it happen (Linux will let you know, have no fear) simply
> turn on some swap *then*.
>
> (NOTE: In a mission-critical server, I always keep _some_ swap on,
> as I don't want to deal with out-of-memory errors when I'm not there
> to handle turning swap on and saving the world. But on my home
> machines where I'll be present, I can adjust this on the fly. I
> don't think I'd ever say to turn swap off of a mission-critical
> server unless you have something like 4GB of RAM and you're just
> running RC5 on it or something. :P~)
I guess I don't view my workstation or home servers as anything
other than "mission critical". Machines that aren't mission
critical to me are likely to not have a huge amount of RAM in
them and so running swap on them is a must. Also, my home
workstation and servers run all the time, even when I'm not
there (and I access them remotely too). If my home machines
weren't mission critical at all I wouldn't bother with putting
them all on UPSs either.
The bottom line is that you can do whatever you want, and
certainly if you have a lot of RAM, then you can probably
get by without running swap, but I don't think it is really
great general advice to people to send the message that "swap
is bad", and to use swap files instead of swap partitions.
Most people, most of the time would probably be best served
by creating a normal rule of thumb 2x physical RAM swap
partition when they do their installation.
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/
--------------------------------------------------
To un-subscribe to this list use the link below:
mailto:listar@cialug.org?subject=unsubscribe%20lug
--------------------------------------------------
To un-subscribe to this list use the link below:
mailto:listar@cialug.org?subject=unsubscribe%20lug