Re: Efficient Create Swap File?

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

 



Mike McCarty wrote, On 03/27/2009 04:01 PM:
I've seen various recommendations for adding swap files after
system creation, and it occurs to me that the "standard" technique
may not be the most efficient. I realize that one rarely creates
swap files, but nonetheless on occasion one needs to "precreate"
some file or other, then do something to it, like mkfs etc.

Anyway, mostly trying to improve my general knowledge of
how best to use the abilities of the system, and my understanding
of the relative merits of doing things one way vs. another,
not trying to speed up rarely performed procedures.

The standard technique is to do something like

$ dd if=/dev/zero of=/path/to/new/file bs=1024 count=524288
$ mkswap /path/to/new/file

to create a 512MB file. The second command may be different,
depending upon the circumstances, but the technique remains
the same. In effect, the new file gets written twice.

It occurs to me that one could, instead, do

$ dd if=/dev/zero of=/path/to/new/file bs=1M seek=511 count=1
$ mkswap /path/to/new/file

and have the same results, requiring only writing the file
once.

<SNIP>

My guess is that when the swap file with a "hole" first gets used, there
will be a long(ish?) pause while some part or parts of the sparse file
get filled in. This is not so good for a swap file, but when one
is actually going to rewrite most of the file anyway, and is only
using the file itself as more or less an indicator of the size, then
it might make sense.

Comments?

Mike

This brings up a question for me...
If using the first method, while in use or during the mkswap command, does the bits written to the file end up at the same physical locations as the 0s they are replacing? if they do, then the first method on a disk that is not fragmented, would give you a contiguous swap space.
if they don't, then like you say, what is the point of writing all the 0s to disk?

So then do we have to think about our file systems?
msdos/vfat would write to the same locations I think.
ext2 would write to the same locations I think.
ext3 without journaling, would write to the same locations I think.???
ext3 with journaling, pathology???
ext4 with/without journaling, I have not used or read about.???
riser???
others???



--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux