Skip to content

Commit f5f60d2

Browse files
RichardWeiYanghtejun
authored andcommitted
cgroup/rstat: check updated_next only for root
After commit dc26532 ("cgroup: rstat: punt root-level optimization to individual controllers"), each rstat on updated_children list has its ->updated_next not NULL. This means we can remove the check on ->updated_next, if we make sure the subtree from @root is on list, which could be done by checking updated_next for root. tj: Coding style fixes. Signed-off-by: Wei Yang <[email protected]> Reviewed-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 0da41f7 commit f5f60d2

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

kernel/cgroup/rstat.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
8888
struct cgroup *root, int cpu)
8989
{
9090
struct cgroup_rstat_cpu *rstatc;
91+
struct cgroup *parent;
9192

9293
if (pos == root)
9394
return NULL;
@@ -96,10 +97,14 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
9697
* We're gonna walk down to the first leaf and visit/remove it. We
9798
* can pick whatever unvisited node as the starting point.
9899
*/
99-
if (!pos)
100+
if (!pos) {
100101
pos = root;
101-
else
102+
/* return NULL if this subtree is not on-list */
103+
if (!cgroup_rstat_cpu(pos, cpu)->updated_next)
104+
return NULL;
105+
} else {
102106
pos = cgroup_parent(pos);
107+
}
103108

104109
/* walk down to the first leaf */
105110
while (true) {
@@ -115,31 +120,25 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
115120
* However, due to the way we traverse, @pos will be the first
116121
* child in most cases. The only exception is @root.
117122
*/
118-
if (rstatc->updated_next) {
119-
struct cgroup *parent = cgroup_parent(pos);
120-
121-
if (parent) {
122-
struct cgroup_rstat_cpu *prstatc;
123-
struct cgroup **nextp;
124-
125-
prstatc = cgroup_rstat_cpu(parent, cpu);
126-
nextp = &prstatc->updated_children;
127-
while (*nextp != pos) {
128-
struct cgroup_rstat_cpu *nrstatc;
129-
130-
nrstatc = cgroup_rstat_cpu(*nextp, cpu);
131-
WARN_ON_ONCE(*nextp == parent);
132-
nextp = &nrstatc->updated_next;
133-
}
134-
*nextp = rstatc->updated_next;
135-
}
123+
parent = cgroup_parent(pos);
124+
if (parent) {
125+
struct cgroup_rstat_cpu *prstatc;
126+
struct cgroup **nextp;
136127

137-
rstatc->updated_next = NULL;
138-
return pos;
128+
prstatc = cgroup_rstat_cpu(parent, cpu);
129+
nextp = &prstatc->updated_children;
130+
while (*nextp != pos) {
131+
struct cgroup_rstat_cpu *nrstatc;
132+
133+
nrstatc = cgroup_rstat_cpu(*nextp, cpu);
134+
WARN_ON_ONCE(*nextp == parent);
135+
nextp = &nrstatc->updated_next;
136+
}
137+
*nextp = rstatc->updated_next;
139138
}
140139

141-
/* only happens for @root */
142-
return NULL;
140+
rstatc->updated_next = NULL;
141+
return pos;
143142
}
144143

145144
/* see cgroup_rstat_flush() */

0 commit comments

Comments
 (0)