How to create holes in files ?

Ben RUBSON ben.rubson at gmail.com
Thu Sep 28 16:11:06 UTC 2017


Hi Fabian,

And thank you very much for your answer !

> On 28 Sep 2017, at 17:26, Fabian Keil <freebsd-listen at fabiankeil.de> wrote:
> 
> Ben RUBSON <ben.rubson at gmail.com> wrote:
> 
>> I'm trying to make holes in files in C.
>> Goal is to deallocate huge files on ZFS while (randomly) reading them.
> 
> My interpretation of the above is that you want to create holes
> without changing the file size and without affecting data that
> is located before or after the holes that you want to create.

Exactly.

> Otherwise you could simply "deallocate" the content with
> truncate(1).
> 
>> The only thing I found is on Linux, fallocate(2) with
>> FALLOC_FL_PUNCH_HOLE.
>> 
>> What about FreeBSD ?
> 
> I remember some discussions about adding something similar
> for FreeBSD but I don't remember ever seeing any patches
> (or commits) for it.

Would really be nice !

> As a work around you can enable ZFS compression (if it isn't
> enabled already) and "overwrite" data you don't need anymore
> with zeros.
> 
> As an example see the delete_range() function in:
> https://www.fabiankeil.de/sourcecode/electrobsd/ElectroBSD-r312620-6cfa243f1516/0033-ggate-cd-Add-BIO_DELETE-support.diff
> 
> Obviously this only works with ZFS, but you didn't mention
> other file systems anyway.

You're right I only use ZFS.
This is clearly a nice workaround !
Unfortunately, for some reasons, I can't enable ZFS compression.
(I absolutely need userquota on logical size so can't enable compression)

Thank you again !

Ben



More information about the freebsd-fs mailing list