container freezer: implement freezer cgroup subsystem

This patch implements a new freezer subsystem in the control groups
framework.  It provides a way to stop and resume execution of all tasks in
a cgroup by writing in the cgroup filesystem.

The freezer subsystem in the container filesystem defines a file named
freezer.state.  Writing "FROZEN" to the state file will freeze all tasks
in the cgroup.  Subsequently writing "RUNNING" will unfreeze the tasks in
the cgroup.  Reading will return the current state.

* Examples of usage :

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

to get status of the freezer subsystem :

   # cat /containers/0/freezer.state
   RUNNING

to freeze all tasks in the container :

   # echo FROZEN > /containers/0/freezer.state
   # cat /containers/0/freezer.state
   FREEZING
   # cat /containers/0/freezer.state
   FROZEN

to unfreeze all tasks in the container :

   # echo RUNNING > /containers/0/freezer.state
   # cat /containers/0/freezer.state
   RUNNING

This is the basic mechanism which should do the right thing for user space
task in a simple scenario.

It's important to note that freezing can be incomplete.  In that case we
return EBUSY.  This means that some tasks in the cgroup are busy doing
something that prevents us from completely freezing the cgroup at this
time.  After EBUSY, the cgroup will remain partially frozen -- reflected
by freezer.state reporting "FREEZING" when read.  The state will remain
"FREEZING" until one of these things happens:

	1) Userspace cancels the freezing operation by writing "RUNNING" to
		the freezer.state file
	2) Userspace retries the freezing operation by writing "FROZEN" to
		the freezer.state file (writing "FREEZING" is not legal
		and returns EIO)
	3) The tasks that blocked the cgroup from entering the "FROZEN"
		state disappear from the cgroup's set of tasks.

[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: export thaw_process]
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Acked-by: Serge E. Hallyn <serue@us.ibm.com>
Tested-by: Matt Helsley <matthltc@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Matt Helsley
2008-10-18 20:27:21 -07:00
committed by Linus Torvalds
parent 8174f1503f
commit dc52ddc0e6
30 changed files with 465 additions and 22 deletions

View File

@@ -70,6 +70,7 @@ config AUTO_IRQ_AFFINITY
default y
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "System setup"

View File

@@ -192,6 +192,8 @@ config VECTORS_BASE
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "System Type"
choice

View File

@@ -72,6 +72,8 @@ config GENERIC_BUG
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "System Type and features"
source "kernel/time/Kconfig"

View File

@@ -64,8 +64,11 @@ config HARDWARE_PM
depends on OPROFILE
source "init/Kconfig"
source "kernel/Kconfig.preempt"
source "kernel/Kconfig.freezer"
menu "Blackfin Processor Options"
comment "Processor and Board Settings"

View File

@@ -62,6 +62,8 @@ config HZ
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "General setup"
source "fs/Kconfig.binfmt"

View File

@@ -66,6 +66,8 @@ mainmenu "Fujitsu FR-V Kernel Configuration"
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Fujitsu FR-V system setup"

View File

@@ -90,6 +90,8 @@ config HZ
source "init/Kconfig"
source "kernel/Kconfig.freezer"
source "arch/h8300/Kconfig.cpu"
menu "Executable file formats"

View File

@@ -7,6 +7,8 @@ mainmenu "IA-64 Linux Kernel Configuration"
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Processor type and features"
config IA64

View File

@@ -42,6 +42,8 @@ config HZ
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Processor type and features"

View File

@@ -62,6 +62,8 @@ mainmenu "Linux/68k Kernel Configuration"
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Platform dependent setup"
config EISA

View File

@@ -75,6 +75,8 @@ config NO_IOPORT
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Processor type and features"
choice

View File

@@ -1885,6 +1885,8 @@ config PROBE_INITRD_HEADER
add initrd or initramfs image to the kernel image.
Otherwise, say N.
source "kernel/Kconfig.freezer"
menu "Bus options (PCI, PCMCIA, EISA, ISA, TC)"
config HW_HAS_EISA

View File

@@ -68,6 +68,8 @@ mainmenu "Matsushita MN10300/AM33 Kernel Configuration"
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Matsushita MN10300 system setup"

View File

@@ -90,6 +90,8 @@ config ARCH_MAY_HAVE_PC_FDC
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Processor type and features"

View File

@@ -230,6 +230,8 @@ config PPC_OF_PLATFORM_PCI
source "init/Kconfig"
source "kernel/Kconfig.freezer"
source "arch/powerpc/sysdev/Kconfig"
source "arch/powerpc/platforms/Kconfig"

View File

@@ -78,6 +78,8 @@ config S390
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Base setup"
comment "Processor type and features"

View File

@@ -106,6 +106,8 @@ config IO_TRAPPED
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "System type"
#

View File

@@ -37,6 +37,8 @@ config HZ
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "General machine setup"
config SMP

View File

@@ -96,6 +96,7 @@ config GENERIC_HARDIRQS_NO__DO_IRQ
def_bool y
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Processor type and features"

View File

@@ -229,6 +229,8 @@ endmenu
source "init/Kconfig"
source "kernel/Kconfig.freezer"
source "drivers/block/Kconfig"
source "arch/um/Kconfig.char"

View File

@@ -193,6 +193,7 @@ config X86_TRAMPOLINE
config KTIME_SCALAR
def_bool X86_32
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Processor type and features"

View File

@@ -55,6 +55,7 @@ config HZ
default 100
source "init/Kconfig"
source "kernel/Kconfig.freezer"
menu "Processor type and features"