← Back to context

Comment by rui314

5 years ago

I chose mmap based on benchmarking. Writing a 2 GiB memory buffer to a file using write(2) was slower than directly constructing file contents to mmap'ed memory region.

What is more interesting is the real bottleneck was not about mmap vs write(v) but in the filesystem. If you create a fresh file and write 2 GiB of data to that file, it takes like 700 milliseconds on my machine (ext4 fs), but if you write the same amount of data to an existing 2 GiB file, the IO speed doubles. So, the filesystem's performance to allocate new disk blocks seems to limit the performance of my linker. That reminded me of the axiom: don't guess about performance but measure.

> So, the filesystem's performance to allocate new disk blocks seems to limit the performance of my linker.

If you know the total size ahead of time, you might try using fallocate(2).

  • I actually tried fallocate(2) but it didn't change the performance characteristics at all. It doesn't seem to do what its man page says.