3 ms·
If your data contains pointers, then for it to be round-tripped through persistence correctly, i would imagine you'd need to map it at the same virtual memory a
by twic 8y ago
If your data contains pointers, then for it to be round-tripped through persistence correctly, i would imagine you'd need to map it at the same virtual memory address every time. Which isn't possible. Have i got that wrong?
- wmf 8y agoWhen you mmap() a file you can specify the virtual address so it will be the same every time.
- pbalcer 8y agoYes, but to accomplish that you would have to use the MAP_FIXED flag, which is quite dangerous because it can replace previous mappings. That can lead to problems with dynamic memory allocation since almost all malloc() implementations use anonymous mmap.
- repolfx 8y agoYes but this is a trivial problem to fix on 64 bit machines. There's so much address space the kernel can just be told to never pick certain address ranges for unfixed mmaps, leaving the rest of the address space free for persistent heaps. The actual hard part of persistent heaps isn't the persistence part. It's transactionality and upgrade management.
- pbalcer 8y agoThat's an excellent observation. You are indeed correct that pointers in memory mapped files are quite tricky to get right. When you think about shared memory in general, this isn't a new problem [0], and the solution is almost exactly the same [1]. Instead of dealing with raw pointers, the library provides an encapsulated fat pointer which contains an offset from the beginning of the mapping. And when the file is opened, we simply register the new virtual address, and calculate the real address when needed. [0] - https://www.boost.org/doc/libs/1_63_0/doc/html/interprocess/quick_guide.html#interprocess.quick_guide.qg_offset_ptr https://www.boost.org/doc/libs/1_63_0/doc/html/interprocess/... [1] - http://pmem.io/pmdk/cpp_obj/master/cpp_html/classpmem_1_1obj_1_1persistent__ptr.html http://pmem.io/pmdk/cpp_obj/master/cpp_html/classpmem_1_1obj...