Linux mmap / munmap / ftruncate / mmap implementation is buggy!

For over ten years, I've been using mmap for my own bigtable implementation.
Now, I can surely confirm that, in Linux, mmap / munmap / ftruncate / mmap implementation is buggy.
If you create a file, mmap it into memory, munmap it, extend it with ftruncate, and again, mmap it into memory, program gets corrupted in unpredictable way.
I tried every solution.
The unique workaround for this bug is to use Linux specific mremap function instead of munmap / mmap.

The bug is consistently repeated in the following scenario, for multi-threaded applications:

Create 10 files, each 2 MBytes.
MMap each file into memory in three segments(First segment, 4096 bytes memory as header, second 128*1024 bytes, and the third, the rest of the file)

Create NumOnlineProcessors * 2 thread and concurrently:
Write some data into mmap'ed segments, especially, 3rd segments.
Then, extend third segment by
  ftruncate (Current file size + 1 MBytes)
  mmap whole 3rd segments
Repeat this process

It's sad to see that Linux has still stability issues.


Bu blogdaki popüler yayınlar

Anayasa'da, "Hukukta toplu sorumluluk"

Visual proofs of Hohha Dynamic XOR Encryption Algorithm