[PATCH] D38295: Do not use posix_fallocate because it's slow.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 13:32:35 PDT 2017


Rafael Avila de Espindola <rafael.espindola at gmail.com> writes:

> Which filesystems don't have it?
>
> Is the issue just an error message? I thought we would get a hard crash
> trying to write to a mmaped area when there is no space available to
> flush it to disk.

Yes, that is the case. See the attached test program. It will crash if
the file system has less than 1gb available.

What I think we can do is

* Nothing and stay slow on file systems that don't support
  fallocate. glibc does use it when it is available.
* Write the output to anonymous memory and then use write(2).
* Create a class to abstract having a buffer we write to.

Given how slow you report the current situation being, I would suggest
first benchmarking the second option in a few file systems. If that is
too slow in some, implement the third option.

The class would look something like

class MMapOutput {
      // allocate FD to Size if it is supported by the filesystem and
      // mmap it. If pre allocation fails, get an anonymous memory
      // buffer of Size bytes.
      MMapOutput(int FD, size_t Size);

      // Return the mmaped or anonymous buffer.
      void *getBuffer();
      private:
      // The buffer if we could not pre allocated the file.
      std::unique_ptr<void *> Buffer;
};

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.c
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170928/93f3e91f/attachment.c>
-------------- next part --------------

Cheers,
Rafael


More information about the llvm-commits mailing list