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

From: Helge Hafting
Date: Fri Dec 05 2003 - 06:14:18 EST


Rob Landley wrote:
On Thursday 04 December 2003 15:10, Szakacsits Szabolcs wrote:

On Thu, 4 Dec 2003, Rob Landley wrote:

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.


Okay, I'll bite. How would one go about adding hole support to cat? :)

Easy. Look at the data you're writing. Don't ever write zeroes, seek
ahead in the file being written instead. The filesystem will create a hole
if possible. You may want to optimize this a bit by not seeking past
very small runs of zeroes.

Of course cat is sometimes used to write to things that aren't regular
files, so make sure seek is supported and fall back to ordinary writing
when it isn't.

Helge Hafting

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/