Dumping and restoring the memory of a process tree is one of the most critical and complex tasks performed by CRIU. This document details the mechanisms, optimizations, and kernel interfaces involved in this process.
A process’s address space is composed of several Virtual Memory Areas (VMAs). CRIU identifies these areas by parsing /proc/$pid/smaps and /proc/$pid/map_files/.
mm-$id.img file.Capturing memory contents while maintaining consistency and performance requires a multi-stage approach.
CRIU cannot efficiently read a process’s private memory from the outside. Instead, it injects parasite code into the target task. This code runs within the task’s own address space and context, allowing it direct access to all memory regions.
To transfer memory from the parasite to the CRIU dumper with minimal overhead, CRIU uses a zero-copy mechanism:
vmsplice() system call with the SPLICE_F_GIFT flag. This effectively “gifts” the memory pages to the kernel’s pipe buffer without copying the data in userspace.splice() to move the data from the pipe directly into the image file (pages-$id.img) or to a network socket (for the page server).CRIU avoids dumping unnecessary data to save time and space:
PAGEMAP_SCAN), CRIU can identify and dump only those pages that have changed since a previous pre-dump.Restoring memory involves reconstructing the exact address space layout the application had at the moment of the checkpoint.
During the early stages of restoration, each process calls mmap() to recreate its VMAs based on the data in mm-$id.img.
CRIU then repopulates the mappings with the data stored in the pages-$id.img files. For efficiency, CRIU uses its own optimized I/O routines to read the images and fill the memory regions.
CRIU uses a specialized strategy to ensure that memory shared via fork() (Copy-on-Write) remains shared after restoration. This minimizes the total physical memory footprint of the restored process tree. See COW Memory for details.
userfaultfd kernel feature and is essential for reducing initial downtime.