Skip to content

Commit 5c9d535

Browse files
committed
cgroup: remove css_parent()
cgroup in general is moving towards using cgroup_subsys_state as the fundamental structural component and css_parent() was introduced to convert from using cgroup->parent to css->parent. It was quite some time ago and we're moving forward with making css more prominent. This patch drops the trivial wrapper css_parent() and let the users dereference css->parent. While at it, explicitly mark fields of css which are public and immutable. v2: New usage from device_cgroup.c converted. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: "David S. Miller" <davem@davemloft.net> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Johannes Weiner <hannes@cmpxchg.org>
1 parent 3b514d2 commit 5c9d535

12 files changed

Lines changed: 34 additions & 41 deletions

File tree

‎block/blk-cgroup.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static inline struct blkcg *bio_blkcg(struct bio *bio)
204204
*/
205205
static inline struct blkcg *blkcg_parent(struct blkcg *blkcg)
206206
{
207-
return css_to_blkcg(css_parent(&blkcg->css));
207+
return css_to_blkcg(blkcg->css.parent);
208208
}
209209

210210
/**

‎include/linux/cgroup.h‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,28 @@ enum cgroup_subsys_id {
4848
};
4949
#undef SUBSYS
5050

51-
/* Per-subsystem/per-cgroup state maintained by the system. */
51+
/*
52+
* Per-subsystem/per-cgroup state maintained by the system. This is the
53+
* fundamental structural building block that controllers deal with.
54+
*
55+
* Fields marked with "PI:" are public and immutable and may be accessed
56+
* directly without synchronization.
57+
*/
5258
struct cgroup_subsys_state {
53-
/* the cgroup that this css is attached to */
59+
/* PI: the cgroup that this css is attached to */
5460
struct cgroup *cgroup;
5561

56-
/* the cgroup subsystem that this css is attached to */
62+
/* PI: the cgroup subsystem that this css is attached to */
5763
struct cgroup_subsys *ss;
5864

5965
/* reference count - access via css_[try]get() and css_put() */
6066
struct percpu_ref refcnt;
6167

62-
/* the parent css */
68+
/* PI: the parent css */
6369
struct cgroup_subsys_state *parent;
6470

6571
/*
66-
* Subsys-unique ID. 0 is unused and root is always 1. The
72+
* PI: Subsys-unique ID. 0 is unused and root is always 1. The
6773
* matching css can be looked up using css_from_id().
6874
*/
6975
int id;
@@ -669,19 +675,6 @@ struct cgroup_subsys {
669675
#include <linux/cgroup_subsys.h>
670676
#undef SUBSYS
671677

672-
/**
673-
* css_parent - find the parent css
674-
* @css: the target cgroup_subsys_state
675-
*
676-
* Return the parent css of @css. This function is guaranteed to return
677-
* non-NULL parent as long as @css isn't the root.
678-
*/
679-
static inline
680-
struct cgroup_subsys_state *css_parent(struct cgroup_subsys_state *css)
681-
{
682-
return css->parent;
683-
}
684-
685678
/**
686679
* task_css_set_check - obtain a task's css_set with extra access conditions
687680
* @task: the task to obtain css_set for

‎kernel/cgroup.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,10 +3176,10 @@ css_next_descendant_pre(struct cgroup_subsys_state *pos,
31763176

31773177
/* no child, visit my or the closest ancestor's next sibling */
31783178
while (pos != root) {
3179-
next = css_next_child(pos, css_parent(pos));
3179+
next = css_next_child(pos, pos->parent);
31803180
if (next)
31813181
return next;
3182-
pos = css_parent(pos);
3182+
pos = pos->parent;
31833183
}
31843184

31853185
return NULL;
@@ -3261,12 +3261,12 @@ css_next_descendant_post(struct cgroup_subsys_state *pos,
32613261
return NULL;
32623262

32633263
/* if there's an unvisited sibling, visit its leftmost descendant */
3264-
next = css_next_child(pos, css_parent(pos));
3264+
next = css_next_child(pos, pos->parent);
32653265
if (next)
32663266
return css_leftmost_descendant(next);
32673267

32683268
/* no sibling left, visit parent */
3269-
return css_parent(pos);
3269+
return pos->parent;
32703270
}
32713271

32723272
static bool cgroup_has_live_children(struct cgroup *cgrp)

‎kernel/cgroup_freezer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static inline struct freezer *task_freezer(struct task_struct *task)
5959

6060
static struct freezer *parent_freezer(struct freezer *freezer)
6161
{
62-
return css_freezer(css_parent(&freezer->css));
62+
return css_freezer(freezer->css.parent);
6363
}
6464

6565
bool cgroup_freezing(struct task_struct *task)

‎kernel/cpuset.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static inline struct cpuset *task_cs(struct task_struct *task)
124124

125125
static inline struct cpuset *parent_cs(struct cpuset *cs)
126126
{
127-
return css_cs(css_parent(&cs->css));
127+
return css_cs(cs->css.parent);
128128
}
129129

130130
#ifdef CONFIG_NUMA

‎kernel/sched/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7586,7 +7586,7 @@ cpu_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
75867586
static int cpu_cgroup_css_online(struct cgroup_subsys_state *css)
75877587
{
75887588
struct task_group *tg = css_tg(css);
7589-
struct task_group *parent = css_tg(css_parent(css));
7589+
struct task_group *parent = css_tg(css->parent);
75907590

75917591
if (parent)
75927592
sched_online_group(tg, parent);

‎kernel/sched/cpuacct.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static inline struct cpuacct *task_ca(struct task_struct *tsk)
4646

4747
static inline struct cpuacct *parent_ca(struct cpuacct *ca)
4848
{
49-
return css_ca(css_parent(&ca->css));
49+
return css_ca(ca->css.parent);
5050
}
5151

5252
static DEFINE_PER_CPU(u64, root_cpuacct_cpuusage);

‎mm/hugetlb_cgroup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static inline bool hugetlb_cgroup_is_root(struct hugetlb_cgroup *h_cg)
5252
static inline struct hugetlb_cgroup *
5353
parent_hugetlb_cgroup(struct hugetlb_cgroup *h_cg)
5454
{
55-
return hugetlb_cgroup_from_css(css_parent(&h_cg->css));
55+
return hugetlb_cgroup_from_css(h_cg->css.parent);
5656
}
5757

5858
static inline bool hugetlb_cgroup_have_usage(struct hugetlb_cgroup *h_cg)

‎mm/memcontrol.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
15401540
int mem_cgroup_swappiness(struct mem_cgroup *memcg)
15411541
{
15421542
/* root ? */
1543-
if (!css_parent(&memcg->css))
1543+
if (!memcg->css.parent)
15441544
return vm_swappiness;
15451545

15461546
return memcg->swappiness;
@@ -4909,7 +4909,7 @@ static int mem_cgroup_hierarchy_write(struct cgroup_subsys_state *css,
49094909
{
49104910
int retval = 0;
49114911
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
4912-
struct mem_cgroup *parent_memcg = mem_cgroup_from_css(css_parent(&memcg->css));
4912+
struct mem_cgroup *parent_memcg = mem_cgroup_from_css(memcg->css.parent);
49134913

49144914
mutex_lock(&memcg_create_mutex);
49154915

@@ -5207,8 +5207,8 @@ static void memcg_get_hierarchical_limit(struct mem_cgroup *memcg,
52075207
if (!memcg->use_hierarchy)
52085208
goto out;
52095209

5210-
while (css_parent(&memcg->css)) {
5211-
memcg = mem_cgroup_from_css(css_parent(&memcg->css));
5210+
while (memcg->css.parent) {
5211+
memcg = mem_cgroup_from_css(memcg->css.parent);
52125212
if (!memcg->use_hierarchy)
52135213
break;
52145214
tmp = res_counter_read_u64(&memcg->res, RES_LIMIT);
@@ -5443,7 +5443,7 @@ static int mem_cgroup_swappiness_write(struct cgroup_subsys_state *css,
54435443
struct cftype *cft, u64 val)
54445444
{
54455445
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5446-
struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css));
5446+
struct mem_cgroup *parent = mem_cgroup_from_css(memcg->css.parent);
54475447

54485448
if (val > 100 || !parent)
54495449
return -EINVAL;
@@ -5790,7 +5790,7 @@ static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css,
57905790
struct cftype *cft, u64 val)
57915791
{
57925792
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5793-
struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css));
5793+
struct mem_cgroup *parent = mem_cgroup_from_css(memcg->css.parent);
57945794

57955795
/* cannot set to root cgroup and only 0 and 1 are allowed */
57965796
if (!parent || !((val == 0) || (val == 1)))
@@ -6407,7 +6407,7 @@ static int
64076407
mem_cgroup_css_online(struct cgroup_subsys_state *css)
64086408
{
64096409
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
6410-
struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(css));
6410+
struct mem_cgroup *parent = mem_cgroup_from_css(css->parent);
64116411

64126412
if (css->id > MEM_CGROUP_ID_MAX)
64136413
return -ENOSPC;

‎net/core/netclassid_cgroup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ cgrp_css_alloc(struct cgroup_subsys_state *parent_css)
4242
static int cgrp_css_online(struct cgroup_subsys_state *css)
4343
{
4444
struct cgroup_cls_state *cs = css_cls_state(css);
45-
struct cgroup_cls_state *parent = css_cls_state(css_parent(css));
45+
struct cgroup_cls_state *parent = css_cls_state(css->parent);
4646

4747
if (parent)
4848
cs->classid = parent->classid;

0 commit comments

Comments
 (0)