But how do you guarantee that all changes have actually made it to disk? OCaml won’t unmap the file when you close it (in fact not even on exit). You could force a garbage collection if you’re sure nothing holds a reference to it anymore (e.g. hide the actual bigarray beyond an option ref
that you make None
and then call full_major
twice).
And without an explicit msync+munmap you can’t know that on all filesystems and all OSes your changes have actually made it to disk.
See mmaped bigarrays over NFS · Issue #3571 · ocaml/ocaml · GitHub (referenced from the Bigarray unmap implementation in OCaml), which references Linux NFS faq “Although some implementations of munmap(2) happen to write dirty pages to local file systems, the NFS version of munmap(2) does not. An msync(2) call is always required to guarantee that dirty mapped data is written to permanent storage.”
Although the OS itself would unmap the pages upon program exit I don’t think we can rely on it to also call msync
on our behalf.