← Documents Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Cgroup v1

Cgroup Freezer

Batch·checkpoint용 hierarchical freezer의 state machine과 cgroupfs 사용법을 설명합니다.

Source pathDocumentation/admin-guide/cgroup-v1/freezer-subsystem.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

Purpose

freezer-subsystem.rst:1-55

Checkpointing과 signal-based stopping의 문제를 설명합니다.

State and interface

freezer-subsystem.rst:56-99

Self/parent freezing state와 세 interface file을 정리합니다.

Usage

freezer-subsystem.rst:100-131

Freeze/thaw command와 cgroup v2 권고를 다룹니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ==============
2 Cgroup Freezer
3 ==============
4
5 The cgroup freezer is useful to batch job management system which start
6 and stop sets of tasks in order to schedule the resources of a machine
7 according to the desires of a system administrator. This sort of program
8 is often used on HPC clusters to schedule access to the cluster as a
9 whole. The cgroup freezer uses cgroups to describe the set of tasks to
10 be started/stopped by the batch job management system. It also provides
11 a means to start and stop the tasks composing the job.
12
13 The cgroup freezer will also be useful for checkpointing running groups
14 of tasks. The freezer allows the checkpoint code to obtain a consistent
15 image of the tasks by attempting to force the tasks in a cgroup into a
16 quiescent state. Once the tasks are quiescent another task can
17 walk /proc or invoke a kernel interface to gather information about the
18 quiesced tasks. Checkpointed tasks can be restarted later should a
19 recoverable error occur. This also allows the checkpointed tasks to be
20 migrated between nodes in a cluster by copying the gathered information
21 to another node and restarting the tasks there.
22
23 Sequences of SIGSTOP and SIGCONT are not always sufficient for stopping
24 and resuming tasks in userspace. Both of these signals are observable
25 from within the tasks we wish to freeze. While SIGSTOP cannot be caught,
26 blocked, or ignored it can be seen by waiting or ptracing parent tasks.
27 SIGCONT is especially unsuitable since it can be caught by the task. Any
28 programs designed to watch for SIGSTOP and SIGCONT could be broken by
29 attempting to use SIGSTOP and SIGCONT to stop and resume tasks. We can
30 demonstrate this problem using nested bash shells::
31
32 $ echo $$
33 16644
34 $ bash
35 $ echo $$
36 16690
37
38 From a second, unrelated bash shell:
39 $ kill -SIGSTOP 16690
40 $ kill -SIGCONT 16690
41
42 <at this point 16690 exits and causes 16644 to exit too>
43
44 This happens because bash can observe both signals and choose how it
45 responds to them.
46
47 Another example of a program which catches and responds to these
48 signals is gdb. In fact any program designed to use ptrace is likely to
49 have a problem with this method of stopping and resuming tasks.
50
51 In contrast, the cgroup freezer uses the kernel freezer code to
52 prevent the freeze/unfreeze cycle from becoming visible to the tasks
53 being frozen. This allows the bash example above and gdb to run as
54 expected.
55
56 The cgroup freezer is hierarchical. Freezing a cgroup freezes all
57 tasks belonging to the cgroup and all its descendant cgroups. Each
58 cgroup has its own state (self-state) and the state inherited from the
59 parent (parent-state). Iff both states are THAWED, the cgroup is
60 THAWED.
61
62 The following cgroupfs files are created by cgroup freezer.
63
64 * freezer.state: Read-write.
65
66 When read, returns the effective state of the cgroup - "THAWED",
67 "FREEZING" or "FROZEN". This is the combined self and parent-states.
68 If any is freezing, the cgroup is freezing (FREEZING or FROZEN).
69
70 FREEZING cgroup transitions into FROZEN state when all tasks
71 belonging to the cgroup and its descendants become frozen. Note that
72 a cgroup reverts to FREEZING from FROZEN after a new task is added
73 to the cgroup or one of its descendant cgroups until the new task is
74 frozen.
75
76 When written, sets the self-state of the cgroup. Two values are
77 allowed - "FROZEN" and "THAWED". If FROZEN is written, the cgroup,
78 if not already freezing, enters FREEZING state along with all its
79 descendant cgroups.
80
81 If THAWED is written, the self-state of the cgroup is changed to
82 THAWED. Note that the effective state may not change to THAWED if
83 the parent-state is still freezing. If a cgroup's effective state
84 becomes THAWED, all its descendants which are freezing because of
85 the cgroup also leave the freezing state.
86
87 * freezer.self_freezing: Read only.
88
89 Shows the self-state. 0 if the self-state is THAWED; otherwise, 1.
90 This value is 1 iff the last write to freezer.state was "FROZEN".
91
92 * freezer.parent_freezing: Read only.
93
94 Shows the parent-state. 0 if none of the cgroup's ancestors is
95 frozen; otherwise, 1.
96
97 The root cgroup is non-freezable and the above interface files don't
98 exist.
99
100 * Examples of usage::
101
102 # mkdir /sys/fs/cgroup/freezer
103 # mount -t cgroup -ofreezer freezer /sys/fs/cgroup/freezer
104 # mkdir /sys/fs/cgroup/freezer/0
105 # echo $some_pid > /sys/fs/cgroup/freezer/0/tasks
106
107 to get status of the freezer subsystem::
108
109 # cat /sys/fs/cgroup/freezer/0/freezer.state
110 THAWED
111
112 to freeze all tasks in the container::
113
114 # echo FROZEN > /sys/fs/cgroup/freezer/0/freezer.state
115 # cat /sys/fs/cgroup/freezer/0/freezer.state
116 FREEZING
117 # cat /sys/fs/cgroup/freezer/0/freezer.state
118 FROZEN
119
120 to unfreeze all tasks in the container::
121
122 # echo THAWED > /sys/fs/cgroup/freezer/0/freezer.state
123 # cat /sys/fs/cgroup/freezer/0/freezer.state
124 THAWED
125
126 This is the basic mechanism which should do the right thing for user space task
127 in a simple scenario.
128
129 This freezer implementation is affected by shortcomings (see commit
130 76f969e8948d8 ("cgroup: cgroup v2 freezer")) and cgroup v2 freezer is
131 recommended.
132

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Batch scheduling과 checkpointing

