CRIU employs a specialized multi-stage process to preserve Copy-on-Write (COW) sharing of private anonymous memory mappings during restoration. This prevents the memory duplication that would occur if each process’s memory were restored independently, thereby significantly reducing the memory footprint of the restored process tree.
When a process calls fork(), the Linux kernel optimizes memory usage by sharing private anonymous mappings between the parent and child. Physical pages are only duplicated (COW) when one of the processes modifies them.
Traditional checkpointing captures each process’s memory separately. If restored naively (by mapping and filling each VMA individually), the kernel would allocate separate physical pages for the parent and child, even for pages that were originally shared. This leads to a massive increase in physical memory usage upon restoration.
To keep COW mappings intact, CRIU performs restoration in a way that mimics the original fork() behavior.
Before forking the process tree, CRIU analyzes the memory maps of all tasks:
PROT_READ, PROT_WRITE), and belong to the same executable.During restoration, processes are created in a specific order:
A parent may contain pages that were unmapped or modified in the child process. To ensure the child’s memory layout is perfectly accurate:
madvise(MADV_DONTNEED) on any pages that exist in the inherited VMA but were not present in the child’s dump images. This effectively “punches holes” in the child’s VMA to match its original state while preserving the sharing of other pages.init (PID 1) and that init process is not part of the checkpointed process tree, CRIU cannot identify the parent’s VMAs, and COW sharing will not be restored for that process.mremap) after the original fork(), CRIU’s current address-based matching algorithm will fail to identify it as a COW candidate.