All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-20  7:47 ` haifeng.xu
  0 siblings, 0 replies; 13+ messages in thread
From: haifeng.xu @ 2022-10-20  7:47 UTC (permalink / raw)
  To: tj; +Cc: lizefan.x, hannes, cgroups, linux-kernel, haifeng.xu

Check the populated state of css_set in css_set_update_populated
and update the populated state of to_cset after from_cset is updated.

Signed-off-by: haifeng.xu <haifeng.xu@shopee.com>
---
 kernel/cgroup/cgroup.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index d922773fa90b..6c474be57f91 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -861,7 +861,8 @@ static void css_set_update_populated(struct css_set *cset, bool populated)
 {
 	struct cgrp_cset_link *link;
 
-	lockdep_assert_held(&css_set_lock);
+	if (!cset || css_set_populated(cset))
+		return;
 
 	list_for_each_entry(link, &cset->cgrp_links, cgrp_link)
 		cgroup_update_populated(link->cgrp, populated);
@@ -903,16 +904,12 @@ static void css_set_move_task(struct task_struct *task,
 {
 	lockdep_assert_held(&css_set_lock);
 
-	if (to_cset && !css_set_populated(to_cset))
-		css_set_update_populated(to_cset, true);
-
 	if (from_cset) {
 		WARN_ON_ONCE(list_empty(&task->cg_list));
 
 		css_set_skip_task_iters(from_cset, task);
 		list_del_init(&task->cg_list);
-		if (!css_set_populated(from_cset))
-			css_set_update_populated(from_cset, false);
+		css_set_update_populated(from_cset, false);
 	} else {
 		WARN_ON_ONCE(!list_empty(&task->cg_list));
 	}
@@ -926,6 +923,7 @@ static void css_set_move_task(struct task_struct *task,
 		WARN_ON_ONCE(task->flags & PF_EXITING);
 
 		cgroup_move_task(task, to_cset);
+		css_set_update_populated(to_cset, true);
 		list_add_tail(&task->cg_list, use_mg_tasks ? &to_cset->mg_tasks :
 							     &to_cset->tasks);
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-20  7:47 ` haifeng.xu
  0 siblings, 0 replies; 13+ messages in thread
From: haifeng.xu @ 2022-10-20  7:47 UTC (permalink / raw)
  To: tj-DgEjT+Ai2ygdnm+yROfE0A
  Cc: lizefan.x-EC8Uxl6Npydl57MIdRCFDg, hannes-druUgvl0LCNAfugRpC6u6w,
	cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, haifeng.xu

Check the populated state of css_set in css_set_update_populated
and update the populated state of to_cset after from_cset is updated.

