aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/freezer.h
diff options
context:
space:
mode:
authorMatt Helsley <matthltc@us.ibm.com>2008-10-18 23:27:21 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-20 11:52:34 -0400
commitdc52ddc0e6f45b04780b26fc0813509f8e798c42 (patch)
tree384826e9fab4e434bc5c85ce744470ae472e52c3 /include/linux/freezer.h
parent8174f1503f4bf7e9a14b3fbbfdb30c6be6e29f77 (diff)
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>
Diffstat (limited to 'include/linux/freezer.h')
-rw-r--r--include/linux/freezer.h29
1 files changed, 10 insertions, 19 deletions
diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index 17e3bb42dd3c..8f225339eee9 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -46,26 +46,11 @@ static inline bool should_send_signal(struct task_struct *p)
46 46
47/* 47/*
48 * Wake up a frozen process 48 * Wake up a frozen process
49 *
50 * task_lock() is taken to prevent the race with refrigerator() which may
51 * occur if the freezing of tasks fails. Namely, without the lock, if the
52 * freezing of tasks failed, thaw_tasks() might have run before a task in
53 * refrigerator() could call frozen_process(), in which case the task would be
54 * frozen and no one would thaw it.
55 */ 49 */
56static inline int thaw_process(struct task_struct *p) 50extern int __thaw_process(struct task_struct *p);
57{ 51
58 task_lock(p); 52/* Takes and releases task alloc lock using task_lock() */
59 if (frozen(p)) { 53extern int thaw_process(struct task_struct *p);
60 p->flags &= ~PF_FROZEN;
61 task_unlock(p);
62 wake_up_process(p);
63 return 1;
64 }
65 clear_freeze_flag(p);
66 task_unlock(p);
67 return 0;
68}
69 54
70extern void refrigerator(void); 55extern void refrigerator(void);
71extern int freeze_processes(void); 56extern int freeze_processes(void);
@@ -83,6 +68,12 @@ static inline int try_to_freeze(void)
83extern bool freeze_task(struct task_struct *p, bool sig_only); 68extern bool freeze_task(struct task_struct *p, bool sig_only);
84extern void cancel_freezing(struct task_struct *p); 69extern void cancel_freezing(struct task_struct *p);
85 70
71#ifdef CONFIG_CGROUP_FREEZER
72extern int cgroup_frozen(struct task_struct *task);
73#else /* !CONFIG_CGROUP_FREEZER */
74static inline int cgroup_frozen(struct task_struct *task) { return 0; }
75#endif /* !CONFIG_CGROUP_FREEZER */
76
86/* 77/*
87 * The PF_FREEZER_SKIP flag should be set by a vfork parent right before it 78 * The PF_FREEZER_SKIP flag should be set by a vfork parent right before it
88 * calls wait_for_completion(&vfork) and reset right after it returns from this 79 * calls wait_for_completion(&vfork) and reset right after it returns from this