[Libguestfs] [PATCH 1/2] Preallocate output file

Richard W.M. Jones rjones at redhat.com
Wed Oct 23 06:37:44 UTC 2013


On Wed, Oct 23, 2013 at 03:38:30AM +0100, Pádraig Brady wrote:
[...]

By the way, Eric Sandeen solved the problem.  It's a genuine
misfeature in ext4 called auto_da_alloc which causes a flush on close
if the file has been truncated (ftruncate or O_TRUNC) and the file
size is zero bytes.  I added these patches which work around the
issue:

http://git.annexia.org/?p=pxzcat.git;a=commitdiff;h=68640d56b2ea96401a1355ab56603b0837058d21
http://git.annexia.org/?p=pxzcat.git;a=commitdiff;h=05f0de58de6cbcbdc40f5a661d406b3fbe5a9060

> >     /* Tell the kernel we won't read the output file. */
> >    posix_fadvise (fd, 0, 0, POSIX_FADV_RANDOM|POSIX_FADV_DONTNEED);
> 
> I know this isn't related to your patch,
> but I don't think you can set a flag like this.
> These are rather operations that need to be done
> while writing I think.
> 
> For ref I made the above call after writing various chunks to disk in:
> https://github.com/pixelb/dvd-vr/blob/master/dvd-vr.c#L322
> and also dd:
> http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commit;h=5f31155

This does explain why the posix_fadvise call has no effect.

How about POSIX_FADV_RANDOM?  I would have thought that should be done
before the write operations ...

> BTW dd has this as an option, and dvd-vr is a specialized tool
> often handling large files, so in both these cases FADV_DONTNEED
> is appropriate. If pxzcat will always be used for virt images then
> that does seem appropriate there too, though if used for general
> files then probably not.
> 
> cheers,
> Pádraig.

Thanks, Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW




More information about the Libguestfs mailing list