Discussion:
swap file vs swap partition
Aloha Guy
2007-02-04 20:06:56 UTC
Permalink
Greetings everyone:

I am planning to build a few new boxes which will run -RELEASE and -CURRENT and I have a question about the swap file. In the past, I had always used a swap partition of 256MB since I originally had 128MB system memory in the 1990's but my system has been upgraded to 2GB and it seems the swap file would have more flexibility as I can just change the size of the swapfile if I needed to. My question is is there any difference in performance between a swap file versus a swap partition and can one run a system with a swap file instead of a swap partition? Also, searching has not gotten me very far but are there any drawbacks to a swap file instead of a swap partition? I read somewhere that a few people seem to think that a swap file can't handle kernel crash dumps? Shouldn't it be the same as both of them occupy disk space and as long as the swap file is large enough, wouldn't it work? Thanks.

John



____________________________________________________________________________________
Yahoo! Music Unlimited
Access over 1 million songs.
http://music.yahoo.com/unlimited
Scott Long
2007-02-04 20:16:37 UTC
Permalink
Post by Aloha Guy
I am planning to build a few new boxes which will run -RELEASE and -CURRENT and I have a question about the swap file. In the past, I had always used a swap partition of 256MB since I originally had 128MB system memory in the 1990's but my system has been upgraded to 2GB and it seems the swap file would have more flexibility as I can just change the size of the swapfile if I needed to. My question is is there any difference in performance between a swap file versus a swap partition and can one run a system with a swap file instead of a swap partition?
Yes. A swap file requires a pass through the filesystem code in order
to figure out where each block is.
Post by Aloha Guy
Also, searching has not gotten me very far but are there any drawbacks to a swap file instead of a swap partition? I read somewhere that a few people seem to think that a swap file can't handle kernel crash dumps?
That's correct, it cannot.
Post by Aloha Guy
Shouldn't it be the same as both of them occupy disk space and as long as the swap file is large enough, wouldn't it work?
The crashdump code is written to assume that the dump space is
completely contiguous, something that is not at all guaranteed by
a swap file. While it would certainly be possible to modify it
to make a pass through the filesystem like above, the intention
of the crashdump code is also to be as simple as possible and to
depend on as few kernel services as possible. When the system has
crashed, who knows what can be trusted anymore, right? Also, filesystem
corruption is a frequent cause of crashes; why risk that dumping to
a swapfile might encounter corruption and trash your entire filesystem.

Scott
Aloha Guy
2007-02-04 21:53:14 UTC
Permalink
Thanks for the input. You do have good points. The only issue with swap partitions is that it seems like you need to increase it everytime you increase the physical memory. Is there a swap partition size limit that pretty much will handle anything and setting a number larger than that will really not offer anything?

John

----- Original Message ----
From: Scott Long <***@samsco.org>
To: Aloha Guy <***@yahoo.com>
Cc: ***@freebsd.org; ***@freebsd.org
Sent: Sunday, February 4, 2007 12:16:37 PM
Subject: Re: swap file vs swap partition
Post by Aloha Guy
I am planning to build a few new boxes which will run -RELEASE and -CURRENT and I have a question about the swap file. In the past, I had always used a swap partition of 256MB since I originally had 128MB system memory in the 1990's but my system has been upgraded to 2GB and it seems the swap file would have more flexibility as I can just change the size of the swapfile if I needed to. My question is is there any difference in performance between a swap file versus a swap partition and can one run a system with a swap file instead of a swap partition?
Yes. A swap file requires a pass through the filesystem code in order
to figure out where each block is.
Post by Aloha Guy
Also, searching has not gotten me very far but are there any drawbacks to a swap file instead of a swap partition? I read somewhere that a few people seem to think that a swap file can't handle kernel crash dumps?
That's correct, it cannot.
Post by Aloha Guy
Shouldn't it be the same as both of them occupy disk space and as long as the swap file is large enough, wouldn't it work?
The crashdump code is written to assume that the dump space is
completely contiguous, something that is not at all guaranteed by
a swap file. While it would certainly be possible to modify it
to make a pass through the filesystem like above, the intention
of the crashdump code is also to be as simple as possible and to
depend on as few kernel services as possible. When the system has
crashed, who knows what can be trusted anymore, right? Also, filesystem
corruption is a frequent cause of crashes; why risk that dumping to
a swapfile might encounter corruption and trash your entire filesystem.

Scott



____________________________________________________________________________________
Get your own web address.
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
Scott Long
2007-02-04 22:28:47 UTC
Permalink
Post by Aloha Guy
Thanks for the input. You do have good points. The only issue with
swap partitions is that it seems like you need to increase it everytime
you increase the physical memory. Is there a swap partition size limit
that pretty much will handle anything and setting a number larger than
that will really not offer anything?
John
Processors and memory have vastly outpaced the speed of disks; any
amount of swapping is going to be percieved as being very slow and
something that should be avoided. Since RAM is also very cheap now,
most people just load enough RAM into their system to handle their load,
and then configure enough swap to hold a crashdump of that RAM. You
always want swap so that you can handle unexpected spikes in load
without crashing, but it's less of an integral piece of normal system
operation these days.

