2022-07-28 01:43:39

by Waiman Long

[permalink] [raw]
Subject: [PATCH 2/2] cgroup: Skip subtree root in cgroup_update_dfl_csses()

The cgroup_update_dfl_csses() function updates css associations when a
cgroup's subtree_control file is modified. Any changes made to a cgroup's
subtree_control file, however, will only affect its descendants but not
the cgroup itself. So there is no point in migrating csses associated
with that cgroup. We can skip them instead.

Signed-off-by: Waiman Long <[email protected]>
---
kernel/cgroup/cgroup.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 13c8e91d7862..1151ff44d578 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2960,6 +2960,15 @@ static int cgroup_update_dfl_csses(struct cgroup *cgrp)
cgroup_for_each_live_descendant_pre(dsct, d_css, cgrp) {
struct cgrp_cset_link *link;

+ /*
+ * As cgroup_update_dfl_csses() is only called by
+ * cgroup_apply_control(). The csses associated with the
+ * given cgrp will not be affected by changes made to
+ * its subtree_control file. We can skip them.
+ */
+ if (dsct == cgrp)
+ continue;
+
list_for_each_entry(link, &dsct->cset_links, cset_link)
cgroup_migrate_add_src(link->cset, dsct, &mgctx);
}
--
2.31.1


2022-07-28 14:54:28

by Michal Koutný

[permalink] [raw]
Subject: Re: [PATCH 2/2] cgroup: Skip subtree root in cgroup_update_dfl_csses()

On Wed, Jul 27, 2022 at 08:58:15PM -0400, Waiman Long <[email protected]> wrote:
> The cgroup_update_dfl_csses() function updates css associations when a
> cgroup's subtree_control file is modified. Any changes made to a cgroup's
> subtree_control file, however, will only affect its descendants but not
> the cgroup itself.

I find this correct.

> So there is no point in migrating csses associated with that cgroup.
> We can skip them instead.

Alone it's not such a big win but it componds with the recent Tejun's
threadgroup_rwsem elision.

> ---
> kernel/cgroup/cgroup.c | 9 +++++++++
> 1 file changed, 9 insertions(+)

Feel free to have
Reviewed-by: Michal Koutn? <[email protected]>

2022-07-28 14:55:00

by Waiman Long

[permalink] [raw]
Subject: Re: [PATCH 2/2] cgroup: Skip subtree root in cgroup_update_dfl_csses()


On 7/28/22 10:44, Michal Koutný wrote:
> On Wed, Jul 27, 2022 at 08:58:15PM -0400, Waiman Long <[email protected]> wrote:
>> The cgroup_update_dfl_csses() function updates css associations when a
>> cgroup's subtree_control file is modified. Any changes made to a cgroup's
>> subtree_control file, however, will only affect its descendants but not
>> the cgroup itself.
> I find this correct.
>
>> So there is no point in migrating csses associated with that cgroup.
>> We can skip them instead.
> Alone it's not such a big win but it componds with the recent Tejun's
> threadgroup_rwsem elision.
>
It is more an optimization patch trying to not waste cpu time doing
unnecessary work.
>> ---
>> kernel/cgroup/cgroup.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
> Feel free to have
> Reviewed-by: Michal Koutný <[email protected]>
>
Thanks for the review.

Cheers,
Longman

2022-07-28 17:37:00

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 2/2] cgroup: Skip subtree root in cgroup_update_dfl_csses()

On Thu, Jul 28, 2022 at 04:44:26PM +0200, Michal Koutn? wrote:
> On Wed, Jul 27, 2022 at 08:58:15PM -0400, Waiman Long <[email protected]> wrote:
> > The cgroup_update_dfl_csses() function updates css associations when a
> > cgroup's subtree_control file is modified. Any changes made to a cgroup's
> > subtree_control file, however, will only affect its descendants but not
> > the cgroup itself.
>
> I find this correct.
>
> > So there is no point in migrating csses associated with that cgroup.
> > We can skip them instead.
>
> Alone it's not such a big win but it componds with the recent Tejun's
> threadgroup_rwsem elision.

The chance is that if you're writing to a cgroup's subtree_control, that
cgroup is gonna be empty. The only case I can think of that this would make
a difference is w/ threaded cgroups, but it does make sense.

Thanks.

--
tejun

2022-07-28 18:21:59

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 2/2] cgroup: Skip subtree root in cgroup_update_dfl_csses()

On Wed, Jul 27, 2022 at 08:58:15PM -0400, Waiman Long wrote:
> The cgroup_update_dfl_csses() function updates css associations when a
> cgroup's subtree_control file is modified. Any changes made to a cgroup's
> subtree_control file, however, will only affect its descendants but not
> the cgroup itself. So there is no point in migrating csses associated
> with that cgroup. We can skip them instead.
>
> Signed-off-by: Waiman Long <[email protected]>

Applied to cgroup/for-5.20.

Thanks.

--
tejun