# checkpoint-restore/criu architecture

> Architecture diagram of the GitHub repository checkpoint-restore/criu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/checkpoint-restore/criu
- Repository: https://github.com/checkpoint-restore/criu

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: User Process and Core Engine
    U["User Process/Application"] 
    CORE["CRIU Core Engine"]:::core
    U -->|"invokes"| CORE

    %% Internal Modules within CRIU Core
    CH["Image Handler & Serializer"]:::core
    PS["Process State Manager"]:::core
    CORE -->|"serializes"| CH
    CORE -->|"managesState"| PS

    %% Modules Group
    subgraph "Modules"
        PI["Parasite Injection Module (libcompel)"]:::plugin
        TCP["TCP Socket Handling (libsoccr)"]:::library
        subgraph "Architecture-Specific Modules"
            CA["CRIU Arch Modules"]:::arch
            CO["Compel Arch Modules"]:::arch
        end
        subgraph "Plugin Extensions"
            PL["Plugins Directory"]:::plugin
            CP["Compel Plugins"]:::plugin
        end
    end

    CORE -->|"injects"| PI
    CORE -->|"handlesTCP"| TCP
    CORE -->|"invokesArch"| CA
    CORE -->|"invokesArch"| CO
    CORE -->|"integrates"| PL
    CORE -->|"integrates"| CP

    %% Supporting Infrastructure Group
    subgraph "Supporting Infrastructure"
        LIB["Libraries (lib/)"]:::library
        INC["Include Files (include/)"]:::library
        SCR["Scripts (scripts/)"]:::library
        DOC["Documentation"]:::library
    end
    LIB --- INC
    LIB --- SCR
    LIB --- DOC
    LIB -->|"supports"| CORE

    %% CI and Testing Infrastructure Group
    subgraph "CI & Testing Infrastructure"
        CI1[".circleci/"]:::ci
        CI2[".github/"]:::ci
        TS["Test Suites (test/)"]:::ci
    end
    CI1 -->|"validates"| CORE
    CI2 -->|"validates"| CORE
    TS -->|"tests"| CORE

    %% Click Events
    click CORE "https://github.com/checkpoint-restore/criu/tree/criu-dev/criu/"
    click PI "https://github.com/checkpoint-restore/criu/tree/criu-dev/compel/"
    click TCP "https://github.com/checkpoint-restore/criu/blob/criu-dev/soccr/soccr.c"
    click CA "https://github.com/checkpoint-restore/criu/tree/criu-dev/criu/arch/"
    click CO "https://github.com/checkpoint-restore/criu/tree/criu-dev/compel/arch/"
    click PL "https://github.com/checkpoint-restore/criu/tree/criu-dev/plugins/"
    click CP "https://github.com/checkpoint-restore/criu/tree/criu-dev/compel/plugins"
    click LIB "https://github.com/checkpoint-restore/criu/tree/criu-dev/lib/"
    click INC "https://github.com/checkpoint-restore/criu/tree/criu-dev/include/"
    click SCR "https://github.com/checkpoint-restore/criu/tree/criu-dev/scripts/"
    click DOC "https://github.com/checkpoint-restore/criu/tree/criu-dev/Documentation/"
    click CI1 "https://github.com/checkpoint-restore/criu/tree/criu-dev/.circleci/"
    click CI2 "https://github.com/checkpoint-restore/criu/tree/criu-dev/.github/"
    click TS "https://github.com/checkpoint-restore/criu/tree/criu-dev/test/"

    %% Styles
    classDef core fill:#ffcccc,stroke:#cc0000,stroke-width:2px,color:#000;
    classDef library fill:#ccffcc,stroke:#006600,stroke-width:2px,color:#000;
    classDef plugin fill:#cce5ff,stroke:#004085,stroke-width:2px,color:#000;
    classDef arch fill:#fff2cc,stroke:#b58900,stroke-width:2px,color:#000;
    classDef ci fill:#f1c0e8,stroke:#a60073,stroke-width:2px,color:#000;
```
