public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn.fujitsu.com>
To: Matt Helsley <matthltc@us.ibm.com>, Cedric Le Goater <clg@fr.ibm.com>
Cc: Paul Menage <menage@google.com>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	Linux-Kernel <linux-kernel@vger.kernel.org>,
	Linux Containers <containers@lists.linux-foundation.org>,
	linux-pm@lists.linux-foundation.org,
	Andrew Morton <akpm@linux-foundation.org>,
	"Serge E. Hallyn" <serue@us.ibm.com>
Subject: [RFC][PATCH] freezer_cg: disable writing freezer.state of root cgroup
Date: Tue, 04 Nov 2008 15:35:50 +0800	[thread overview]
Message-ID: <490FFB56.7030300@cn.fujitsu.com> (raw)
In-Reply-To: <6599ad830811032240n640f3fao48f1a9f05892b797@mail.gmail.com>

With this change, the root cgroup is unfreezable, and writing to
its freezer.state returns -EIO.

I think it's reasonable to disallow freezing all the tasks in the
root cgroup. And this avoids fork overhead when freezer subsystem
is compiled but not used.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
 Documentation/cgroups/freezer-subsystem.txt |   18 ++++++++++--------
 kernel/cgroup_freezer.c                     |    7 +++++++
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Documentation/cgroups/freezer-subsystem.txt b/Documentation/cgroups/freezer-subsystem.txt
index c50ab58..e842bad 100644
--- a/Documentation/cgroups/freezer-subsystem.txt
+++ b/Documentation/cgroups/freezer-subsystem.txt
@@ -1,4 +1,4 @@
-	The cgroup freezer is useful to batch job management system which start
+The cgroup freezer is useful to batch job management system which start
 and stop sets of tasks in order to schedule the resources of a machine
 according to the desires of a system administrator. This sort of program
 is often used on HPC clusters to schedule access to the cluster as a
@@ -6,7 +6,7 @@ whole. The cgroup freezer uses cgroups to describe the set of tasks to
 be started/stopped by the batch job management system. It also provides
 a means to start and stop the tasks composing the job.
 
-	The cgroup freezer will also be useful for checkpointing running groups
+The cgroup freezer will also be useful for checkpointing running groups
 of tasks. The freezer allows the checkpoint code to obtain a consistent
 image of the tasks by attempting to force the tasks in a cgroup into a
 quiescent state. Once the tasks are quiescent another task can
@@ -16,7 +16,7 @@ recoverable error occur. This also allows the checkpointed tasks to be
 migrated between nodes in a cluster by copying the gathered information
 to another node and restarting the tasks there.
 
-	Sequences of SIGSTOP and SIGCONT are not always sufficient for stopping
+Sequences of SIGSTOP and SIGCONT are not always sufficient for stopping
 and resuming tasks in userspace. Both of these signals are observable
 from within the tasks we wish to freeze. While SIGSTOP cannot be caught,
 blocked, or ignored it can be seen by waiting or ptracing parent tasks.
@@ -37,26 +37,28 @@ demonstrate this problem using nested bash shells:
 
 	<at this point 16990 exits and causes 16644 to exit too>
 
-	This happens because bash can observe both signals and choose how it
+This happens because bash can observe both signals and choose how it
 responds to them.
 
-	Another example of a program which catches and responds to these
+Another example of a program which catches and responds to these
 signals is gdb. In fact any program designed to use ptrace is likely to
 have a problem with this method of stopping and resuming tasks.
 
-	 In contrast, the cgroup freezer uses the kernel freezer code to
+In contrast, the cgroup freezer uses the kernel freezer code to
 prevent the freeze/unfreeze cycle from becoming visible to the tasks
 being frozen. This allows the bash example above and gdb to run as
 expected.
 
-	The freezer subsystem in the container filesystem defines a file named
+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 "THAWED" will unfreeze the tasks in the cgroup.
 Reading will return the current state.
 
+Note it's not allowed to freeze the root cgroup.
+
 * Examples of usage :
 
-   # mkdir /containers/freezer
+   # mkdir /containers/
    # mount -t cgroup -ofreezer freezer  /containers
    # mkdir /containers/0
    # echo $some_pid > /containers/0/tasks
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 6605907..6b5c45d 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -192,6 +192,9 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
 	 */
 	freezer = task_freezer(task);
 
+	if (!freezer->css.cgroup->parent)
+		return;
+
 	spin_lock_irq(&freezer->lock);
 	BUG_ON(freezer->state == CGROUP_FROZEN);
 
@@ -330,6 +333,10 @@ static int freezer_write(struct cgroup *cgroup,
 	int retval;
 	enum freezer_state goal_state;
 
+	/* It's not allowed to freeze the root cgroup */
+	if (!cgroup->parent)
+		return -EIO;
+
 	if (strcmp(buffer, freezer_state_strs[CGROUP_THAWED]) == 0)
 		goal_state = CGROUP_THAWED;
 	else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0)
-- 
1.5.4.rc3

  parent reply	other threads:[~2008-11-04  7:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-11 23:53 [PATCH 0/5] Container Freezer v6: Reuse Suspend Freezer Matt Helsley
2008-08-11 23:53 ` [PATCH 1/5] Container Freezer: Add TIF_FREEZE flag to all architectures Matt Helsley
2008-08-11 23:53 ` [PATCH 2/5] Container Freezer: Make refrigerator always available Matt Helsley
2008-08-12 20:49   ` Rafael J. Wysocki
2008-08-13  1:01     ` [ProbableSpam]Re: " Matt Helsley
2008-08-13 14:31       ` Rafael J. Wysocki
2008-08-11 23:53 ` [PATCH 3/5] Container Freezer: Implement freezer cgroup subsystem Matt Helsley
2008-08-12 22:56   ` Andrew Morton
2008-08-13  2:38     ` Matt Helsley
2008-08-13 14:51       ` Rafael J. Wysocki
2008-11-04  5:43   ` Paul Menage
2008-11-04  6:12     ` Li Zefan
2008-11-04  6:40       ` Paul Menage
2008-11-04  7:25         ` Li Zefan
2008-11-04  7:35         ` Li Zefan [this message]
2008-11-04  7:56           ` [RFC][PATCH] freezer_cg: disable writing freezer.state of root cgroup Paul Menage
2008-11-04  8:01             ` Li Zefan
2008-11-05 10:18               ` Cedric Le Goater
2008-11-06  0:48               ` Paul Menage
2008-11-04  6:48       ` [PATCH] freezer_cg: remove task_lock from freezer_fork() Li Zefan
2008-08-11 23:53 ` [PATCH 4/5] Container Freezer: Skip frozen cgroups during power management resume Matt Helsley
2008-08-12 20:50   ` Rafael J. Wysocki
2008-08-11 23:53 ` [PATCH 5/5] Container Freezer: Prevent frozen tasks or cgroups from changing Matt Helsley
2008-08-12 22:44 ` [PATCH 0/5] Container Freezer v6: Reuse Suspend Freezer Andrew Morton
2008-08-13  3:47   ` [linux-pm] " Vivek Kashyap
2008-08-13  4:08     ` Andrew Morton
2008-08-15 21:54       ` Matt Helsley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=490FFB56.7030300@cn.fujitsu.com \
    --to=lizf@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=clg@fr.ibm.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=matthltc@us.ibm.com \
    --cc=menage@google.com \
    --cc=rjw@sisk.pl \
    --cc=serue@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox