Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63876986 authored by Tejun Heo's avatar Tejun Heo
Browse files

cgroup: add css_parent()



Currently, controllers have to explicitly follow the cgroup hierarchy
to find the parent of a given css.  cgroup is moving towards using
cgroup_subsys_state as the main controller interface construct, so
let's provide a way to climb the hierarchy using just csses.

This patch implements css_parent() which, given a css, returns its
parent.  The function is guarnateed to valid non-NULL parent css as
long as the target css is not at the top of the hierarchy.

freezer, cpuset, cpu, cpuacct, hugetlb, memory, net_cls and devices
are converted to use css_parent() instead of accessing cgroup->parent
directly.

* __parent_ca() is dropped from cpuacct and its usage is replaced with
  parent_ca().  The only difference between the two was NULL test on
  cgroup->parent which is now embedded in css_parent() making the
  distinction moot.  Note that eventually a css->parent field will be
  added to css and the NULL check in css_parent() will go away.

This patch shouldn't cause any behavior differences.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
parent a7c6d554
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -209,9 +209,7 @@ static inline struct blkcg *bio_blkcg(struct bio *bio)
 */
static inline struct blkcg *blkcg_parent(struct blkcg *blkcg)
{
	struct cgroup *pcg = blkcg->css.cgroup->parent;

	return pcg ? cgroup_to_blkcg(pcg) : NULL;
	return css_to_blkcg(css_parent(&blkcg->css));
}

/**
+15 −0
Original line number Diff line number Diff line
@@ -646,6 +646,21 @@ struct cgroup_subsys {
#undef IS_SUBSYS_ENABLED
#undef SUBSYS

/**
 * css_parent - find the parent css
 * @css: the target cgroup_subsys_state
 *
 * Return the parent css of @css.  This function is guaranteed to return
 * non-NULL parent as long as @css isn't the root.
 */
static inline
struct cgroup_subsys_state *css_parent(struct cgroup_subsys_state *css)
{
	struct cgroup *parent_cgrp = css->cgroup->parent;

	return parent_cgrp ? parent_cgrp->subsys[css->ss->subsys_id] : NULL;
}

/**
 * cgroup_css - obtain a cgroup's css for the specified subsystem
 * @cgrp: the cgroup of interest
+2 −6
Original line number Diff line number Diff line
@@ -62,11 +62,7 @@ static inline struct freezer *task_freezer(struct task_struct *task)

static struct freezer *parent_freezer(struct freezer *freezer)
{
	struct cgroup *pcg = freezer->css.cgroup->parent;

	if (pcg)
		return cgroup_freezer(pcg);
	return NULL;
	return css_freezer(css_parent(&freezer->css));
}

bool cgroup_freezing(struct task_struct *task)
@@ -234,7 +230,7 @@ static void freezer_fork(struct task_struct *task)
	 * The root cgroup is non-freezable, so we can skip the
	 * following check.
	 */
	if (!freezer->css.cgroup->parent)
	if (!parent_freezer(freezer))
		goto out;

	spin_lock_irq(&freezer->lock);
+1 −5
Original line number Diff line number Diff line
@@ -133,11 +133,7 @@ static inline struct cpuset *task_cs(struct task_struct *task)

static inline struct cpuset *parent_cs(struct cpuset *cs)
{
	struct cgroup *pcgrp = cs->css.cgroup->parent;

	if (pcgrp)
		return cgroup_cs(pcgrp);
	return NULL;
	return css_cs(css_parent(&cs->css));
}

#ifdef CONFIG_NUMA
+3 −6
Original line number Diff line number Diff line
@@ -7114,12 +7114,9 @@ static struct cgroup_subsys_state *cpu_cgroup_css_alloc(struct cgroup *cgrp)
static int cpu_cgroup_css_online(struct cgroup *cgrp)
{
	struct task_group *tg = cgroup_tg(cgrp);
	struct task_group *parent;
	struct task_group *parent = css_tg(css_parent(&tg->css));

	if (!cgrp->parent)
		return 0;

	parent = cgroup_tg(cgrp->parent);
	if (parent)
		sched_online_group(tg, parent);
	return 0;
}
Loading