This is basically used for this little gem: http://symas.com/mdb/ LMDB is at the heart of the ubiquitous LDAP ( OpenLDAP ) and is very well optimized ( look at his benchmarks ). Now they are optimized for reading, which is important. I would imagine mmap-ing with large amount of write will result in unpredictable performance....
The mmap pattern
31–40 of 48 posts
Re: The mmap pattern
#32For a while I've wanted a nice C library for an mmapped heap with allocation and common data structures (and maybe locks?) - all the usual stuff you'd expect in a standard library, but with support for relative offsets instead of pointers, crash robustness, introspection, and other features required to work well with a persistent file. I do not know any library of this type that currently exists.
Re: The mmap pattern
#33Earlier quoted context omitted.
Different types of crashes and different memory. You can crash because you program did not handle a network error well, etc. Also, you do not need to use mmap'ed memory for everything. You can still use the stack and the heap for temporary structures, but store permanent data in the mmap'ed segments. Think about persistent data vs running queries in a database server.
How is it then different from sqlite?
Re: The mmap pattern
#34> One very key architectural decision for a system is the degree of reliability that it should possess. This is an explicit trade-off between the rapidity of development (in particular the level of indoctrination needed before new contributors are able to augment the feature set) and the operational stability. By preserving state explicitly to memory backed files, several classes of unexpected events causing the prog…
Re: The mmap pattern
#35The act of serializing data structures and reloading them can be a guard against long-term corruption. If you only use mmap, there's a risk of some corner of the object graph getting subtly wrong owing to a bug in one version of the software, and never getting repaired. Versioning of data structures is also a problem. I'd leave this pattern for use cases for which copying of memory on load has a measurable impact on…
Re: The mmap pattern
#36Optimizations aside, beware this approach. ASLR is one of your two best friends (the other is DEP). When you purposely circumvent the protection it provides a security researcher somewhere will make you the topic of a very pointy blog post.
Re: The mmap pattern
#37> One very key architectural decision for a system is the degree of reliability that it should possess. This is an explicit trade-off between the rapidity of development (in particular the level of indoctrination needed before new contributors are able to augment the feature set) and the operational stability. By preserving state explicitly to memory backed files, several classes of unexpected events causing the prog…
I've worked on financial transaction processing systems using memory mapped files as their primary means of data storage. It is very effective.
Re: The mmap pattern
#38The act of serializing data structures and reloading them can be a guard against long-term corruption. If you only use mmap, there's a risk of some corner of the object graph getting subtly wrong owing to a bug in one version of the software, and never getting repaired. Versioning of data structures is also a problem. I'd leave this pattern for use cases for which copying of memory on load has a measurable impact on…
One obvious example would be filesystems. They're basically specialized databases which treat your whole disk as a single gigantic file, and of course there's a long, proud history of programs used to repair corruption in them due to bugs or other problematic events.
To me, that's an argument for not using formats with incremental formats if you can get away with rewriting the file each time, but once you have enough data to where you can't afford a total rewrite each time, does mmap make the problem any worse?
Re: The mmap pattern
#39"By preserving state explicitly to memory backed files, several classes of unexpected events causing the program to crash can be recovered from with minimal disruption." The cure is surely worse than the disease! The program state in memory at the time of abnormal termination is likely to be inconsistent, leading to an unusable file. The subset of that that happens to have been committed to disk is likely to be worse…
Re: The mmap pattern
#40https://plus.google.com/u/0/+KentonVarda/posts/NKUUzx2nEsN
If you're looking for an easy way to exploit mmap in your code, Cap'n Proto is a serialization format that works similarly to Protocol Buffers but is designed to work well with mmap():
(Disclosure: I am the author of Cap'n Proto... and also the former maintainer of protobufs.)