This articles describes some intricacies of handling shared memory mappings,i.e. anonymous (not file-based) mappings that are shared between a few processes.
== Checkpoint ==
Every process has one or more so called mmapings -- regions of virtual memory which it's allowed to use. Some mappings can be shared between a few processes.
During the checkpointing, CRIU needs to figure out all the shared mappings in order to dump them as such.
It does so by calling <code>fstatat()</code> on each entry found in the <code>/proc/$PID/map_files/</code>,
noting the ''device:inode'' pair of the structure returned by fstatat(). Now, if some processes have amapping with the same ''device:inode'' pair, this mapping is marked as shared between
them and is dumped as such.
Dumping a mapping means writing an entry into proceess' mm.img file and storing its contents. For shared mapping the contents is stored into pagemap-shmem.img and pages.img pair of images (see [[Memory dumps]]).
It' s important to note that the above mechanism works not just for the file-based mappings, but also for the anonymous ones. For an anonymous mapping, kernel actually creates a hidden tmpfs file, and so <code>fstatat()</code> on the <code>/proc/$PID/map_files/</code> entry works the same way as for other files. The tmpfs file itself is not visible from any tmpfs mounts, but can be opened via its <code>map_files</code> entry.
== Restore ==