public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cedric Le Goater <clg@fr.ibm.com>
To: Matt Helsley <matthltc@us.ibm.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>,
	Andrew Morton <akpm@linux-foundation.org>,
	Paul Menage <menage@google.com>, Li Zefan <lizf@cn.fujitsu.com>,
	Linux-Kernel <linux-kernel@vger.kernel.org>,
	Linux Containers <containers@lists.linux-foundation.org>,
	linux-pm@lists.linux-foundation.org,
	"Serge E. Hallyn" <serue@us.ibm.com>
Subject: Re: [PATCH 3/6] Container Freezer: Implement freezer cgroup subsystem
Date: Sat, 02 Aug 2008 09:38:55 +0200	[thread overview]
Message-ID: <48940F0F.4050604@fr.ibm.com> (raw)
In-Reply-To: <1217635891.25300.292.camel@localhost.localdomain>

Matt Helsley wrote:
> On Sat, 2008-08-02 at 00:58 +0200, Rafael J. Wysocki wrote:
>> On Friday, 1 of August 2008, Matt Helsley wrote:
>>> 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.
>>>
>>> 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>
>>> ---
>>>  include/linux/cgroup_freezer.h |   71 ++++++++
>>>  include/linux/cgroup_subsys.h  |    6 
>>>  include/linux/freezer.h        |   16 +-
>>>  init/Kconfig                   |    7 
>>>  kernel/Makefile                |    1 
>>>  kernel/cgroup_freezer.c        |  328 +++++++++++++++++++++++++++++++++++++++++
>>>  6 files changed, 425 insertions(+), 4 deletions(-)
>>>  create mode 100644 include/linux/cgroup_freezer.h
>>>  create mode 100644 kernel/cgroup_freezer.c
>>>
>>> Index: linux-2.6.27-rc1-mm1/include/linux/cgroup_freezer.h
>>> ===================================================================
>>> --- /dev/null
>>> +++ linux-2.6.27-rc1-mm1/include/linux/cgroup_freezer.h
>>> @@ -0,0 +1,71 @@
>>> +#ifndef _LINUX_CGROUP_FREEZER_H
>>> +#define _LINUX_CGROUP_FREEZER_H
>>> +/*
>>> + * cgroup_freezer.h -  control group freezer subsystem interface
>>> + *
>>> + * Copyright IBM Corporation, 2007
>>> + *
>>> + * Author : Cedric Le Goater <clg@fr.ibm.com>
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify it
>>> + * under the terms of version 2.1 of the GNU Lesser General Public License
>>> + * as published by the Free Software Foundation.
>>> + *
>>> + * This program is distributed in the hope that it would be useful, but
>>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>>> + */
>>> +
>>> +#include <linux/cgroup.h>
>>> +
>>> +#ifdef CONFIG_CGROUP_FREEZER
>>> +
>>> +enum freezer_state {
>>> +	STATE_RUNNING = 0,
>>> +	STATE_FREEZING,
>>> +	STATE_FROZEN,
>>> +};
>>> +
>>> +struct freezer {
>>> +	struct cgroup_subsys_state css;
>>> +	enum freezer_state state;
>>> +	spinlock_t lock; /* protects _writes_ to state */
>>> +};
>>> +
>>> +static inline struct freezer *cgroup_freezer(
>>> +		struct cgroup *cgroup)
>>> +{
>>> +	return container_of(
>>> +		cgroup_subsys_state(cgroup, freezer_subsys_id),
>>> +		struct freezer, css);
>>> +}
>>> +
>>> +static inline struct freezer *task_freezer(struct task_struct *task)
>>> +{
>>> +	return container_of(task_subsys_state(task, freezer_subsys_id),
>>> +			    struct freezer, css);
>>> +}
>>> +
>>> +static inline int cgroup_frozen(struct task_struct *task)
>>> +{
>>> +	struct freezer *freezer;
>>> +	enum freezer_state state;
>>> +
>>> +	task_lock(task);
>>> +	freezer = task_freezer(task);
>>> +	state = freezer->state;
>>> +	task_unlock(task);
>>> +
>>> +	return state == STATE_FROZEN;
>>> +}
>>> +
>>> +#else /* !CONFIG_CGROUP_FREEZER */
>>> +
>>> +static inline int cgroup_frozen(struct task_struct *task)
>>> +{
>>> +	return 0;
>>> +}
>>> +
>>> +#endif /* !CONFIG_CGROUP_FREEZER */
>>> +
>>> +#endif /* _LINUX_CGROUP_FREEZER_H */
>> Hmm.  I wonder if we really need a separate file for this.  I'd prefer it to be
>> in freezer.h, unless there's a good reason not to place it in there.
> 
> 	Yeah, it's a pretty small header so combining it with another header
> would be nice. However if we combine it with freezer.h we'd be including
> cgroup.h in unrelated filesystem code. An alternative might be to put it
> into a cgroup header for "small" subsystems (which might just be
> cgroup.h for now..).
> 
> Thanks for the review!

I'm not sure the inline is really useful. In that case, we could probably do 
something like the following : 

include/linux/freezer.h :

	#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 */

and in kernel/cgroup_freezer.c:

	int cgroup_frozen(struct task_struct *task)
	{
		struct freezer *freezer;
		enum freezer_state state;

		task_lock(task);
		freezer = task_freezer(task);
		state = freezer->state;
		task_unlock(task);

		return state == STATE_FROZEN;
	}

and kill include/linux/cgroup_freezer.h ? 

Thanks Matt,

C.




  reply	other threads:[~2008-08-02  7:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-01  5:06 [PATCH 0/6] Container Freezer: Reuse Suspend Freezer Matt Helsley
2008-08-01  5:07 ` [PATCH 1/6] Container Freezer: Add TIF_FREEZE flag to all architectures Matt Helsley
2008-08-01 10:32   ` Nigel Cunningham
2008-08-01 12:32     ` Cedric Le Goater
2008-08-01 22:05       ` Matt Helsley
2008-08-01 22:54         ` Rafael J. Wysocki
2008-08-02  1:13         ` Nigel Cunningham
2008-08-01  5:07 ` [PATCH 2/6] Container Freezer: Make refrigerator always available Matt Helsley
2008-08-01 10:33   ` Nigel Cunningham
2008-08-01 14:27   ` Thomas Petazzoni
2008-08-01 19:08     ` Matt Helsley
2008-08-01 22:53       ` Rafael J. Wysocki
2008-08-01 23:24         ` Matt Helsley
2008-08-02 14:34           ` Rafael J. Wysocki
2008-08-02  2:30         ` Matt Helsley
2008-08-02 10:39       ` Thomas Petazzoni
2008-08-01  5:07 ` [PATCH 3/6] Container Freezer: Implement freezer cgroup subsystem Matt Helsley
2008-08-01 22:58   ` Rafael J. Wysocki
2008-08-02  0:11     ` Matt Helsley
2008-08-02  7:38       ` Cedric Le Goater [this message]
2008-08-02 14:37         ` Rafael J. Wysocki
2008-08-01  5:07 ` [PATCH 4/6] Container Freezer: Skip frozen cgroups during power management resume Matt Helsley
2008-08-01 10:24   ` Nigel Cunningham
2008-08-01  5:07 ` [PATCH 5/6] Container Freezer: Prevent frozen tasks or cgroups from changing Matt Helsley
2008-08-01  5:07 ` [PATCH 6/6] Container Freezer: Use cgroup write_string method Matt Helsley
2008-08-01  5:16 ` [PATCH 0/6] Container Freezer: Reuse Suspend Freezer Matt Helsley
2008-08-01 13:04   ` Rafael J. Wysocki

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=48940F0F.4050604@fr.ibm.com \
    --to=clg@fr.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=lizf@cn.fujitsu.com \
    --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