Signed-off-by: haifeng.xu <haifeng.xu-LL2PKPoSiP3QT0dZR+AlfA@public.gmane.org>
---
 kernel/cgroup/cgroup.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index d922773fa90b..6c474be57f91 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -861,7 +861,8 @@ static void css_set_update_populated(struct css_set *cset, bool populated)
 {
 	struct cgrp_cset_link *link;
 
-	lockdep_assert_held(&css_set_lock);
+	if (!cset || css_set_populated(cset))
+		return;
 
 	list_for_each_entry(link, &cset->cgrp_links, cgrp_link)
 		cgroup_update_populated(link->cgrp, populated);
@@ -903,16 +904,12 @@ static void css_set_move_task(struct task_struct *task,
 {
 	lockdep_assert_held(&css_set_lock);
 
-	if (to_cset && !css_set_populated(to_cset))
-		css_set_update_populated(to_cset, true);
-
 	if (from_cset) {
 		WARN_ON_ONCE(list_empty(&task->cg_list));
 
 		css_set_skip_task_iters(from_cset, task);
 		list_del_init(&task->cg_list);
-		if (!css_set_populated(from_cset))
-			css_set_update_populated(from_cset, false);
+		css_set_update_populated(from_cset, false);
 	} else {
 		WARN_ON_ONCE(!list_empty(&task->cg_list));
 	}
@@ -926,6 +923,7 @@ static void css_set_move_task(struct task_struct *task,
 		WARN_ON_ONCE(task->flags & PF_EXITING);
 
 		cgroup_move_task(task, to_cset);
+		css_set_update_populated(to_cset, true);
 		list_add_tail(&task->cg_list, use_mg_tasks ? &to_cset->mg_tasks :
 							     &to_cset->tasks);
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-27  8:05   ` Michal Koutný
  0 siblings, 0 replies; 13+ messages in thread
From: Michal Koutný @ 2022-10-27  8:05 UTC (permalink / raw)
  To: haifeng.xu; +Cc: tj, lizefan.x, hannes, cgroups, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 468 bytes --]

Hello.

On Thu, Oct 20, 2022 at 07:47:01AM +0000, "haifeng.xu" <haifeng.xu@shopee.com> wrote:
> -	lockdep_assert_held(&css_set_lock);
> +	if (!cset || css_set_populated(cset))
> +		return;

1) the guard should be css_set_populated() ^ populated (when unsetting
the populated trait)

2) I'd keep the lockdep_assert_held() after it anyway.

Also the commit message should explain what's the reason to move
css_set_populated() after css_set_move_task().


Thanks,
Michal

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-27  8:05   ` Michal Koutný
  0 siblings, 0 replies; 13+ messages in thread
From: Michal Koutný @ 2022-10-27  8:05 UTC (permalink / raw)
  To: haifeng.xu
  Cc: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
	hannes-druUgvl0LCNAfugRpC6u6w, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

Hello.

On Thu, Oct 20, 2022 at 07:47:01AM +0000, "haifeng.xu" <haifeng.xu-LL2PKPoSiP3QT0dZR+AlfA@public.gmane.org> wrote:
> -	lockdep_assert_held(&css_set_lock);
> +	if (!cset || css_set_populated(cset))
> +		return;

1) the guard should be css_set_populated() ^ populated (when unsetting
the populated trait)

2) I'd keep the lockdep_assert_held() after it anyway.

Also the commit message should explain what's the reason to move
css_set_populated() after css_set_move_task().


Thanks,
Michal

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-28 11:29     ` Haifeng Xu
  0 siblings, 0 replies; 13+ messages in thread
From: Haifeng Xu @ 2022-10-28 11:29 UTC (permalink / raw)
  To: Michal Koutný; +Cc: tj, lizefan.x, hannes, cgroups, linux-kernel



On 2022/10/27 16:05, Michal Koutný wrote:
> Hello.
> 
> On Thu, Oct 20, 2022 at 07:47:01AM +0000, "haifeng.xu" <haifeng.xu@shopee.com> wrote:
>> -	lockdep_assert_held(&css_set_lock);
>> +	if (!cset || cset is either getting the first task or losing the last(cset))
>> +		return;
> 
> 1) the guard should be css_set_populated() ^ populated (when unsetting
> the populated trait)
> 
> 2) I'd keep the lockdep_assert_held() after it anyway.
> 
> Also the commit message should explain what's the reason to move
> css_set_populated() after css_set_move_task().
> 
> 
> Thanks,
> Michal
Hi, Michal.

1) If calls 'css_set_update_populated' , the cset is either getting the
first task or losing the last. There is a need to update the populated
state of the cset only when 'css_set_populated' returns false.
In other words, the last has been deleted from from_cset and the first
hasn't been added to to_cset yet.

2) Thanks for your suggestion. I'll keep 'lockdep_assert_held'.

3) In order to update the populated state of to_cset the same way
from_cset does, 'css_set_update_populated' is also invoked during the
process of moving a task to to_cset.

Thanks,
Haifeng

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-28 11:29     ` Haifeng Xu
  0 siblings, 0 replies; 13+ messages in thread
From: Haifeng Xu @ 2022-10-28 11:29 UTC (permalink / raw)
  To: Michal Koutný
  Cc: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
	hannes-druUgvl0LCNAfugRpC6u6w, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA



On 2022/10/27 16:05, Michal Koutný wrote:
> Hello.
> 
> On Thu, Oct 20, 2022 at 07:47:01AM +0000, "haifeng.xu" <haifeng.xu-LL2PKPoSiP3QT0dZR+AlfA@public.gmane.org> wrote:
>> -	lockdep_assert_held(&css_set_lock);
>> +	if (!cset || cset is either getting the first task or losing the last(cset))
>> +		return;
> 
> 1) the guard should be css_set_populated() ^ populated (when unsetting
> the populated trait)
> 
> 2) I'd keep the lockdep_assert_held() after it anyway.
> 
> Also the commit message should explain what's the reason to move
> css_set_populated() after css_set_move_task().
> 
> 
> Thanks,
> Michal
Hi, Michal.

1) If calls 'css_set_update_populated' , the cset is either getting the
first task or losing the last. There is a need to update the populated
state of the cset only when 'css_set_populated' returns false.
In other words, the last has been deleted from from_cset and the first
hasn't been added to to_cset yet.

2) Thanks for your suggestion. I'll keep 'lockdep_assert_held'.

3) In order to update the populated state of to_cset the same way
from_cset does, 'css_set_update_populated' is also invoked during the
process of moving a task to to_cset.

