Previously, all datafiles/journals that were initially mapped were mapped with PROT_READ only, and later the memory protection was changed to PROT_READ | PROT_WRITE using mprotect().
However, on filesystems that are mounted with NOEXEC, changing the protection from PROT_READ to PROT_READ | PROT_WRITE later may fail. This has been reported in issue #2220.
This change now maps all datafiles/journals with PROT_READ | PROT_WRITE in the beginning, and will later change the mapping to PROT_READ if no writes are required
This prevents SIGBUS when a sparse datafile is accessed and the disk is full. In
this case the mmapped region is not necessarily backed by physical memory, and
accessing the memory may crash the program
Essentially the strategy is: A newly created and a newly opened file
is advised to be "SEQUENTIAL ACCESS", because we will either write to
it or scan it sequentially. As soon as it is sealed, we switch the
advice to "RANDOM ACCESS", because this should be the normal pattern and
aggressive read-aheads tend to be bad. The collector and the compactor
switch a sealed file back to "SEQUENTIAL ACCESS" just before they scan
it and back to "RANDOM ACCESS", when they are done.
Furthermore, all data files in a collection are advised with "WILLNEED"
just before the collection is scanned during loading.
Finally, the actual hash table of AssocMulti is advised to be random
access, although this is an anonymous map given to us by malloc and not
a memory mapped file.