Skip to content

Commit

Permalink
container freezer: implement freezer cgroup subsystem
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Matt Helsley authored and torvalds committed Oct 20, 2008
1 parent 8174f15 commit dc52ddc
Show file tree
Hide file tree
Showing 30 changed files with 465 additions and 22 deletions.
1 change: 1 addition & 0 deletions arch/alpha/Kconfig
Expand Up @@ -70,6 +70,7 @@ config AUTO_IRQ_AFFINITY
default y

source "init/Kconfig"
source "kernel/Kconfig.freezer"


menu "System setup"
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/Kconfig
Expand Up @@ -192,6 +192,8 @@ config VECTORS_BASE

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "System Type"

choice
Expand Down
2 changes: 2 additions & 0 deletions arch/avr32/Kconfig
Expand Up @@ -72,6 +72,8 @@ config GENERIC_BUG

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "System Type and features"

source "kernel/time/Kconfig"
Expand Down
3 changes: 3 additions & 0 deletions arch/blackfin/Kconfig
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions arch/cris/Kconfig
Expand Up @@ -62,6 +62,8 @@ config HZ

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "General setup"

source "fs/Kconfig.binfmt"
Expand Down
2 changes: 2 additions & 0 deletions arch/frv/Kconfig
Expand Up @@ -66,6 +66,8 @@ mainmenu "Fujitsu FR-V Kernel Configuration"

source "init/Kconfig"

source "kernel/Kconfig.freezer"


menu "Fujitsu FR-V system setup"

Expand Down
2 changes: 2 additions & 0 deletions arch/h8300/Kconfig
Expand Up @@ -90,6 +90,8 @@ config HZ

source "init/Kconfig"

source "kernel/Kconfig.freezer"

source "arch/h8300/Kconfig.cpu"

menu "Executable file formats"
Expand Down
2 changes: 2 additions & 0 deletions arch/ia64/Kconfig
Expand Up @@ -7,6 +7,8 @@ mainmenu "IA-64 Linux Kernel Configuration"

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "Processor type and features"

config IA64
Expand Down
2 changes: 2 additions & 0 deletions arch/m32r/Kconfig
Expand Up @@ -42,6 +42,8 @@ config HZ

source "init/Kconfig"

source "kernel/Kconfig.freezer"


menu "Processor type and features"

Expand Down
2 changes: 2 additions & 0 deletions arch/m68k/Kconfig
Expand Up @@ -62,6 +62,8 @@ mainmenu "Linux/68k Kernel Configuration"

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "Platform dependent setup"

config EISA
Expand Down
2 changes: 2 additions & 0 deletions arch/m68knommu/Kconfig
Expand Up @@ -75,6 +75,8 @@ config NO_IOPORT

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "Processor type and features"

choice
Expand Down
2 changes: 2 additions & 0 deletions arch/mips/Kconfig
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions arch/mn10300/Kconfig
Expand Up @@ -68,6 +68,8 @@ mainmenu "Matsushita MN10300/AM33 Kernel Configuration"

source "init/Kconfig"

source "kernel/Kconfig.freezer"


menu "Matsushita MN10300 system setup"

Expand Down
2 changes: 2 additions & 0 deletions arch/parisc/Kconfig
Expand Up @@ -90,6 +90,8 @@ config ARCH_MAY_HAVE_PC_FDC

source "init/Kconfig"

source "kernel/Kconfig.freezer"


menu "Processor type and features"

Expand Down
2 changes: 2 additions & 0 deletions arch/powerpc/Kconfig
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions arch/s390/Kconfig
Expand Up @@ -78,6 +78,8 @@ config S390

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "Base setup"

comment "Processor type and features"
Expand Down
2 changes: 2 additions & 0 deletions arch/sh/Kconfig
Expand Up @@ -106,6 +106,8 @@ config IO_TRAPPED

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "System type"

#
Expand Down
2 changes: 2 additions & 0 deletions arch/sparc/Kconfig
Expand Up @@ -37,6 +37,8 @@ config HZ

