Line 19: |
Line 19: |
| === Restoring === | | === Restoring === |
| | | |
− | Restoring is pretty straightforward as during restore CRIU morphs itself into the target task. Two things worth mentioning. | + | Restoring is pretty straightforward as during restore CRIU morphs itself into the target task. Two things worth mentioning before diving into explanation of steps. |
| | | |
| ;[[COW]] | | ;[[COW]] |
Line 26: |
Line 26: |
| ;[[Shared memory]] | | ;[[Shared memory]] |
| :Those areas are implemented in the kernel by supporting a pseudo file on a hidden tmpfs mount. So on restore we just determine who will create the shared are and who will attach to it (see the [[postulates]]). Then the creator <code>mmap</code>-s the region and the others open the /proc/pid/map_files/ link. However, on the recent kernels, we use the new <code>memfd</code> system call that does similar thing but works for user namespaces. Briefly -- creator creates the memfd, all the others get one via /proc/pid/fd link which is not that strict as compared to the map_files. | | :Those areas are implemented in the kernel by supporting a pseudo file on a hidden tmpfs mount. So on restore we just determine who will create the shared are and who will attach to it (see the [[postulates]]). Then the creator <code>mmap</code>-s the region and the others open the /proc/pid/map_files/ link. However, on the recent kernels, we use the new <code>memfd</code> system call that does similar thing but works for user namespaces. Briefly -- creator creates the memfd, all the others get one via /proc/pid/fd link which is not that strict as compared to the map_files. |
| + | |
| + | having said that, the restore of memory is done in the following steps |
| + | |
| + | ; Opening images and reading VMA-s in |
| + | : Here we open all the mm.img, read mappings in, resolve shared memory segments and check whether we need to special-care mapped files. |
| + | |
| + | ; Forking and pre-mapping |
| + | : At this stage each task pre-mmaps private anonymous areas and populates them with pages (from pagemap/pages images). Then task fork()-s the child which does the same. This is done like this to make COW-ed areas actually share the pages they should. On fork() the shared pages become such and currently that's the only way to make Linux kernel do this. |
| + | |
| + | ; Opening file mappings |
| + | : Soon after fork we check which VMA-s are MAP_FILE ones and request the [[files]] engine to open them. |
| + | |
| + | ; Opening shared mappings |
| + | : At almost the same place we create an FD for shared anonymous VMA-s. |
| + | |
| + | ; Diving into [[restorer context]] |
| + | : At this stage we strip off all the old CRIU mappings thus making the VM be ready for restored mappings. |
| + | |
| + | ; Restoring mappings in their places |
| + | : Anonymous private mappings are <code>mremap</code>-ed from the pre-mapped areas one-by-one, file mappings are created with <code>mmap</code> system call. Anonymous shared mappings are also just mmaped. |
| | | |
| === Non linear mappings === | | === Non linear mappings === |