Jeff McAdams on 19 Dec 2007 12:19:25 -0800


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

Re: [PLUG] Pros and cons of swap in a partition vs. in a file in the file system


Walt Mankowski wrote:
> On Wed, Dec 19, 2007 at 02:53:04PM -0500, Jeff McAdams wrote:
>> We've done this where I work, on occasion.  We have some commercial apps
>> (aren't they always the problem children?) that insist on having x
>> amount of swap space available on the system, regardless of whether
>> there's ever any real chance of even touching it.  So we use dd to
>> create a big file of the size needed, mkswap it, and swapon it at a
>> priority level that it'll never get used.  Badly behaved commercial apps
>> are happy, and the only thing we're out is some disk space that'll never
>> get touched.  Shoot...if you can swing a way to create the file as a
>> sparse file, there's a pretty good chance that most of that disk space
>> will never actually get allocated anyway!
> 
> Using a sparse file as a swap file sounds like a really dangerous
> idea, and I'm not even sure it's supported.  The manpage for mkswap(8)
> says:
> 
>   Note that a swap file must not contain any holes

> which would seem to rule out sparse files.

Huh...perhaps that's why I've never actually tried that, then.

Ah well...disk is cheap.  ;)

> I always thought the main advantage of swap partitions over swap files
> was speed.  All the bytes in a partition are continuous, so access
> time is slightly higher than for a file created with dd, which can be
> scattered over the disk.

There is that, there is also that it doesn't have to go through so much
of the other sorts of processing in the kernel.  VFS, perhaps LVM,
filesystem code, et al.  The hit here is pretty minor, but there is a bit.
-- 
Jeff McAdams
"They that can give up essential liberty to obtain a
little temporary safety deserve neither liberty nor safety."
                                       -- Benjamin Franklin

Attachment: signature.asc
Description: OpenPGP digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug