criu

Pagemap Cache

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 Performance Problem

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.

Implementation Details

The pagemap cache (struct pmc) optimizes access through several advanced techniques:

1. Sliding Window Caching

Instead of reading the entire pagemap at once, CRIU uses a sliding window (typically 2MB in size, defined as PMC_SIZE).

2. ioctl(PAGEMAP_SCAN) Integration

On modern kernels (v6.7+), the pagemap cache leverages the PAGEMAP_SCAN ioctl. This interface is far more efficient than the legacy /proc file:

3. Cache Invalidation

To ensure consistency, the pagemap cache is per-process and is strictly managed:

Debugging and Control

The pagemap cache can be disabled for troubleshooting or performance comparison by setting the CRIU_PMC_OFF environment variable.

See also