Why doesn't Lucene (or Elasticsearch) use mmap for writing?

Viewed 73

In most cases, Lucene use MMapDirectory for reading and writing. And it uses mmap for reading, but not for writing. As in the comment of class MMapDirectory :

File-based Directory implementation that uses mmap for reading, and FSDirectory.FSIndexOutput for writing.

I'd like to know why. Is it because mmap write is not faster than traditional write?

1 Answers
  • In Lucene, segments are read many, but only write once. So do mmap writing may be slower than common writing.
  • When using mmap for writing, lucene need to know the total size of index file (use ftruncate + mmap like this answer . However, it is hard to know it when writing.

So, using buffered write is more reasonable and maybe more faster in this case.

Related