freezer-subsystem.rst 4.8 KB

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