Skip to content

Commit

Permalink
cgroup: add cgroup_subsys->free() method and use it to fix pids contr…
Browse files Browse the repository at this point in the history
…oller

pids controller is completely broken in that it uncharges when a task
exits allowing zombies to escape resource control.  With the recent
updates, cgroup core now maintains cgroup association till task free
and pids controller can be fixed by uncharging on free instead of
exit.

This patch adds cgroup_subsys->free() method and update pids
controller to use it instead of ->exit() for uncharging.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Aleksa Sarai <cyphar@cyphar.com>
  • Loading branch information
htejun committed Oct 15, 2015
1 parent 2e91fa7 commit afcf6c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Documentation/cgroups/cgroups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ void exit(struct task_struct *task)

Called during task exit.

void free(struct task_struct *task)

Called when the task_struct is freed.

void bind(struct cgroup *root)
(cgroup_mutex held by caller)

Expand Down
1 change: 1 addition & 0 deletions include/linux/cgroup-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ struct cgroup_subsys {
void (*cancel_fork)(struct task_struct *task, void *priv);
void (*fork)(struct task_struct *task, void *priv);
void (*exit)(struct task_struct *task);
void (*free)(struct task_struct *task);
void (*bind)(struct cgroup_subsys_state *root_css);

int early_init;
Expand Down
7 changes: 7 additions & 0 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ static u64 css_serial_nr_next = 1;
*/
static unsigned long have_fork_callback __read_mostly;
static unsigned long have_exit_callback __read_mostly;
static unsigned long have_free_callback __read_mostly;

/* Ditto for the can_fork callback. */
static unsigned long have_canfork_callback __read_mostly;
Expand Down Expand Up @@ -5180,6 +5181,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)

have_fork_callback |= (bool)ss->fork << ss->id;
have_exit_callback |= (bool)ss->exit << ss->id;
have_free_callback |= (bool)ss->free << ss->id;
have_canfork_callback |= (bool)ss->can_fork << ss->id;

/* At system boot, before all subsystems have been
Expand Down Expand Up @@ -5637,6 +5639,11 @@ void cgroup_exit(struct task_struct *tsk)
void cgroup_free(struct task_struct *task)
{
struct css_set *cset = task_css_set(task);
struct cgroup_subsys *ss;
int ssid;

for_each_subsys_which(ss, ssid, &have_free_callback)
ss->free(task);

put_css_set(cset);
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/cgroup_pids.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static void pids_fork(struct task_struct *task, void *priv)
css_put(old_css);
}

static void pids_exit(struct task_struct *task)
static void pids_free(struct task_struct *task)
{
struct pids_cgroup *pids = css_pids(task_css(task, pids_cgrp_id));

Expand Down Expand Up @@ -347,7 +347,7 @@ struct cgroup_subsys pids_cgrp_subsys = {
.can_fork = pids_can_fork,
.cancel_fork = pids_cancel_fork,
.fork = pids_fork,
.exit = pids_exit,
.free = pids_free,
.legacy_cftypes = pids_files,
.dfl_cftypes = pids_files,
};

0 comments on commit afcf6c8

Please sign in to comment.