source "init/Kconfig"

source "kernel/Kconfig.freezer"

menu "General machine setup"

config SMP
Expand Down
1 change: 1 addition & 0 deletions arch/sparc64/Kconfig
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions arch/um/Kconfig
Expand Up @@ -229,6 +229,8 @@ endmenu

source "init/Kconfig"

source "kernel/Kconfig.freezer"

source "drivers/block/Kconfig"

source "arch/um/Kconfig.char"
Expand Down
1 change: 1 addition & 0 deletions arch/x86/Kconfig
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions arch/xtensa/Kconfig
Expand Up @@ -55,6 +55,7 @@ config HZ
default 100

source "init/Kconfig"
source "kernel/Kconfig.freezer"

menu "Processor type and features"

Expand Down
6 changes: 6 additions & 0 deletions include/linux/cgroup_subsys.h
Expand Up @@ -48,3 +48,9 @@ SUBSYS(devices)
#endif

/* */

#ifdef CONFIG_CGROUP_FREEZER
SUBSYS(freezer)
#endif

/* */
29 changes: 10 additions & 19 deletions include/linux/freezer.h
Expand Up @@ -46,26 +46,11 @@ static inline bool should_send_signal(struct task_struct *p)

/*
* Wake up a frozen process
*
* task_lock() is taken to prevent the race with refrigerator() which may
* occur if the freezing of tasks fails. Namely, without the lock, if the
* freezing of tasks failed, thaw_tasks() might have run before a task in
* refrigerator() could call frozen_process(), in which case the task would be
* frozen and no one would thaw it.
*/
static inline int thaw_process(struct task_struct *p)
{
task_lock(p);
if (frozen(p)) {
p->flags &= ~PF_FROZEN;
task_unlock(p);
wake_up_process(p);
return 1;
}
clear_freeze_flag(p);
task_unlock(p);
return 0;
}
extern int __thaw_process(struct task_struct *p);

/* Takes and releases task alloc lock using task_lock() */
extern int thaw_process(struct task_struct *p);

extern void refrigerator(void);
extern int freeze_processes(void);
Expand All @@ -83,6 +68,12 @@ static inline int try_to_freeze(void)
extern bool freeze_task(struct task_struct *p, bool sig_only);
extern void cancel_freezing(struct task_struct *p);

#ifdef CONFIG_CGROUP_FREEZER
extern int cgroup_frozen(struct task_struct *task);
#else /* !CONFIG_CGROUP_FREEZER */
static inline int cgroup_frozen(struct task_struct *task) { return 0; }
#endif /* !CONFIG_CGROUP_FREEZER */

/*
* The PF_FREEZER_SKIP flag should be set by a vfork parent right before it
* calls wait_for_completion(&vfork) and reset right after it returns from this
Expand Down
7 changes: 7 additions & 0 deletions init/Kconfig
Expand Up @@ -299,6 +299,13 @@ config CGROUP_NS
for instance virtual servers and checkpoint/restart
jobs.

config CGROUP_FREEZER
bool "control group freezer subsystem"
depends on CGROUPS
help
Provides a way to freeze and unfreeze all tasks in a
cgroup.

config CGROUP_DEVICE
bool "Device controller for cgroups"
depends on CGROUPS && EXPERIMENTAL
Expand Down
2 changes: 2 additions & 0 deletions kernel/Kconfig.freezer
@@ -0,0 +1,2 @@
config FREEZER
def_bool PM_SLEEP || CGROUP_FREEZER
1 change: 1 addition & 0 deletions kernel/Makefile
Expand Up @@ -56,6 +56,7 @@ obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
obj-$(CONFIG_COMPAT) += compat.o
obj-$(CONFIG_CGROUPS) += cgroup.o
obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o
obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
obj-$(CONFIG_CPUSETS) += cpuset.o
obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o
obj-$(CONFIG_UTS_NS) += utsname.o
Expand Down

0 comments on commit dc52ddc

Please sign in to comment.