Skip to content

Commit

Permalink
cgroup: move cgroup->serial_nr into cgroup_subsys_state
Browse files Browse the repository at this point in the history
We're moving towards using cgroup_subsys_states as the fundamental
structural blocks.  All csses including the cgroup->self and actual
ones now form trees through css->children and ->sibling which follow
the same rules as what cgroup->children and ->sibling followed.  This
patch moves cgroup->serial_nr which is used to implement css iteration
into css.

Note that all csses, regardless of their types, allocate their serial
numbers from the same monotonically increasing counter.  This doesn't
affect the ordering needed by css iteration or cause any other
material behavior changes.  This will be used to update css iteration.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
  • Loading branch information
Tejun Heo committed May 16, 2014
1 parent 1fed1b2 commit 0cb51d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
16 changes: 8 additions & 8 deletions include/linux/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ struct cgroup_subsys_state {

unsigned int flags;

/*
* Monotonically increasing unique serial number which defines a
* uniform order among all csses. It's guaranteed that all
* ->children lists are in the ascending order of ->serial_nr and
* used to allow interrupting and resuming iterations.
*/
u64 serial_nr;

/* percpu_ref killing and RCU release */
struct rcu_head rcu_head;
struct work_struct destroy_work;
Expand Down Expand Up @@ -178,14 +186,6 @@ struct cgroup {
struct kernfs_node *kn; /* cgroup kernfs entry */
struct kernfs_node *populated_kn; /* kn for "cgroup.subtree_populated" */

/*
* Monotonically increasing unique serial number which defines a
* uniform order among all cgroups. It's guaranteed that all
* ->children lists are in the ascending order of ->serial_nr.
* It's used to allow interrupting and resuming iterations.
*/
u64 serial_nr;

/* the bitmask of subsystems enabled on the child cgroups */
unsigned int child_subsys_mask;

Expand Down
20 changes: 11 additions & 9 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@ static int cgroup_root_count;
static DEFINE_IDR(cgroup_hierarchy_idr);

/*
* Assign a monotonically increasing serial number to cgroups. It
* guarantees cgroups with bigger numbers are newer than those with smaller
* numbers. Also, as cgroups are always appended to the parent's
* ->children list, it guarantees that sibling cgroups are always sorted in
* the ascending serial number order on the list. Protected by
* cgroup_mutex.
* Assign a monotonically increasing serial number to csses. It guarantees
* cgroups with bigger numbers are newer than those with smaller numbers.
* Also, as csses are always appended to the parent's ->children list, it
* guarantees that sibling csses are always sorted in the ascending serial
* number order on the list. Protected by cgroup_mutex.
*/
static u64 cgroup_serial_nr_next = 1;
static u64 css_serial_nr_next = 1;

/* This flag indicates whether tasks in the fork and exit paths should
* check for fork/exit handlers to call. This avoids us having to do
Expand Down Expand Up @@ -3133,7 +3132,7 @@ css_next_child(struct cgroup_subsys_state *pos_css,
next = list_entry_rcu(pos->self.sibling.next, struct cgroup, self.sibling);
} else {
list_for_each_entry_rcu(next, &cgrp->self.children, self.sibling)
if (next->serial_nr > pos->serial_nr)
if (next->self.serial_nr > pos->self.serial_nr)
break;
}

Expand Down Expand Up @@ -4168,13 +4167,16 @@ static void css_release(struct percpu_ref *ref)
static void init_and_link_css(struct cgroup_subsys_state *css,
struct cgroup_subsys *ss, struct cgroup *cgrp)
{
lockdep_assert_held(&cgroup_mutex);

cgroup_get(cgrp);

memset(css, 0, sizeof(*css));
css->cgroup = cgrp;
css->ss = ss;
INIT_LIST_HEAD(&css->sibling);
INIT_LIST_HEAD(&css->children);
css->serial_nr = css_serial_nr_next++;

if (cgroup_parent(cgrp)) {
css->parent = cgroup_css(cgroup_parent(cgrp), ss);
Expand Down Expand Up @@ -4348,7 +4350,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
*/
kernfs_get(kn);

cgrp->serial_nr = cgroup_serial_nr_next++;
cgrp->self.serial_nr = css_serial_nr_next++;

/* allocation complete, commit to creation */
list_add_tail_rcu(&cgrp->self.sibling, &cgroup_parent(cgrp)->self.children);
Expand Down

0 comments on commit 0cb51d7

Please sign in to comment.