Line 1: |
Line 1: |
− | This articles describes some intricacies of handling shared memory mappings, i.e. mappings that are shared between a few processes. | + | 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 == | | == Checkpoint == |
| | | |
− | Every process has one or more mmaped files. Some mappings (for example, ones of shared libraries) | + | Every process has one or more mmaped files. Some mappings can be shared between a few processes. |
− | are shared between a few processes. During the checkpointing, CRIU need to figure out
| + | During the checkpointing, CRIU need to figure out all the shared mappings in order to dump them as such. |
− | all the mappings that are shared in order to dump them as such. | |
| | | |
| It does so by performing <code>fstatat()</code> for each entry in <code>/proc/$PID/map_files/</code>, | | It does so by performing <code>fstatat()</code> for each entry in <code>/proc/$PID/map_files/</code>, |
Line 20: |
Line 20: |
| == Restore == | | == Restore == |
| | | |
− | During the restore, CRIU already knows which mappings are shared, so they need to be restored as shared. | + | During the restore, CRIU already knows which mappings are shared, so they need to be |
− | To restore file mappings, no tricks are needed, they are opened and mmaped with with a MAP_SHARED flag set.
| + | restored as such. Here is how it is done. |
− | | |
− | Anonymous memory mappings, though, need some work to be restored as such. Here is how it is done.
| |
| | | |
| Among all the processes sharing a mapping, the one with the lowest PID among the group | | Among all the processes sharing a mapping, the one with the lowest PID among the group |