CRIU provides comprehensive support for checkpointing and restoring Control Groups (CGroups) for both cgroup v1 and cgroup v2.
When managing CGroups, CRIU handles three main aspects:
CLONE_NEWCGROUP), ensuring that the restored tasks have the same view of the cgroup hierarchy.By default, CRIU manages cgroups in soft mode (--manage-cgroups=soft). In this mode:
CRIU fully supports the unified cgroup v2 hierarchy. Key features include:
cgroup.subtree_control, cgroup.max.descendants, and cgroup.max.depth.cgroup.procs (or cgroup.threads for threaded controllers).cgroup.freeze).CRIU leverages cgroup namespaces to accurately restore a container’s view of the cgroup tree. During restoration:
unshare(CLONE_NEWCGROUP) to pin the root of the cgroup namespace to that location, matching the original environment.CRIU supports dumping and restoring cgroup filesystem mountpoints. However, a significant limitation exists regarding bind-mounted subgroups:
Root Mount Requirement: By default, CRIU expects to find the “root” mount of a cgroup controller (where the mount root is /) within the dumped mount namespace.
/sys/fs/cgroup/memory/my-container is bind-mounted to /sys/fs/cgroup/memory) without a corresponding root mount of that controller being visible, CRIU may fail the dump.To overcome this, such mounts must often be treated as external mounts (--external mnt[...]) or the full hierarchy must be made visible to CRIU during the dump.
The --manage-cgroups=MODE option allows for fine-grained control:
none: Requires cgroups to pre-exist; does not restore properties.props: Requires cgroups to pre-exist; restores properties from the image.soft (Default): Restores properties only for cgroups created by CRIU.full: Always recreates all cgroups and restores all properties.strict: Recreates all cgroups from scratch; fails if any already exist.ignore: Completely ignores cgroup information.The --cgroup-yard PATH option allows CRIU to use a pre-mounted cgroup hierarchy located at PATH. This is particularly useful in unprivileged environments where CRIU may not have the CAP_SYS_ADMIN capability required to mount cgroup filesystems itself. For every cgroup mount, there should be exactly one directory named after the controller(s) co-mounted there (or “unified” for cgroup v2).