forked from Minki/linux
Merge branch 'for-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup updates from Tejun Heo: "Nothing too exciting. - updates to the pids controller so that pid limit breaches can be noticed and monitored from userland. - cleanups and non-critical bug fixes" * 'for-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup: remove duplicated include from cgroup.c cgroup: Use lld instead of ld when printing pids controller events_limit cgroup: Add pids controller event when fork fails because of pid limit cgroup: allow NULL return from ss->css_alloc() cgroup: remove unnecessary 0 check from css_from_id() cgroup: fix idr leak for the first cgroup root
This commit is contained in:
commit
b55b048718
@ -61,7 +61,6 @@
|
||||
#include <linux/cpuset.h>
|
||||
#include <linux/proc_ns.h>
|
||||
#include <linux/nsproxy.h>
|
||||
#include <linux/proc_ns.h>
|
||||
#include <net/sock.h>
|
||||
|
||||
/*
|
||||
@ -1160,18 +1159,12 @@ static void cgroup_exit_root_id(struct cgroup_root *root)
|
||||
{
|
||||
lockdep_assert_held(&cgroup_mutex);
|
||||
|
||||
if (root->hierarchy_id) {
|
||||
idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
|
||||
root->hierarchy_id = 0;
|
||||
}
|
||||
idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
|
||||
}
|
||||
|
||||
static void cgroup_free_root(struct cgroup_root *root)
|
||||
{
|
||||
if (root) {
|
||||
/* hierarchy ID should already have been released */
|
||||
WARN_ON_ONCE(root->hierarchy_id);
|
||||
|
||||
idr_destroy(&root->cgroup_idr);
|
||||
kfree(root);
|
||||
}
|
||||
@ -5146,6 +5139,8 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp,
|
||||
lockdep_assert_held(&cgroup_mutex);
|
||||
|
||||
css = ss->css_alloc(parent_css);
|
||||
if (!css)
|
||||
css = ERR_PTR(-ENOMEM);
|
||||
if (IS_ERR(css))
|
||||
return css;
|
||||
|
||||
@ -6172,7 +6167,7 @@ struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
|
||||
struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss)
|
||||
{
|
||||
WARN_ON_ONCE(!rcu_read_lock_held());
|
||||
return id > 0 ? idr_find(&ss->css_idr, id) : NULL;
|
||||
return idr_find(&ss->css_idr, id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,6 +49,12 @@ struct pids_cgroup {
|
||||
*/
|
||||
atomic64_t counter;
|
||||
int64_t limit;
|
||||
|
||||
/* Handle for "pids.events" */
|
||||
struct cgroup_file events_file;
|
||||
|
||||
/* Number of times fork failed because limit was hit. */
|
||||
atomic64_t events_limit;
|
||||
};
|
||||
|
||||
static struct pids_cgroup *css_pids(struct cgroup_subsys_state *css)
|
||||
@ -72,6 +78,7 @@ pids_css_alloc(struct cgroup_subsys_state *parent)
|
||||
|
||||
pids->limit = PIDS_MAX;
|
||||
atomic64_set(&pids->counter, 0);
|
||||
atomic64_set(&pids->events_limit, 0);
|
||||
return &pids->css;
|
||||
}
|
||||
|
||||
@ -213,10 +220,21 @@ static int pids_can_fork(struct task_struct *task)
|
||||
{
|
||||
struct cgroup_subsys_state *css;
|
||||
struct pids_cgroup *pids;
|
||||
int err;
|
||||
|
||||
css = task_css_check(current, pids_cgrp_id, true);
|
||||
pids = css_pids(css);
|
||||
return pids_try_charge(pids, 1);
|
||||
err = pids_try_charge(pids, 1);
|
||||
if (err) {
|
||||
/* Only log the first time events_limit is incremented. */
|
||||
if (atomic64_inc_return(&pids->events_limit) == 1) {
|
||||
pr_info("cgroup: fork rejected by pids controller in ");
|
||||
pr_cont_cgroup_path(task_cgroup(current, pids_cgrp_id));
|
||||
pr_cont("\n");
|
||||
}
|
||||
cgroup_file_notify(&pids->events_file);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static void pids_cancel_fork(struct task_struct *task)
|
||||
@ -288,6 +306,14 @@ static s64 pids_current_read(struct cgroup_subsys_state *css,
|
||||
return atomic64_read(&pids->counter);
|
||||
}
|
||||
|
||||
static int pids_events_show(struct seq_file *sf, void *v)
|
||||
{
|
||||
struct pids_cgroup *pids = css_pids(seq_css(sf));
|
||||
|
||||
seq_printf(sf, "max %lld\n", (s64)atomic64_read(&pids->events_limit));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct cftype pids_files[] = {
|
||||
{
|
||||
.name = "max",
|
||||
@ -300,6 +326,12 @@ static struct cftype pids_files[] = {
|
||||
.read_s64 = pids_current_read,
|
||||
.flags = CFTYPE_NOT_ON_ROOT,
|
||||
},
|
||||
{
|
||||
.name = "events",
|
||||
.seq_show = pids_events_show,
|
||||
.file_offset = offsetof(struct pids_cgroup, events_file),
|
||||
.flags = CFTYPE_NOT_ON_ROOT,
|
||||
},
|
||||
{ } /* terminate */
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user