TopHome
<2023-11-14 Tue>linux

The freezer cgroup

Turns out, there is this interesting cgroup subsystem: the freezer.

      $ ls /sys/fs/cgroup
blkio  cpuacct      cpuset   freezer  memory   net_cls,net_prio  perf_event  rdma
cpu    cpu,cpuacct  devices  hugetlb  net_cls  net_prio          pids        systemd

To test this out, I ran a simple docker container. You can manually create your own cgroup, but this is just faster.

Something like:

$ docker run -it --rm alpine:latest sh

Notice anything strange about this output?

# for i in `seq 1 10`; do date; sleep 1; done
Tue Nov 14 10:36:05 UTC 2023
Tue Nov 14 10:36:06 UTC 2023
Tue Nov 14 10:36:07 UTC 2023
Tue Nov 14 10:36:08 UTC 2023
Tue Nov 14 10:36:32 UTC 2023
Tue Nov 14 10:36:33 UTC 2023
Tue Nov 14 10:36:34 UTC 2023
Tue Nov 14 10:36:35 UTC 2023
Tue Nov 14 10:36:36 UTC 2023
Tue Nov 14 10:36:37 UTC 2023

After the 4th line, I froze the process, using the freezer cgroup. All you need to do is the run the following as root:

echo FROZEN > /sys/fs/cgroup/freezer/docker/<container-cgroup-id>/freezer.state

That's it, the terminal freezes up. "Thaw out" your cgroup again with:

echo THAWED > /sys/fs/cgroup/freezer/docker/<container-cgroup-id>/freezer.state

…and your process(es) begin running again.

It turns out that this is one of the options used by CRIU to do it's freezing, though there is a lot more going on there for saving state and finally being able to restore it, even on another machine.