Skip to content

Commit cd22cba

Browse files
committed
cgroup: Minor reorganization of cgroup_create()
cgroup_bpf init and exit handling will be moved to a notifier chain. In prepartion, reorganize cgroup_create() a bit so that the new cgroup is fully initialized before any outside changes are made. - cgrp->ancestors[] initialization and the hierarchical nr_descendants and nr_frozen_descendants updates were in the same loop. Separate them out and do the former earlier and do the latter later. - Relocate cgroup_bpf_inherit() call so that it's after all cgroup initializations are complete. No visible behavior changes expected. Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent d16e799 commit cd22cba

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

kernel/cgroup/cgroup.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5660,7 +5660,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
56605660
struct cgroup_root *root = parent->root;
56615661
struct cgroup *cgrp, *tcgrp;
56625662
struct kernfs_node *kn;
5663-
int level = parent->level + 1;
5663+
int i, level = parent->level + 1;
56645664
int ret;
56655665

56665666
/* allocate the cgroup and its ID, 0 is reserved for the root */
@@ -5700,11 +5700,8 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
57005700
if (ret)
57015701
goto out_stat_exit;
57025702

5703-
if (cgrp->root == &cgrp_dfl_root) {
5704-
ret = cgroup_bpf_inherit(cgrp);
5705-
if (ret)
5706-
goto out_psi_free;
5707-
}
5703+
for (tcgrp = cgrp; tcgrp; tcgrp = cgroup_parent(tcgrp))
5704+
cgrp->ancestors[tcgrp->level] = tcgrp;
57085705

57095706
/*
57105707
* New cgroup inherits effective freeze counter, and
@@ -5722,24 +5719,6 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
57225719
set_bit(CGRP_FROZEN, &cgrp->flags);
57235720
}
57245721

5725-
spin_lock_irq(&css_set_lock);
5726-
for (tcgrp = cgrp; tcgrp; tcgrp = cgroup_parent(tcgrp)) {
5727-
cgrp->ancestors[tcgrp->level] = tcgrp;
5728-
5729-
if (tcgrp != cgrp) {
5730-
tcgrp->nr_descendants++;
5731-
5732-
/*
5733-
* If the new cgroup is frozen, all ancestor cgroups
5734-
* get a new frozen descendant, but their state can't
5735-
* change because of this.
5736-
*/
5737-
if (cgrp->freezer.e_freeze)
5738-
tcgrp->freezer.nr_frozen_descendants++;
5739-
}
5740-
}
5741-
spin_unlock_irq(&css_set_lock);
5742-
57435722
if (notify_on_release(parent))
57445723
set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
57455724

@@ -5748,7 +5727,28 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
57485727

57495728
cgrp->self.serial_nr = css_serial_nr_next++;
57505729

5730+
if (cgrp->root == &cgrp_dfl_root) {
5731+
ret = cgroup_bpf_inherit(cgrp);
5732+
if (ret)
5733+
goto out_psi_free;
5734+
}
5735+
57515736
/* allocation complete, commit to creation */
5737+
spin_lock_irq(&css_set_lock);
5738+
for (i = 0; i < level; i++) {
5739+
tcgrp = cgrp->ancestors[i];
5740+
tcgrp->nr_descendants++;
5741+
5742+
/*
5743+
* If the new cgroup is frozen, all ancestor cgroups get a new
5744+
* frozen descendant, but their state can't change because of
5745+
* this.
5746+
*/
5747+
if (cgrp->freezer.e_freeze)
5748+
tcgrp->freezer.nr_frozen_descendants++;
5749+
}
5750+
spin_unlock_irq(&css_set_lock);
5751+
57525752
list_add_tail_rcu(&cgrp->self.sibling, &cgroup_parent(cgrp)->self.children);
57535753
atomic_inc(&root->nr_cgrps);
57545754
cgroup_get_live(parent);

0 commit comments

Comments
 (0)