On Thu, Apr 4, 2013 at 8:19 AM, Howard Chu <h...@symas.com> wrote: > This is why OpenLDAP LMDB uses a read-only mmap by default. User bugs get an > immediate SEGV, and usually the bug becomes obvious and easy to fix.
There are many reasons to want to use read-only mmap()s (with MAP_SHARED though) and write(2)/pwrite(2) for writing. Accidental write prevention is only one of them. Another has to do with managing of write visibility and performance of msync(MS_SYNC): - msync(MS_SYNC) is depressingly often implemented as a sequence of synchronous writes of each page in the given memory range(!), which completely destroys write performance. Whereas write(2)/pwrite(2) are completely asynchronous and fsync(2) does a single synchronous operation (well, it's not that simple, but fsync(2) is generally much faster than msync(MS_SYNC). Of course, one can still write via an mmap, call msync(MS_ASYNC), then fsync(2) and get the same effect as writing via write(2) and then fsync(2). - msync(MS_ASYNC) is a no-op on unified buffer cache OSes. msync(MS_ASYNC) should be used prior to reading new transaction data, even though in general it will be a no-op. Nico -- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users