All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Paul Menage <paul@paulmenage.org>, Li Zefan <lizf@cn.fujitsu.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Aditya Kali <adityakali@google.com>,
	Oleg Nesterov <oleg@redhat.com>,
	Kay Sievers <kay.sievers@vrfy.org>,
	Tim Hockin <thockin@hockin.org>, Tejun Heo <tj@kernel.org>,
	Containers <containers@lists.linux-foundation.org>
Subject: Re: [PATCH 09/10] cgroups: Allow subsystems to cancel a fork
Date: Tue, 4 Oct 2011 04:38:59 +0300	[thread overview]
Message-ID: <20111004013859.GC7361@shutemov.name> (raw)
In-Reply-To: <1317668832-10784-10-git-send-email-fweisbec@gmail.com>

On Mon, Oct 03, 2011 at 09:07:11PM +0200, Frederic Weisbecker wrote:
> Let the subsystem's fork callback return an error value so
> that they can cancel a fork. This is going to be used by
> the task counter subsystem to implement the limit.
> 
> Suggested-by: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Acked-by: Kirill A. Shutemov <kirill@shutemov.name>

> Cc: Paul Menage <paul@paulmenage.org>
> Cc: Li Zefan <lizf@cn.fujitsu.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Aditya Kali <adityakali@google.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kay Sievers <kay.sievers@vrfy.org>
> Cc: Tim Hockin <thockin@hockin.org>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Kirill A. Shutemov <kirill@shutemov.name>
> Cc: Containers <containers@lists.linux-foundation.org>
> ---
>  include/linux/cgroup.h  |   20 ++++++++++++++------
>  kernel/cgroup.c         |   23 +++++++++++++++++++----
>  kernel/cgroup_freezer.c |    6 ++++--
>  kernel/exit.c           |    2 +-
>  kernel/fork.c           |    7 +++++--
>  5 files changed, 43 insertions(+), 15 deletions(-)
> 
> diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
> index b62cf5e..9c8151e 100644
> --- a/include/linux/cgroup.h
> +++ b/include/linux/cgroup.h
> @@ -17,10 +17,11 @@
>  #include <linux/rwsem.h>
>  #include <linux/idr.h>
>  
> +struct cgroup_subsys;
> +
>  #ifdef CONFIG_CGROUPS
>  
>  struct cgroupfs_root;
> -struct cgroup_subsys;
>  struct inode;
>  struct cgroup;
>  struct css_id;
> @@ -32,9 +33,11 @@ extern int cgroup_lock_is_held(void);
>  extern bool cgroup_lock_live_group(struct cgroup *cgrp);
>  extern void cgroup_unlock(void);
>  extern void cgroup_fork(struct task_struct *p);
> -extern void cgroup_fork_callbacks(struct task_struct *p);
> +extern int cgroup_fork_callbacks(struct task_struct *p,
> +				 struct cgroup_subsys **failed_ss);
>  extern void cgroup_post_fork(struct task_struct *p);
> -extern void cgroup_exit(struct task_struct *p, int run_callbacks);
> +extern void cgroup_exit(struct task_struct *p, int run_callbacks,
> +			struct cgroup_subsys *failed_ss);
>  extern int cgroupstats_build(struct cgroupstats *stats,
>  				struct dentry *dentry);
>  extern int cgroup_load_subsys(struct cgroup_subsys *ss);
> @@ -479,7 +482,7 @@ struct cgroup_subsys {
>  			    struct task_struct *tsk);
>  	void (*attach)(struct cgroup_subsys *ss, struct cgroup *cgrp,
>  		       struct cgroup *old_cgrp, struct task_struct *tsk);
> -	void (*fork)(struct cgroup_subsys *ss, struct task_struct *task);
> +	int (*fork)(struct cgroup_subsys *ss, struct task_struct *task);
>  	void (*exit)(struct cgroup_subsys *ss, struct cgroup *cgrp,
>  			struct cgroup *old_cgrp, struct task_struct *task);
>  	int (*populate)(struct cgroup_subsys *ss,
> @@ -636,9 +639,14 @@ struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id);
>  static inline int cgroup_init_early(void) { return 0; }
>  static inline int cgroup_init(void) { return 0; }
>  static inline void cgroup_fork(struct task_struct *p) {}
> -static inline void cgroup_fork_callbacks(struct task_struct *p) {}
> +static inline int cgroup_fork_callbacks(struct task_struct *p,
> +					struct cgroup_subsys **failed_ss)
> +{
> +	return 0;
> +}
>  static inline void cgroup_post_fork(struct task_struct *p) {}
> -static inline void cgroup_exit(struct task_struct *p, int callbacks) {}
> +static inline void cgroup_exit(struct task_struct *p, int callbacks,
> +			       struct cgroup_subsys *failed_ss) {}
>  
>  static inline void cgroup_lock(void) {}
>  static inline void cgroup_unlock(void) {}
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index 709baef..018df9d 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -4540,8 +4540,11 @@ void cgroup_fork(struct task_struct *child)
>   * tasklist. No need to take any locks since no-one can
>   * be operating on this task.
>   */
> -void cgroup_fork_callbacks(struct task_struct *child)
> +int cgroup_fork_callbacks(struct task_struct *child,
> +			  struct cgroup_subsys **failed_ss)
>  {
> +	int err;
> +
>  	if (need_forkexit_callback) {
>  		int i;
>  		/*
> @@ -4551,10 +4554,17 @@ void cgroup_fork_callbacks(struct task_struct *child)
>  		 */
>  		for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) {
>  			struct cgroup_subsys *ss = subsys[i];
> -			if (ss->fork)
> -				ss->fork(ss, child);
> +			if (ss->fork) {
> +				err = ss->fork(ss, child);
> +				if (err) {
> +					*failed_ss = ss;
> +					return err;
> +				}
> +			}
>  		}
>  	}
> +
> +	return 0;
>  }
>  
>  /**
> @@ -4612,7 +4622,8 @@ void cgroup_post_fork(struct task_struct *child)
>   *    which wards off any cgroup_attach_task() attempts, or task is a failed
>   *    fork, never visible to cgroup_attach_task.
>   */
> -void cgroup_exit(struct task_struct *tsk, int run_callbacks)
> +void cgroup_exit(struct task_struct *tsk, int run_callbacks,
> +		 struct cgroup_subsys *failed_ss)
>  {
>  	struct css_set *cg;
>  	int i;
> @@ -4641,6 +4652,10 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks)
>  		 */
>  		for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) {
>  			struct cgroup_subsys *ss = subsys[i];
> +
> +			if (ss == failed_ss)
> +				break;
> +
>  			if (ss->exit) {
>  				struct cgroup *old_cgrp =
>  					rcu_dereference_raw(cg->subsys[i])->cgroup;
> diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
> index c1421a1..30a4332 100644
> --- a/kernel/cgroup_freezer.c
> +++ b/kernel/cgroup_freezer.c
> @@ -187,7 +187,7 @@ static int freezer_can_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
>  	return 0;
>  }
>  
> -static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
> +static int freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
>  {
>  	struct freezer *freezer;
>  
> @@ -207,7 +207,7 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
>  	 * following check.
>  	 */
>  	if (!freezer->css.cgroup->parent)
> -		return;
> +		return 0;
>  
>  	spin_lock_irq(&freezer->lock);
>  	BUG_ON(freezer->state == CGROUP_FROZEN);
> @@ -216,6 +216,8 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
>  	if (freezer->state == CGROUP_FREEZING)
>  		freeze_task(task, true);
>  	spin_unlock_irq(&freezer->lock);
> +
> +	return 0;
>  }
>  
>  /*
> diff --git a/kernel/exit.c b/kernel/exit.c
> index 2913b35..abab32b 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -994,7 +994,7 @@ NORET_TYPE void do_exit(long code)
>  	 */
>  	perf_event_exit_task(tsk);
>  
> -	cgroup_exit(tsk, 1);
> +	cgroup_exit(tsk, 1, NULL);
>  
>  	if (group_dead)
>  		disassociate_ctty(1);
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 8e6b6f4..ee8abdb 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1058,6 +1058,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
>  	int retval;
>  	struct task_struct *p;
>  	int cgroup_callbacks_done = 0;
> +	struct cgroup_subsys *cgroup_failed_ss = NULL;
>  
>  	if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
>  		return ERR_PTR(-EINVAL);
> @@ -1312,8 +1313,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,
>  	/* Now that the task is set up, run cgroup callbacks if
>  	 * necessary. We need to run them before the task is visible
>  	 * on the tasklist. */
> -	cgroup_fork_callbacks(p);
> +	retval = cgroup_fork_callbacks(p, &cgroup_failed_ss);
>  	cgroup_callbacks_done = 1;
> +	if (retval)
> +		goto bad_fork_free_pid;
>  
>  	/* Need tasklist lock for parent etc handling! */
>  	write_lock_irq(&tasklist_lock);
> @@ -1419,7 +1422,7 @@ bad_fork_cleanup_cgroup:
>  #endif
>  	if (clone_flags & CLONE_THREAD)
>  		threadgroup_fork_read_unlock(current);
> -	cgroup_exit(p, cgroup_callbacks_done);
> +	cgroup_exit(p, cgroup_callbacks_done, cgroup_failed_ss);
>  	delayacct_tsk_free(p);
>  	module_put(task_thread_info(p)->exec_domain->module);
>  bad_fork_cleanup_count:
> -- 
> 1.7.5.4
> 

-- 
 Kirill A. Shutemov

  reply	other threads:[~2011-10-04  1:39 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-03 19:07 [PATCH 00/10] cgroups: Task counter subsystem v6 Frederic Weisbecker
2011-10-03 19:07 ` [PATCH 01/10] cgroups: Add res_counter_write_u64() API Frederic Weisbecker
2011-10-04  0:17   ` Kirill A. Shutemov
2011-10-11 13:44     ` Frederic Weisbecker
2011-10-03 19:07 ` [PATCH 02/10] cgroups: New resource counter inheritance API Frederic Weisbecker
2011-10-04  0:20   ` Kirill A. Shutemov
2011-10-03 19:07 ` [PATCH 03/10] cgroups: Add previous cgroup in can_attach_task/attach_task callbacks Frederic Weisbecker
2011-10-04  0:22   ` Kirill A. Shutemov
2011-10-03 19:07 ` [PATCH 04/10] cgroups: New cancel_attach_task subsystem callback Frederic Weisbecker
2011-10-04  0:27   ` Kirill A. Shutemov
2011-10-03 19:07 ` [PATCH 05/10] cgroups: Ability to stop res charge propagation on bounded ancestor Frederic Weisbecker
2011-10-04  0:41   ` Kirill A. Shutemov
2011-10-03 19:07 ` [PATCH 06/10] cgroups: Add res counter common ancestor searching Frederic Weisbecker
2011-10-03 19:07 ` [PATCH 07/10] res_counter: Allow charge failure pointer to be null Frederic Weisbecker
2011-10-04  1:30   ` Kirill A. Shutemov
2011-10-03 19:07 ` [PATCH 08/10] cgroups: Pull up res counter charge failure interpretation to caller Frederic Weisbecker
2011-10-04  1:32   ` Kirill A. Shutemov
2011-10-03 19:07 ` [PATCH 09/10] cgroups: Allow subsystems to cancel a fork Frederic Weisbecker
2011-10-04  1:38   ` Kirill A. Shutemov [this message]
2011-10-03 19:07 ` [PATCH 10/10] cgroups: Add a task counter subsystem Frederic Weisbecker
2011-10-06  9:23   ` Kirill A. Shutemov
2011-10-11 13:41     ` Frederic Weisbecker
2011-10-04 22:01 ` [PATCH 00/10] cgroups: Task counter subsystem v6 Andrew Morton
2011-10-11 13:40   ` Frederic Weisbecker
2011-10-25 20:06   ` Tim Hockin
     [not found]     ` <CAAAKZwu67VMiZgdpp=i5p7zyGbOHGHXwF_iprufGPzTLkkUF2A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-10-28 23:30       ` Andrew Morton
2011-10-28 23:30         ` Andrew Morton
     [not found]         ` <20111028163021.1ce61f8a.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2011-10-29  9:38           ` Glauber Costa
2011-10-29  9:38             ` Glauber Costa
     [not found]             ` <CAA6-i6o0SPfZJDx4SRR1hY-He0L6zHuv0saH6EaE7Mrc2HF6PA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-03 16:49               ` Frederic Weisbecker
2011-11-03 16:49                 ` Frederic Weisbecker
     [not found]                 ` <20111103164917.GF8198-oHC15RC7JGTpAmv0O++HtFaTQe2KTcn/@public.gmane.org>
2011-11-03 16:58                   ` Glauber Costa
2011-11-03 16:58                     ` Glauber Costa
     [not found]                     ` <4EB2C852.6020706-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-11-03 17:02                       ` Paul Menage
2011-11-03 17:02                         ` Paul Menage
     [not found]                         ` <CALdu-PDY8zpXYM3V9KRk4f2NyGevfNnuaWVdoT-qzSHOK--K3A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-03 17:06                           ` Glauber Costa
2011-11-03 17:06                             ` Glauber Costa
     [not found]                             ` <4EB2CA03.7030601-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-11-03 17:28                               ` Paul Menage
2011-11-03 17:28                                 ` Paul Menage
     [not found]                                 ` <CALdu-PA2CDoeUMoNd1y44p_QzphX8J4s6NDcSyVC-rP1HGYwkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-03 17:35                                   ` Glauber Costa
2011-11-03 17:35                                     ` Glauber Costa
     [not found]                                     ` <4EB2D0F2.40309-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-11-03 17:56                                       ` Paul Menage
2011-11-03 17:56                                         ` Paul Menage
     [not found]                                         ` <CALdu-PDbJ69FayXSd-kjAMX8AKEroZytPapxsUn8GFsz-z1omQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-04 13:17                                           ` Glauber Costa
2011-11-04 13:17                                         ` Glauber Costa
2011-11-03 17:00           ` Frederic Weisbecker
2011-11-03 17:00             ` Frederic Weisbecker
     [not found]             ` <20111103170038.GG8198-oHC15RC7JGTpAmv0O++HtFaTQe2KTcn/@public.gmane.org>
2011-11-04  2:57               ` Li Zefan
2011-11-04  2:57                 ` Li Zefan
2011-11-04 12:37                 ` Frederic Weisbecker
     [not found]                 ` <4EB3549D.5090404-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2011-11-04 12:37                   ` Frederic Weisbecker
2011-10-06  6:51 ` Li Zefan
2011-10-11 13:41   ` Frederic Weisbecker
     [not found] ` <1317668832-10784-1-git-send-email-fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-12-13 15:58   ` Tejun Heo
2011-12-13 15:58     ` Tejun Heo
     [not found]     ` <20111213155848.GI25802-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2011-12-13 19:06       ` Frederic Weisbecker
2011-12-13 19:06         ` Frederic Weisbecker
     [not found]         ` <20111213190642.GB2421-oHC15RC7JGTpAmv0O++HtFaTQe2KTcn/@public.gmane.org>
2011-12-13 20:49           ` Tejun Heo
2011-12-13 20:49             ` Tejun Heo
     [not found]             ` <20111213204918.GK25802-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2011-12-14 15:07               ` Frederic Weisbecker
2011-12-14 15:07                 ` Frederic Weisbecker

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=20111004013859.GC7361@shutemov.name \
    --to=kirill@shutemov.name \
    --cc=adityakali@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=oleg@redhat.com \
    --cc=paul@paulmenage.org \
    --cc=thockin@hockin.org \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.