1-18

Cgroup freezer는 system administrator 정책에 따라 machine resource를 schedule하는 batch job manager가 task 집합을 시작·정지할 때 유용합니다. 특히 HPC cluster에서 cluster 전체 access를 schedule하는 데 쓰이며 cgroup으로 job task 집합을 표현하고 그 task들을 함께 stop/start합니다.

Freezer use cases
Use caseWhy freeze the cgroup
Batch schedulingJob task 전체를 멈추고 machine resource를 다른 job에 배정
CheckpointingConsistent task image를 수집할 quiescent state 확보
RecoveryRecoverable error 뒤 checkpointed task restart
Cluster migrationCollected state를 다른 node로 복사해 restart

Task group을 quiescent state로 만드는 두 대표 목적입니다.

Checkpoint and migration
Freeze cgroup tasksAll tasks become quiescentAnother task walks /proc or kernel interfaceCollect consistent stateRestart locally or on another cluster node

Freezer가 task group의 일관된 snapshot 수집을 가능하게 합니다.

SIGSTOP/SIGCONT가 부적합한 이유

19-55

User-space에서 `SIGSTOP`과 `SIGCONT`를 차례로 보내는 것만으로는 task를 투명하게 stop/resume할 수 없습니다. 두 signal 모두 대상 task 내부에서 관측할 수 있습니다. `SIGSTOP`은 catch·block·ignore할 수 없지만 wait하거나 parent를 ptrace하면 보이고, `SIGCONT`는 task가 직접 catch할 수도 있습니다.

demonstrate this problem using nested bash shells::

	$ echo $$
	16644
	$ bash
	$ echo $$
	16690

	From a second, unrelated bash shell:
	$ kill -SIGSTOP 16690
	$ kill -SIGCONT 16690

	<at this point 16690 exits and causes 16644 to exit too>
Signal freezing versus cgroup freezer
MechanismVisible to frozen taskConsequence
SIGSTOPObservable by waiting or ptracing parentProgram may react
SIGCONTCatchable and observableResume changes program behavior
Kernel freezerFreeze/unfreeze cycle hiddenBash and gdb behave normally

