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

Re: Efficient Create Swap File?

Mike McCarty wrote:
> $ diff -s file1 file2
> Files file1 and file2 are identical

Identical? Try this:
  du file1 file2

and you will see that one of them has not allocated disk blocks,
it is sparse (has holes).
IIRC sparse files are unacceptable for swap (the recent "swap files
are as fast as swap partition" feature actually means that the kernel
identifies where the file is on the disk and uses those blocks as a
sort of "fragmented partition").
And even if it works, it's a bad idea: the swap file will allocate
blocks in a very fragmented way in the future
(and there would be a "out-of-space" risk at the filesystem level
during a swapout..., brrrr).

You are right in one thing: writing the zeroes should not be
needed; it happens to be that writing something is the
only way to allocate disk blocks in most filesystems
(persistent preallocation in ext4 will change this).

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

In theory, but you would risk: fragmentation and possible disk-full.

Best regards.
   Roberto Ragusa    mail at robertoragusa.it

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