Efficient Create Swap File?

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

 



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.

$ time dd if=/dev/zero of=file1 bs=1024 count=524288
524288+0 records in
524288+0 records out

real    0m17.898s
user    0m0.528s
sys     0m4.895s

$ time /sbin/mkswap file1
Setting up swapspace version 1, size = 536866 kB

real    0m0.432s
user    0m0.000s
sys     0m0.024s

$ time dd if=/dev/zero of=file2 bs=1M seek=511 count=1
1+0 records in
1+0 records out

real    0m0.077s
user    0m0.000s
sys     0m0.007s

$ time /sbin/mkswap file2
Setting up swapspace version 1, size = 536866 kB

real    0m0.024s
user    0m0.000s
sys     0m0.004s

$ diff -s file1 file2
Files file1 and file2 are identical

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
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!

--
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