Re: Is there a "make hole" (truncate in middle) syscall?

Måns Rullgård
2003-12-05T12:11:12Z

Szakacsits Szabolcs <szaka@sienet.hu> writes:

>> What are the downsides of holes? [...] is there a performance penalty to
>> having a file with 1000 4k holes in it, etc...)
>
> Depends what you do, what fs you use. Using XFS XFS_IOC_GETBMAPX you might
> get a huge improvement, see e.g. some numbers,
>
> http://marc.theaimsgroup.com/?l=reiserfs&m=105827549109079&w=2
>
> The problem is, 0 general purpose (like cp, tar, cat, etc) util supports
> it, you have to code your app accordingly.

I found this paragraph in the man page of GNU cp:

--sparse=WHEN
A `sparse file' contains `holes' - sequences of
zero bytes that do not occupy any physical disk
blocks; the `read' system call reads these as
zeroes. This can both save considerable disk space
and increase speed, since many binary files contain
lots of consecutive zero bytes. By default, cp
detects holes in input source files via a crude
heuristic and makes the corresponding output file
sparse as well.

The WHEN value can be one of the following:

auto The default behavior: the output file is
sparse if the input file is sparse.

always Always make the output file sparse. This is
useful when the input file resides on a
filesystem that does not support sparse
files, but the output file is on a filesys-
tem that does.

never Never make the output file sparse. If you
find an application for this option, let us
know.

--
Måns Rullgård
mru@kth.se