Thanks,
Haifeng

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-31 13:11       ` Michal Koutný
  0 siblings, 0 replies; 13+ messages in thread
From: Michal Koutný @ 2022-10-31 13:11 UTC (permalink / raw)
  To: Haifeng Xu; +Cc: tj, lizefan.x, hannes, cgroups, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]

Hello.

> 1) If calls 'css_set_update_populated' , the cset is either getting the
> first task or losing the last. There is a need to update the populated
> state of the cset only when 'css_set_populated' returns false.
> In other words, the last has been deleted from from_cset and the first
> hasn't been added to to_cset yet.

I've likely misread the condition previously. I see how this works now
(update happens after "from_cset" but before "to_cset" migration).

> 3) In order to update the populated state of to_cset the same way
> from_cset does, 'css_set_update_populated' is also invoked during the
> process of moving a task to to_cset.

As I think more about this in the context of vertical migrations
(ancestor<->descendant, such as during controller dis- or enablement),
I'm afraid the inverted order would lead to "spurious" emptiness
notifications in ancestors (in the case a there is just a single task
that migrates parent->child, parent/cgroup.populated would generate and
event that'd be nullified by the subsequent population of the child).

So I'm not sure the change is worth it.

Michal

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-10-31 13:11       ` Michal Koutný
  0 siblings, 0 replies; 13+ messages in thread
From: Michal Koutný @ 2022-10-31 13:11 UTC (permalink / raw)
  To: Haifeng Xu
  Cc: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
	hannes-druUgvl0LCNAfugRpC6u6w, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]

Hello.

> 1) If calls 'css_set_update_populated' , the cset is either getting the
> first task or losing the last. There is a need to update the populated
> state of the cset only when 'css_set_populated' returns false.
> In other words, the last has been deleted from from_cset and the first
> hasn't been added to to_cset yet.

I've likely misread the condition previously. I see how this works now
(update happens after "from_cset" but before "to_cset" migration).

> 3) In order to update the populated state of to_cset the same way
> from_cset does, 'css_set_update_populated' is also invoked during the
> process of moving a task to to_cset.

