Skip to content

Commit

Permalink
seize: enable support for frozen containers
Browse files Browse the repository at this point in the history
Container runtimes like CRI-O and containerd utilize the freezer cgroup
to create a consistent snapshot of container root filesystem (rootfs)
changes. In this case, the container is frozen before invoking CRIU.
After CRIU successfully completes, a copy of the container rootfs diff
is saved, and the container is then unfrozen.

However, the `cuda-checkpoint` tool is not able to perform a 'lock'
action on frozen threads.  To support GPU checkpointing with these
container runtimes, we need to unfreeze the cgroup and return it to its
original state once the checkpointing is complete.

To reflect this new behavior, the following changes are applied:
 - `dont_use_freeze_cgroup(void)` -> `set_compel_interrupt_only_mode(void)`
 - `bool freeze_cgroup_disabled` -> `bool compel_interrupt_only_mode`
 - `check_freezer_cgroup(void)` -> `prepare_freezer_for_interrupt_only_mode(void)`

Note that when `compel_interrupt_only_mode` is set to `true`,
`compel_interrupt_task()` is used instead of `freeze_processes()`
to prevent tasks from running during `criu dump`.

Fixes: #2508

Signed-off-by: Radostin Stoyanov <[email protected]>
  • Loading branch information
rst0git committed Nov 7, 2024
1 parent 216d804 commit 979e277
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion criu/fault-injection.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int fault_injection_init(void)

switch (fi_strategy) {
case FI_DISABLE_FREEZE_CGROUP:
dont_use_freeze_cgroup();
set_compel_interrupt_only_mode();
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion criu/include/seize.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ extern bool alarm_timeouted(void);

extern char *task_comm_info(pid_t pid, char *comm, size_t size);
extern char *__task_comm_info(pid_t pid);
extern void dont_use_freeze_cgroup(void);
extern void set_compel_interrupt_only_mode(void);

#endif
46 changes: 26 additions & 20 deletions criu/seize.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
#include "xmalloc.h"
#include "util.h"

static bool freeze_cgroup_disabled;
static bool compel_interrupt_only_mode;

/*
* Disables the use of freeze cgroups for process seizing, even if explicitly
* requested via the --freeze-cgroup option. This is necessary for plugins
* (e.g., CUDA) that do not function correctly when processes are frozen using
* cgroups.
* requested via the --freeze-cgroup option or already set in a frozen state.
* This is necessary for plugins (e.g., CUDA) that do not function correctly
* when processes are frozen using cgroups.
*/
void __attribute__((used)) dont_use_freeze_cgroup(void)
void __attribute__((used)) set_compel_interrupt_only_mode(void)
{
freeze_cgroup_disabled = true;
compel_interrupt_only_mode = true;
}

char *task_comm_info(pid_t pid, char *comm, size_t size)
Expand Down Expand Up @@ -410,7 +410,7 @@ static int freezer_detach(void)
{
int i;

if (!opts.freeze_cgroup || freeze_cgroup_disabled)
if (!opts.freeze_cgroup || compel_interrupt_only_mode)
return 0;

for (i = 0; i < processes_to_wait && processes_to_wait_pids; i++) {
Expand Down Expand Up @@ -505,29 +505,35 @@ static int log_unfrozen_stacks(char *root)
return 0;
}

static int check_freezer_cgroup(void)
static int prepare_freezer_for_interrupt_only_mode(void)
{
enum freezer_state state = THAWED;
int fd;
int exit_code = -1;

BUG_ON(!freeze_cgroup_disabled);
BUG_ON(!compel_interrupt_only_mode);

fd = freezer_open();
if (fd < 0)
return -1;

state = get_freezer_state(fd);
close(fd);
if (state == FREEZER_ERROR) {
return -1;
goto err;
}

origin_freezer_state = state == FREEZING ? FROZEN : state;

if (state != THAWED) {
pr_err("One or more plugins are incompatible with the freezer cgroup in the FROZEN state.\n");
return -1;
pr_warn("unfreezing cgroup for plugin compatibility\n");
if (freezer_write_state(fd, THAWED))
goto err;
}

return 0;
exit_code = 0;
err:
close(fd);
return exit_code;
}

static int freeze_processes(void)
Expand Down Expand Up @@ -681,7 +687,7 @@ static int collect_children(struct pstree_item *item)
goto free;
}

if (!opts.freeze_cgroup || freeze_cgroup_disabled)
if (!opts.freeze_cgroup || compel_interrupt_only_mode)
/* fails when meets a zombie */
__ignore_value(compel_interrupt_task(pid));

Expand Down Expand Up @@ -869,7 +875,7 @@ static int collect_threads(struct pstree_item *item)

pr_info("\tSeizing %d's %d thread\n", item->pid->real, pid);

if ((!opts.freeze_cgroup || freeze_cgroup_disabled) &&
if ((!opts.freeze_cgroup || compel_interrupt_only_mode) &&
compel_interrupt_task(pid))
continue;

Expand Down Expand Up @@ -926,7 +932,7 @@ static int collect_loop(struct pstree_item *item, int (*collect)(struct pstree_i
{
int attempts = NR_ATTEMPTS, nr_inprogress = 1;

if (opts.freeze_cgroup && !freeze_cgroup_disabled)
if (opts.freeze_cgroup && !compel_interrupt_only_mode)
attempts = 1;

/*
Expand Down Expand Up @@ -1032,11 +1038,11 @@ int collect_pstree(void)

pr_debug("Detected cgroup V%d freezer\n", cgroup_v2 ? 2 : 1);

if (opts.freeze_cgroup && !freeze_cgroup_disabled) {
if (opts.freeze_cgroup && !compel_interrupt_only_mode) {
if (freeze_processes())
goto err;
} else {
if (opts.freeze_cgroup && check_freezer_cgroup())
if (opts.freeze_cgroup && prepare_freezer_for_interrupt_only_mode())
goto err;
if (compel_interrupt_task(pid)) {
set_cr_errno(ESRCH);
Expand Down Expand Up @@ -1067,7 +1073,7 @@ int collect_pstree(void)
if (ret < 0)
goto err;

if (opts.freeze_cgroup && !freeze_cgroup_disabled &&
if (opts.freeze_cgroup && !compel_interrupt_only_mode &&
freezer_wait_processes()) {
goto err;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/cuda/cuda_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ int cuda_plugin_init(int stage)
INIT_LIST_HEAD(&cuda_pids);
}

dont_use_freeze_cgroup();
set_compel_interrupt_only_mode();

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion test/jenkins/criu-fault.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fi
# also check for the main thread corruption
./test/zdtm.py run -t zdtm/static/fpu00 --fault 134 -f h --norst || fail

# check dont_use_freeze_cgroup
# check set_compel_interrupt_only_mode
./test/zdtm.py run -t zdtm/static/env00 --freezecg zdtm:t --fault 137
./test/zdtm.py run -t zdtm/static/env00 --freezecg zdtm:t --fault 137 --norst

Expand Down

0 comments on commit 979e277

Please sign in to comment.