== Restore ==
Upon restore, CRIU already knows which mappings are shared, and the trick is to restore them as such. For that, two different approaches are used, depending on the availability.
The common part is, between the processes sharing a mapping, the one with the lowest PID among the group performs the actual <code>mmap()</code>, while all the others wait for the mapping to appear and, once it's available, use it.
=== memfd ===
Linux kernel v3.17 adds a [http://man7.org/linux/man-pages/man2/memfd_create.2.html memfd_create()] syscall. CRIU restore checks if it is available from the running kernel; it yes, it is used.
HOW: The memfd in question is created in the task with lowest PID ( see [[postulates]]) among those having this shmem segment mapped, then criu waits for the others to get this file by opening the creator's /proc/ pid/ fd/ link. Afterwards all the files just mmap() this descriptor into their address space.
=== /proc/$PID/map_files/ === This method is used if memfd is not available. The limitation is, /proc/$PID/map_files/ is not available for users inside user namespaces ( due to security concerns) , so it's not possible to use it if there are any user namespaces in the dump.
HOW: The same technique as with memfd is used, with two exceptions. First is that creator calls mmap() not memfd_create() and creates the shared memory at once. Then it waits for the others to open its /proc/pid/map_files/ link. After opening "the others" mmap() one to their address space just as if they would have done it with memfd descriptor.
== Changes tracking ==