How checkpoint-restore/criu works
Main Components
• Core Checkpoint/Restore Engine – This covers the “criu” directory, which contains the majority of the runtime code responsible for creating checkpoints, handling images, and restoring processes.
• Parasite Injection Module – Represented by the “compel” directory and associated files; this library (libcompel) implements the technique of injecting code into a live process.
• TCP Socket Handling – The “libsoccr” functionality, along with the “soccr” directory and related tests, support saving and restoring TCP socket states.
• Architecture-Specific Modules – The project supports numerous architectures as indicated by directories like “compel/arch” and “criu/arch”. These modules provide low-level CPU- or kernel-specific code to cope with differences between various systems.
• Plugins – CRIU is modular; the “plugins” directory and subdirectories (e.g., for amdgpu, cuda, etc.) extend the functionality with specific use-case extensions.
• Supporting Libraries and Utility Code – This includes the “lib”, “include”, and “scripts” folders which provide auxiliary functions, public interfaces, build tools, and testing frameworks.
• CI and Testing Infrastructure – With extensive CI configuration files (.github, .circleci, etc.) and “test” directories, it’s clear that automated building and testing are key aspects.
Interactions and Relationships
• The core checkpoint/restore engine then interacts with the parasite injection module (libcompel) to dynamically invoke code inside the running process.
• Once a checkpoint is created, various image files (using the “images” folder and associated message definitions) are generated that capture process state, open file descriptors, memory mappings, and more.
• During restore, the engine uses the same modules in reverse: reestablishing connections via libsoccr (for TCP sockets) and calling architecture-specific routines to set up the process’s CPU state.
• The plugins come into play for specialized tasks (e.g., GPU/AMDGPU, CUDA) and extend the restoration process with additional, externally defined functionality.
• At the bottom layer, common utility libraries and build scripts (Makefiles, configuration files) tie together various modules, while CI and test harnesses validate each component.
Architectural Patterns and Design Principles
• Abstraction per Architecture – A clear pattern is the use of “arch” directories in both CRIU and compel. This abstraction decouples architecture-specific code from the logic in the core engine.
• Library-Driven and Plugin-Extensible – Libraries such as libcompel and libsoccr serve as standalone building blocks which the core engine leverages. Similarly, plugins provide additional functionality without modifying the core.
• Automated Testing and Build Integration – While not part of the runtime path, the extensive CI setups and test folders are an indicator of continuous integration and validation cycles.