Skip to contentSkip to conversation

cgroup: a u16 is enough for cgroup_subsys.depends_on

PATCH In review Wei Yang 2 participants 5 messages Oct 4, 2021 cgroup

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/4 cgroup: a u16 is enough for cgroup_subsys.depends_on

After commit 6e5c830770f9 ("cgroup: make cgroup subsystem masks u16"), we limit the number of subsystem to be less then 16. This applies to cgroup_subsys.depends_on too.

---
 include/linux/cgroup-defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/cgroup-defs.h +1 -1
index db2e147e069f..f6d80896daab 100644
@@ -705,7 +705,7 @@ struct cgroup_subsys {
 	 * not visible to userland until explicitly enabled.  The following
 	 * specifies the mask of subsystems that this one depends on.
 	 */
-	unsigned int depends_on;
+	u16 depends_on;
 };
 
 extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH 2/4 cgroup: reorder cgroup_subsys fields to save 8 byte

On 64bit platform, struct is aligned by 8 bytes by default.

By moving cgroup_subsys.depends_on, we fit these adjacent fields into 8 bytes alignment.

---
 include/linux/cgroup-defs.h | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
include/linux/cgroup-defs.h +9 -8
index f6d80896daab..4649d09396fd 100644
@@ -672,6 +672,15 @@ struct cgroup_subsys {
 	 */
 	bool threaded:1;
 
+	/*
+	 * A subsystem may depend on other subsystems.  When such subsystem
+	 * is enabled on a cgroup, the depended-upon subsystems are enabled
+	 * together if available.  Subsystems enabled due to dependency are
+	 * not visible to userland until explicitly enabled.  The following
+	 * specifies the mask of subsystems that this one depends on.
+	 */
+	u16 depends_on;
+
 	/* the following two fields are initialized automatically during boot */
 	int id;
 	const char *name;
@@ -698,14 +707,6 @@ struct cgroup_subsys {
 	struct cftype *dfl_cftypes;	/* for the default hierarchy */
 	struct cftype *legacy_cftypes;	/* for the legacy hierarchies */
 
-	/*
-	 * A subsystem may depend on other subsystems.  When such subsystem
-	 * is enabled on a cgroup, the depended-upon subsystems are enabled
-	 * together if available.  Subsystems enabled due to dependency are
-	 * not visible to userland until explicitly enabled.  The following
-	 * specifies the mask of subsystems that this one depends on.
-	 */
-	u16 depends_on;
 };
 
 extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;
Signature · 1 line
2.23.0
author
#2 lore raw

PATCH 3/4 cgroup: simplify the cgroup descendant helper

In reply to Wei Yang

cgroup_for_each_live_descendant_[pre|post] use cgroup_css() to get the root. While since the 2nd parameter is NULL, cgroup_css() always return cgrp->self.

Let's simplify this a little.

---
 kernel/cgroup/cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cgroup.c +2 -2
index 570b0c97392a..457353aeb0ca 100644
@@ -732,7 +732,7 @@ EXPORT_SYMBOL_GPL(of_css);
 
 /* walk live descendants in pre order */
 #define cgroup_for_each_live_descendant_pre(dsct, d_css, cgrp)		\
-	css_for_each_descendant_pre((d_css), cgroup_css((cgrp), NULL))	\
+	css_for_each_descendant_pre((d_css), &(cgrp)->self)		\
 		if (({ lockdep_assert_held(&cgroup_mutex);		\
 		       (dsct) = (d_css)->cgroup;			\
 		       cgroup_is_dead(dsct); }))			\
@@ -741,7 +741,7 @@ EXPORT_SYMBOL_GPL(of_css);
 
 /* walk live descendants in postorder */
 #define cgroup_for_each_live_descendant_post(dsct, d_css, cgrp)		\
-	css_for_each_descendant_post((d_css), cgroup_css((cgrp), NULL))	\
+	css_for_each_descendant_post((d_css), &(cgrp)->self)		\
 		if (({ lockdep_assert_held(&cgroup_mutex);		\
 		       (dsct) = (d_css)->cgroup;			\
 		       cgroup_is_dead(dsct); }))			\
Signature · 1 line
2.23.0
author
#3 lore raw

PATCH 4/4 cgroup: use parent directly instead of cgroup_parent()

In reply to Wei Yang

During cgroup_create(), we are sure who is our parent.

Let's use parent directly instead of fetch it from cgroup hierarchy.

---
 kernel/cgroup/cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup/cgroup.c +1 -1
index 457353aeb0ca..694b1c7803c2 100644
@@ -5368,7 +5368,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
 	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);
+	list_add_tail_rcu(&cgrp->self.sibling, &parent->self.children);
 	atomic_inc(&root->nr_cgrps);
 	cgroup_get_live(parent);
 
Signature · 1 line
2.23.0
maintainer
#4 lore raw
In reply to Wei Yang
Quoted 3 lines · Wei Yang

After commit 6e5c830770f9 ("cgroup: make cgroup subsystem masks u16"), we limit the number of subsystem to be less then 16. This applies to cgroup_subsys.depends_on too.

None of the patches seems meaningful enough. I'm gonna ignore this series.

Thanks.

Signature · 1 line
tejun