Punching holes in files
In particular, this patch adds a new flag (FALLOC_FL_PUNCH_HOLE)
which is recognized by the system call. If the underlying filesystem is
able to perform the operation, the indicated range of data will be removed
from the file; otherwise ENOTSUPP will be returned. The current
implementation will not change the size of the file; if the final blocks of
the file are "punched" out, the file will retain the same length. There
has been some discussion of whether changing the size of the file should be
supported, but the consensus seems to be
that, for now, changing the file size would create more problems than it
would solve.
Index entries for this article | |
---|---|
Kernel | fallocate() |
Posted Nov 18, 2010 8:00 UTC (Thu)
by stefanha (subscriber, #55072)
[Link] (2 responses)
Posted Nov 18, 2010 13:33 UTC (Thu)
by Tomasu (guest, #39889)
[Link] (1 responses)
I could actually see the file system or vfs sending down a TRIM command after a hole is punched in a file.
Posted Nov 18, 2010 13:53 UTC (Thu)
by stefanha (subscriber, #55072)
[Link]
FITRIM will only discard freed blocks in a filesystem. It does not punch new holes in a particular file.
Posted Nov 18, 2010 15:09 UTC (Thu)
by Trelane (subscriber, #56877)
[Link] (5 responses)
Posted Nov 18, 2010 15:51 UTC (Thu)
by josefwhiter (guest, #39238)
[Link] (4 responses)
Posted Nov 18, 2010 16:08 UTC (Thu)
by Trelane (subscriber, #56877)
[Link]
Posted Nov 18, 2010 16:54 UTC (Thu)
by chmouel (subscriber, #6335)
[Link] (2 responses)
Posted Nov 18, 2010 18:40 UTC (Thu)
by nix (subscriber, #2304)
[Link]
Currently, the backing file still takes up space on the host's filesystem when that is done. It need not. (Possible downside: files with huge numbers of holes scattered through them had a historical propensity to get enormously fragmented, but for VM filesystem images this is probably completely unimportant, as the 'fragmentation' is going to be precisely in line with actual *files* in the contained FS.)
Posted Nov 19, 2010 16:55 UTC (Fri)
by ewan (guest, #5533)
[Link]
Posted Nov 19, 2010 1:51 UTC (Fri)
by brouhaha (subscriber, #1698)
[Link]
Back when my colleagues and I developed the original ReplayTV (which was not Linux-based, alas), we used the same concept to implement the variable-sized live-TV rewind buffer. Some of the engineers wanted to use a fixed-size file as a circular buffer, but I pointed out that if we used hole-punching (and 64-bit file offsets), the live-TV buffer could potentially use all otherwise unused disk space, and that as we needed to reclaim space for new video, we could just punch a hole at the beginning of the file. Effectively, the conceptual beginning of the file moves forward as the oldest video in the buffer is discarded.
This worked out really well, though I'm not sure whether they continued to use this approach when they switched to VxWorks for the 4000-series and later units.
Posted Nov 28, 2010 19:06 UTC (Sun)
by kolk (guest, #36699)
[Link] (7 responses)
Standard long ago has specified that holes in sparse files are read as zeros.
There is no need for any special interfaces on any level.
Posted Nov 29, 2010 1:04 UTC (Mon)
by nybble41 (subscriber, #55106)
[Link] (3 responses)
So a separate interface is required after all.
Posted Nov 29, 2010 12:17 UTC (Mon)
by mfedyk (guest, #55303)
[Link] (2 responses)
Posted Dec 29, 2010 15:33 UTC (Wed)
by yoe (guest, #25743)
[Link] (1 responses)
Posted Jan 20, 2011 2:22 UTC (Thu)
by jzbiciak (guest, #5246)
[Link]
Posted Jan 20, 2011 3:23 UTC (Thu)
by brouhaha (subscriber, #1698)
[Link] (2 responses)
Posted Jan 27, 2011 18:16 UTC (Thu)
by mcortese (guest, #52099)
[Link] (1 responses)
Posted Jan 27, 2011 21:34 UTC (Thu)
by brouhaha (subscriber, #1698)
[Link]
In any case, supposing that I did want to punch a big hole, then fill it, I wouldn't want to have to write the whole region twice.
Punching holes in files
Punching holes in files
Punching holes in files
http://lwn.net/Articles/397538/
Punching holes in files
Punching holes in files
Punching holes in files
Punching holes in files
Punching holes in files
Punching holes in files
Useful feature
Traditional interface is zero-filling
Similarly, block should be freed or punched out automatically when it's overwritten with zeros, may be conditionally if it's not optimal thing to do.
And any such interface should just zero-fill underlaying storage if not supported as is, and never return its own error code.
Traditional interface is zero-filling
Traditional interface is zero-filling
Traditional interface is zero-filling
Traditional interface is zero-filling
If I want to punch a 5GB hole in the middle of a file, I don't want to have to do 5GB of writes to make it happen.
And yes, I actually have a use for punching really big holes.
Traditional interface is zero-filling
Traditional interface is zero-filling
If I want to punch a 5GB hole in the middle of a file, I don't want to have to do 5GB of writes to make it happen.
Wouldn't you need to do it anyway when you allocate that space again?
Traditional interface is zero-filling