When dumping the memory of a process, CRIU must frequently query the kernel to determine which virtual memory pages are currently present in RAM, swapped out, or modified (dirty). This information is typically retrieved from the /proc/$pid/pagemap file. However, reading and parsing this file repeatedly for every Virtual Memory Area (VMA) is inefficient. To solve this, CRIU implements a high-performance Pagemap Cache.
The /proc/$pid/pagemap file is a 64-bit-per-page binary stream. For a process with a large address space, this file can be several megabytes in size. While a single sequential read is fast, CRIU needs this data across multiple stages of the dump (e.g., initial size estimation, private memory dumping, shared memory dumping, and iterative pre-dumps). Performing multiple full reads and frequent lseek() calls into this file introduces significant overhead, especially for applications with thousands of small VMAs.
The pagemap cache (struct pmc) optimizes access through several advanced techniques:
Instead of reading the entire pagemap at once, CRIU uses a sliding window (typically 2MB in size, defined as PMC_SIZE).
read() system calls and minimizes the overhead of kernel-side page table walks.On modern kernels (v6.7+), the pagemap cache leverages the PAGEMAP_SCAN ioctl. This interface is far more efficient than the legacy /proc file:
To ensure consistency, the pagemap cache is per-process and is strictly managed:
The pagemap cache can be disabled for troubleshooting or performance comparison by setting the CRIU_PMC_OFF environment variable.