As I think more about this in the context of vertical migrations
(ancestor<->descendant, such as during controller dis- or enablement),
I'm afraid the inverted order would lead to "spurious" emptiness
notifications in ancestors (in the case a there is just a single task
that migrates parent->child, parent/cgroup.populated would generate and
event that'd be nullified by the subsequent population of the child).

So I'm not sure the change is worth it.

Michal

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-11-03  2:13         ` Haifeng Xu
  0 siblings, 0 replies; 13+ messages in thread
From: Haifeng Xu @ 2022-11-03  2:13 UTC (permalink / raw)
  To: Michal Koutný; +Cc: tj, lizefan.x, hannes, cgroups, linux-kernel



On 2022/10/31 21:11, Michal Koutný wrote:
> Hello.
> 
>> 1) If calls 'css_set_update_populated' , the cset is either getting the
>> first task or losing the last. There is a need to update the populated
>> state of the cset only when 'css_set_populated' returns false.
>> In other words, the last has been deleted from from_cset and the first
>> hasn't been added to to_cset yet.
> 
> I've likely misread the condition previously. I see how this works now
> (update happens after "from_cset" but before "to_cset" migration).
> 
>> 3) In order to update the populated state of to_cset the same way
>> from_cset does, 'css_set_update_populated' is also invoked during the
>> process of moving a task to to_cset.
> 
> As I think more about this in the context of vertical migrations
> (ancestor<->descendant, such as during controller dis- or enablement),
> I'm afraid the inverted order would lead to "spurious" emptiness
> notifications in ancestors (in the case a there is just a single task
> that migrates parent->child, parent/cgroup.populated would generate and
> event that'd be nullified by the subsequent population of the child).
Hi, Michal.

I understand your worries. Can I just check the populated state of
css_set in 'css_set_update_populated' and don't change the order any
more? I think it can also streamline 'css_set_move_task' a bit.

Thanks,
Hiafeng.
> 
> So I'm not sure the change is worth it.
> 
> Michal

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-11-03  2:13         ` Haifeng Xu
  0 siblings, 0 replies; 13+ messages in thread
From: Haifeng Xu @ 2022-11-03  2:13 UTC (permalink / raw)
  To: Michal Koutný
  Cc: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
	hannes-druUgvl0LCNAfugRpC6u6w, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA



On 2022/10/31 21:11, Michal Koutný wrote:
> Hello.
> 
>> 1) If calls 'css_set_update_populated' , the cset is either getting the
>> first task or losing the last. There is a need to update the populated
>> state of the cset only when 'css_set_populated' returns false.
>> In other words, the last has been deleted from from_cset and the first
>> hasn't been added to to_cset yet.
> 
> I've likely misread the condition previously. I see how this works now
> (update happens after "from_cset" but before "to_cset" migration).
> 
>> 3) In order to update the populated state of to_cset the same way
>> from_cset does, 'css_set_update_populated' is also invoked during the
>> process of moving a task to to_cset.
> 
> As I think more about this in the context of vertical migrations
> (ancestor<->descendant, such as during controller dis- or enablement),
> I'm afraid the inverted order would lead to "spurious" emptiness
> notifications in ancestors (in the case a there is just a single task
> that migrates parent->child, parent/cgroup.populated would generate and
> event that'd be nullified by the subsequent population of the child).
Hi, Michal.

I understand your worries. Can I just check the populated state of
css_set in 'css_set_update_populated' and don't change the order any
more? I think it can also streamline 'css_set_move_task' a bit.

Thanks,
Hiafeng.
> 
> So I'm not sure the change is worth it.
> 
> Michal

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-11-03  2:31           ` Tejun Heo
  0 siblings, 0 replies; 13+ messages in thread
From: Tejun Heo @ 2022-11-03  2:31 UTC (permalink / raw)
  To: Haifeng Xu; +Cc: Michal Koutný, lizefan.x, hannes, cgroups, linux-kernel

On Thu, Nov 03, 2022 at 10:13:22AM +0800, Haifeng Xu wrote:
> I understand your worries. Can I just check the populated state of
> css_set in 'css_set_update_populated' and don't change the order any
> more? I think it can also streamline 'css_set_move_task' a bit.

FWIW, I don't see much value in the proposed change. The resulting code
isn't better in any noticeable way. Even if the change were straightforward,
the value of the patch would seem questionable. There's no point in creating
code churns like this. Nothing is improved in any material way while
creating completely unnecessary risk for subtle breakages.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
@ 2022-11-03  2:31           ` Tejun Heo
  0 siblings, 0 replies; 13+ messages in thread
From: Tejun Heo @ 2022-11-03  2:31 UTC (permalink / raw)
  To: Haifeng Xu
  Cc: Michal Koutný,
	lizefan.x-EC8Uxl6Npydl57MIdRCFDg, hannes-druUgvl0LCNAfugRpC6u6w,
	cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Thu, Nov 03, 2022 at 10:13:22AM +0800, Haifeng Xu wrote:
> I understand your worries. Can I just check the populated state of
> css_set in 'css_set_update_populated' and don't change the order any
> more? I think it can also streamline 'css_set_move_task' a bit.

FWIW, I don't see much value in the proposed change. The resulting code
isn't better in any noticeable way. Even if the change were straightforward,
the value of the patch would seem questionable. There's no point in creating
code churns like this. Nothing is improved in any material way while
creating completely unnecessary risk for subtle breakages.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] cgroup: Simplify code in css_set_move_task
  2022-11-03  2:31           ` Tejun Heo
  (?)
@ 2022-11-03 14:55           ` Haifeng Xu
  -1 siblings, 0 replies; 13+ messages in thread
From: Haifeng Xu @ 2022-11-03 14:55 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Michal Koutný, lizefan.x, hannes, cgroups, linux-kernel



On 2022/11/3 10:31, Tejun Heo wrote:
> On Thu, Nov 03, 2022 at 10:13:22AM +0800, Haifeng Xu wrote:
>> I understand your worries. Can I just check the populated state of
>> css_set in 'css_set_update_populated' and don't change the order any
>> more? I think it can also streamline 'css_set_move_task' a bit.
> 
> FWIW, I don't see much value in the proposed change. The resulting code
> isn't better in any noticeable way. Even if the change were straightforward,
> the value of the patch would seem questionable. There's no point in creating
> code churns like this. Nothing is improved in any material way while
> creating completely unnecessary risk for subtle breakages.
> 
> Thanks.
> 
Got it, thanks.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-11-03 14:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-20  7:47 [PATCH] cgroup: Simplify code in css_set_move_task haifeng.xu
2022-10-20  7:47 ` haifeng.xu
2022-10-27  8:05 ` Michal Koutný
2022-10-27  8:05   ` Michal Koutný
2022-10-28 11:29   ` Haifeng Xu
2022-10-28 11:29     ` Haifeng Xu
2022-10-31 13:11     ` Michal Koutný
2022-10-31 13:11       ` Michal Koutný
2022-11-03  2:13       ` Haifeng Xu
2022-11-03  2:13         ` Haifeng Xu
2022-11-03  2:31         ` Tejun Heo
2022-11-03  2:31           ` Tejun Heo
2022-11-03 14:55           ` Haifeng Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.