Bash, gdb와 ptrace-aware program이 보게 되는 차이입니다.

Nested Bash 예제에서는 child shell 16690에 두 signal을 보내자 child가 종료되고 parent 16644도 함께 종료됩니다. Bash가 signal을 관측해 자체 대응하기 때문입니다. `gdb`처럼 ptrace를 사용하는 program도 같은 문제가 생길 수 있습니다.

Cgroup freezer는 kernel freezer code를 사용해 freeze/unfreeze cycle을 대상 task에 보이지 않게 하므로 Bash 예제와 gdb가 예상대로 동작합니다.

계층 상태와 cgroupfs interface

56-99

Freezer는 hierarchical합니다. Cgroup을 freeze하면 그 cgroup과 모든 descendant cgroup의 task가 freeze됩니다. 각 cgroup은 자체 self-state와 parent에서 상속한 parent-state를 가지며 둘 다 `THAWED`일 때만 effective state가 `THAWED`입니다.

Freezer interface files
FileAccessMeaning
freezer.stateRead-writeEffective THAWED/FREEZING/FROZEN; write FROZEN or THAWED to self-state
freezer.self_freezingRead-onlyLast self request: THAWED=0, FROZEN request=1
freezer.parent_freezingRead-onlyAny frozen ancestor: yes=1, none=0

각 cgroup이 제공하는 state file과 의미입니다.

Freezer state transitions
Write FROZENSelf-state becomes freezingCgroup and descendants enter FREEZINGAll tasks frozenFROZEN
Add a new task while FROZENRevert to FREEZINGFreeze new taskFROZEN again
Write THAWEDSelf-state THAWEDParent still freezing?Remain effectively freezing or become THAWED

Effective state는 self와 ancestor request, 실제 task freeze 완료 여부를 결합합니다.

`freezer.state` read는 combined effective state를 반환합니다. Self나 parent 중 하나가 freezing이면 effective state도 `FREEZING` 또는 `FROZEN`입니다. 모든 local·descendant task가 frozen이 되면 `FREEZING`에서 `FROZEN`으로 바뀝니다.

`THAWED`를 써도 ancestor가 freezing이면 effective state는 thawed가 되지 않습니다. 실제 effective state가 `THAWED`가 되면 그 cgroup 때문에 freezing 중이던 descendant도 freezing을 벗어납니다. Root cgroup은 freeze할 수 없고 이 interface file도 없습니다.

Mount·freeze·thaw 예제와 v2 권고

100-131
* Examples of usage::

   # mkdir /sys/fs/cgroup/freezer
   # mount -t cgroup -ofreezer freezer /sys/fs/cgroup/freezer
   # mkdir /sys/fs/cgroup/freezer/0
   # echo $some_pid > /sys/fs/cgroup/freezer/0/tasks

to get status of the freezer subsystem::

   # cat /sys/fs/cgroup/freezer/0/freezer.state
   THAWED

to freeze all tasks in the container::

   # echo FROZEN > /sys/fs/cgroup/freezer/0/freezer.state
   # cat /sys/fs/cgroup/freezer/0/freezer.state
   FREEZING
   # cat /sys/fs/cgroup/freezer/0/freezer.state
   FROZEN

to unfreeze all tasks in the container::

   # echo THAWED > /sys/fs/cgroup/freezer/0/freezer.state
   # cat /sys/fs/cgroup/freezer/0/freezer.state
   THAWED
Basic freezer operation
Mount freezer controllermkdir freezer/0Write PID to tasksRead THAWEDWrite FROZENObserve FREEZING then FROZENWrite THAWED

Child cgroup을 만들고 task를 attach한 뒤 state가 완료될 때까지 관측합니다.

Implementation caveat
ItemStatus
Cgroup v1 freezerBasic userspace task scenario 지원, known shortcomings 존재
Known referencecommit 76f969e8948d8 ("cgroup: cgroup v2 freezer")
Recommended controllerCgroup v2 freezer

Legacy freezer와 권장 대안을 구분합니다.