Skip to content

Commit

Permalink
cpuset: introduce ->css_on/offline()
Browse files Browse the repository at this point in the history
Add cpuset_css_on/offline() and rearrange css init/exit such that,

* Allocation and clearing to the default values happen in css_alloc().
  Allocation now uses kzalloc().

* Config inheritance and registration happen in css_online().

* css_offline() undoes what css_online() did.

* css_free() frees.

This doesn't introduce any visible behavior changes.  This will help
cleaning up locking.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
  • Loading branch information
Tejun Heo committed Jan 7, 2013
1 parent 0772324 commit c8f699b
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions kernel/cpuset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1790,38 +1790,47 @@ static struct cftype files[] = {

static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cont)
{
struct cgroup *parent_cg = cont->parent;
struct cgroup *tmp_cg;
struct cpuset *parent, *cs;
struct cpuset *cs;

if (!parent_cg)
if (!cont->parent)
return &top_cpuset.css;
parent = cgroup_cs(parent_cg);

cs = kmalloc(sizeof(*cs), GFP_KERNEL);
cs = kzalloc(sizeof(*cs), GFP_KERNEL);
if (!cs)
return ERR_PTR(-ENOMEM);
if (!alloc_cpumask_var(&cs->cpus_allowed, GFP_KERNEL)) {
kfree(cs);
return ERR_PTR(-ENOMEM);
}

cs->flags = 0;
if (is_spread_page(parent))
set_bit(CS_SPREAD_PAGE, &cs->flags);
if (is_spread_slab(parent))
set_bit(CS_SPREAD_SLAB, &cs->flags);
set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
cpumask_clear(cs->cpus_allowed);
nodes_clear(cs->mems_allowed);
fmeter_init(&cs->fmeter);
cs->relax_domain_level = -1;
cs->parent = cgroup_cs(cont->parent);

return &cs->css;
}

static int cpuset_css_online(struct cgroup *cgrp)
{
struct cpuset *cs = cgroup_cs(cgrp);
struct cpuset *parent = cs->parent;
struct cgroup *tmp_cg;

if (!parent)
return 0;

if (is_spread_page(parent))
set_bit(CS_SPREAD_PAGE, &cs->flags);
if (is_spread_slab(parent))
set_bit(CS_SPREAD_SLAB, &cs->flags);

cs->parent = parent;
number_of_cpusets++;

if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &cont->flags))
goto skip_clone;
if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags))
return 0;

/*
* Clone @parent's configuration if CGRP_CPUSET_CLONE_CHILDREN is
Expand All @@ -1836,19 +1845,34 @@ static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cont)
* changed to grant parent->cpus_allowed-sibling_cpus_exclusive
* (and likewise for mems) to the new cgroup.
*/
list_for_each_entry(tmp_cg, &parent_cg->children, sibling) {
list_for_each_entry(tmp_cg, &cgrp->parent->children, sibling) {
struct cpuset *tmp_cs = cgroup_cs(tmp_cg);

if (is_mem_exclusive(tmp_cs) || is_cpu_exclusive(tmp_cs))
goto skip_clone;
return 0;
}

mutex_lock(&callback_mutex);
cs->mems_allowed = parent->mems_allowed;
cpumask_copy(cs->cpus_allowed, parent->cpus_allowed);
mutex_unlock(&callback_mutex);
skip_clone:
return &cs->css;

return 0;
}

static void cpuset_css_offline(struct cgroup *cgrp)
{
struct cpuset *cs = cgroup_cs(cgrp);

/* css_offline is called w/o cgroup_mutex, grab it */
cgroup_lock();

if (is_sched_load_balance(cs))
update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);

number_of_cpusets--;

cgroup_unlock();
}

/*
Expand All @@ -1861,17 +1885,15 @@ static void cpuset_css_free(struct cgroup *cont)
{
struct cpuset *cs = cgroup_cs(cont);

if (is_sched_load_balance(cs))
update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);

number_of_cpusets--;
free_cpumask_var(cs->cpus_allowed);
kfree(cs);
}

struct cgroup_subsys cpuset_subsys = {
.name = "cpuset",
.css_alloc = cpuset_css_alloc,
.css_online = cpuset_css_online,
.css_offline = cpuset_css_offline,
.css_free = cpuset_css_free,
.can_attach = cpuset_can_attach,
.attach = cpuset_attach,
Expand Down

0 comments on commit c8f699b

Please sign in to comment.