2021-10-04 08:51:19

by Wei Yang

[permalink] [raw]
Subject: [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.

Signed-off-by: Wei Yang <[email protected]>
---
include/linux/cgroup-defs.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index db2e147e069f..f6d80896daab 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -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;
--
2.23.0


2021-10-04 08:51:24

by Wei Yang

[permalink] [raw]
Subject: [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.

Signed-off-by: Wei Yang <[email protected]>
---
include/linux/cgroup-defs.h | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index f6d80896daab..4649d09396fd 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -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;
--
2.23.0

2021-10-04 08:54:44

by Wei Yang

[permalink] [raw]
Subject: [PATCH 4/4] cgroup: use parent directly instead of cgroup_parent()

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

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

Signed-off-by: Wei Yang <[email protected]>
---
kernel/cgroup/cgroup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 457353aeb0ca..694b1c7803c2 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -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);

--
2.23.0

2021-10-04 10:22:40

by Wei Yang

[permalink] [raw]
Subject: [PATCH 3/4] cgroup: simplify the cgroup descendant helper

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.

Signed-off-by: Wei Yang <[email protected]>
---
kernel/cgroup/cgroup.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 570b0c97392a..457353aeb0ca 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -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); })) \
--
2.23.0

2021-10-05 00:11:06

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 1/4] cgroup: a u16 is enough for cgroup_subsys.depends_on

On Mon, Oct 04, 2021 at 08:49:25AM +0000, Wei Yang wrote:
> 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.

--
tejun