Scott
Daniel O'Connor
2007-02-05 00:23:33 UTC
Permalink
Post by Scott Long
Processors and memory have vastly outpaced the speed of disks; any
amount of swapping is going to be percieved as being very slow and
something that should be avoided. Since RAM is also very cheap now,
most people just load enough RAM into their system to handle their load,
and then configure enough swap to hold a crashdump of that RAM. You
always want swap so that you can handle unexpected spikes in load
without crashing, but it's less of an integral piece of normal system
operation these days.
Mini-dumps have made it a lot easier to get away with a small amount of swap.
That said it's not like disk is expensive either!
--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
Richard Lynch
2007-02-05 06:22:44 UTC
Permalink
Post by Aloha Guy
Thanks for the input. You do have good points. The only issue with
swap partitions is that it seems like you need to increase it
everytime you increase the physical memory. Is there a swap partition
size limit that pretty much will handle anything and setting a number
larger than that will really not offer anything?
What you *might* consider doing:

A swap partition the size of *ONE* RAM chip.

A swap file the size of all your RAM chips.

If you are having kernel panics, you can pull out RAM and then get
your kernel dump, I would presume.

This is a made-up answer from a guy who has no idea what he's talking
about, really...
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
Aloha Guy
2007-02-04 23:24:39 UTC
Permalink
What I actually meant was, I know in the old days, if you had 128MB, you want a 256MB swap but with 2GB RAM, isn't 4GB going to be overkill for a swap or are you saying that a 2GB swap will work? I'm still lost on the ratio since I thought the 2x was only if you had like small amounts of RAM.

John


----- Original Message ----
From: Scott Long <***@samsco.org>
To: Aloha Guy <***@yahoo.com>
Cc: ***@freebsd.org; ***@freebsd.org
Sent: Sunday, February 4, 2007 2:28:47 PM
Subject: Re: swap file vs swap partition
Post by Aloha Guy
Thanks for the input. You do have good points. The only issue with
swap partitions is that it seems like you need to increase it everytime
you increase the physical memory. Is there a swap partition size limit
that pretty much will handle anything and setting a number larger than
that will really not offer anything?
John
Processors and memory have vastly outpaced the speed of disks; any
amount of swapping is going to be percieved as being very slow and
something that should be avoided. Since RAM is also very cheap now,
most people just load enough RAM into their system to handle their load,
and then configure enough swap to hold a crashdump of that RAM. You
always want swap so that you can handle unexpected spikes in load
without crashing, but it's less of an integral piece of normal system
operation these days.

Scott



____________________________________________________________________________________
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/
Peter Jeremy
2007-02-05 07:07:55 UTC
Permalink
Please wrap your lines and don't top-post.

On Sun, 2007-Feb-04 15:24:39 -0800, Aloha Guy wrote: What I actually
Post by Aloha Guy
meant was, I know in the old days, if you had 128MB, you want a 256MB
swap but with 2GB RAM, isn't 4GB going to be overkill for a swap or
are you saying that a 2GB swap will work? I'm still lost on the
ratio since I thought the 2x was only if you had like small amounts
of RAM.
2:1 was a very old rule of thumb. A better approach is to consider
your workload: Your working set needs to fit in RAM and the total
virtual size needs to fit into RAM+swap. If you tend to leave lots
of large processes lying around not doing anything, you might be
able to usefully use much more swap than if you religiously kill
processes that you aren't using - particularly if you don't have
massive amounts of RAM. My desktop at work typically runs with
swap utilisation about twice RAM (but it only has ~160MB RAM).

Keep in mind that you can use multiple swap partitions so it can
be useful to have an active swap on each disk. (The VM system
stripes across available swaps).
--
Peter Jeremy
Jerry McAllister
2007-02-05 15:56:25 UTC
Permalink
Post by Aloha Guy
What I actually meant was, I know in the old days, if you had 128MB, you
want a 256MB swap but with 2GB RAM, isn't 4GB going to be overkill for a
swap or are you saying that a 2GB swap will work? I'm still lost on the
ratio since I thought the 2x was only if you had like small amounts of RAM.
It really depends on what you are doing with the system.
The system also pages to swap space. Now, you really want enough
ram so that you are not depending on paging while something is
running, but if you have lots of processes with many kind of resting
until something comes up, the system may gradually use up their
in-core space for other stuff, even though the process is not
actually swapped out. Then, if some of those processes have to
run again, they don't half to be built up again. The system just
pulls back in the pages it needs - not necessarily the whole thing.
It is, then good to have enough space for that. It would take
some observation on how your system is used to decide just how
important your swap size is. If you are running a big enough
system that 4 GB of ram is needed, then 4 GB or even 8 GB swap
is not so comparatively large. You would probably be running
disk sizes in 70-160 GB size and maybe more than one, so what's 4 GB!

Anyway, you want to have enough swap to cover a crash-dump - not
that it is a frequent occurance unless you are doing development.
After all, this is FreeBSD, not MS. But, still, it is good to have.

////jerry

ps. Please learn to break your text lines at about 70 characters.
It makes responding much easier.
/jrm
Post by Aloha Guy
John
----- Original Message ----
Sent: Sunday, February 4, 2007 2:28:47 PM
Subject: Re: swap file vs swap partition
Post by Aloha Guy
Thanks for the input. You do have good points. The only issue with
swap partitions is that it seems like you need to increase it everytime
you increase the physical memory. Is there a swap partition size limit
that pretty much will handle anything and setting a number larger than
that will really not offer anything?
John
Processors and memory have vastly outpaced the speed of disks; any
amount of swapping is going to be percieved as being very slow and
something that should be avoided. Since RAM is also very cheap now,
most people just load enough RAM into their system to handle their load,
and then configure enough swap to hold a crashdump of that RAM. You
always want swap so that you can handle unexpected spikes in load
without crashing, but it's less of an integral piece of normal system
operation these days.
Scott
____________________________________________________________________________________
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/
_______________________________________________
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
Continue reading on narkive:
Loading...