mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] freezer, sched: report the frozen task stat as 'D'
@ 2024-11-11 13:54 Chen Ridong
  2024-11-13 14:34 ` Valentin Schneider
  0 siblings, 1 reply; 10+ messages in thread
From: Chen Ridong @ 2024-11-11 13:54 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid
  Cc: linux-kernel, chenridong, wangweiyang2

From: Chen Ridong <chenridong@huawei.com>

Before the commit f5d39b020809 ("freezer,sched: Rewrite core freezer
logic"), the frozen task stat was reported as 'D' in cgroup v1.
However, after rewriting core freezer logic, the frozen task stat is
reported as 'R'. This is confusing, especially when a task with stat of
'S' is frozen.

This can be reproduced as bellow step:
cd /sys/fs/cgroup/freezer/
mkdir test
sleep 1000 &
[1] 739         // task whose stat is 'S'
echo 739 > test/cgroup.procs
echo FROZEN > test/freezer.state
ps -aux | grep 739
root     739  0.1  0.0   8376  1812 pts/0    R    10:56   0:00 sleep 1000

As shown above, a task whose stat is 'S' was changed to 'R' when it was
frozen. To solve this issue, simply maintain the same reported state as
before the rewrite.

Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 include/linux/sched.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index f0f23efdb245..878acce2f8d6 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1630,8 +1630,9 @@ static inline unsigned int __task_state_index(unsigned int tsk_state,
 	 * We're lying here, but rather than expose a completely new task state
 	 * to userspace, we can make this appear as if the task has gone through
 	 * a regular rt_mutex_lock() call.
+	 * Report the frozen task uninterruptible.
 	 */
-	if (tsk_state & TASK_RTLOCK_WAIT)
+	if (tsk_state & TASK_RTLOCK_WAIT || tsk_state & TASK_FROZEN)
 		state = TASK_UNINTERRUPTIBLE;
 
 	return fls(state);
-- 
2.34.1


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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-11-11 13:54 [PATCH] freezer, sched: report the frozen task stat as 'D' Chen Ridong
@ 2024-11-13 14:34 ` Valentin Schneider
  2024-11-14  7:47   ` Chen Ridong
  0 siblings, 1 reply; 10+ messages in thread
From: Valentin Schneider @ 2024-11-13 14:34 UTC (permalink / raw)
  To: Chen Ridong, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman
  Cc: linux-kernel, chenridong, wangweiyang2

On 11/11/24 13:54, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> Before the commit f5d39b020809 ("freezer,sched: Rewrite core freezer
> logic"), the frozen task stat was reported as 'D' in cgroup v1.
> However, after rewriting core freezer logic, the frozen task stat is
> reported as 'R'. This is confusing, especially when a task with stat of
> 'S' is frozen.
>
> This can be reproduced as bellow step:
> cd /sys/fs/cgroup/freezer/
> mkdir test
> sleep 1000 &
> [1] 739         // task whose stat is 'S'
> echo 739 > test/cgroup.procs
> echo FROZEN > test/freezer.state
> ps -aux | grep 739
> root     739  0.1  0.0   8376  1812 pts/0    R    10:56   0:00 sleep 1000
>
> As shown above, a task whose stat is 'S' was changed to 'R' when it was
> frozen. To solve this issue, simply maintain the same reported state as
> before the rewrite.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
>  include/linux/sched.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index f0f23efdb245..878acce2f8d6 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1630,8 +1630,9 @@ static inline unsigned int __task_state_index(unsigned int tsk_state,
>  	 * We're lying here, but rather than expose a completely new task state
>  	 * to userspace, we can make this appear as if the task has gone through
>  	 * a regular rt_mutex_lock() call.
> +	 * Report the frozen task uninterruptible.
>  	 */
> -	if (tsk_state & TASK_RTLOCK_WAIT)
> +	if (tsk_state & TASK_RTLOCK_WAIT || tsk_state & TASK_FROZEN)

Hmph, for RTLOCK this was good enough since !PREEMPT_RT really would be
TASK_UNINTERRUPTIBLE. 

For the freezer AFAICT there's more variation, following your example:

  crash> task -R __state,saved_state 195
  PID: 195      TASK: ffff888004abab80  CPU: 1    COMMAND: "sh"
    __state = 32768    -> 0x8000 aka TASK_FROZEN
    saved_state = 8193 -> 0x2001 aka TASK_INTERRUPTIBLE | TASK_FREEZABLE

so we ought to read ->saved_state, but as pointed out in [1] this is
racy...

[1]: https://lore.kernel.org/lkml/20220120162520.570782-3-valentin.schneider@arm.com/

>  		state = TASK_UNINTERRUPTIBLE;
>  
>  	return fls(state);
> -- 
> 2.34.1


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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-11-13 14:34 ` Valentin Schneider
@ 2024-11-14  7:47   ` Chen Ridong
  2024-11-14 16:44     ` Tejun Heo
  0 siblings, 1 reply; 10+ messages in thread
From: Chen Ridong @ 2024-11-14  7:47 UTC (permalink / raw)
  To: Valentin Schneider, Chen Ridong, mingo, peterz, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	Tejun Heo, mkoutny@suse.com >> Michal Koutný
  Cc: linux-kernel, wangweiyang2, cgroups



On 2024/11/13 22:34, Valentin Schneider wrote:
> On 11/11/24 13:54, Chen Ridong wrote:
>> From: Chen Ridong <chenridong@huawei.com>
>>
>> Before the commit f5d39b020809 ("freezer,sched: Rewrite core freezer
>> logic"), the frozen task stat was reported as 'D' in cgroup v1.
>> However, after rewriting core freezer logic, the frozen task stat is
>> reported as 'R'. This is confusing, especially when a task with stat of
>> 'S' is frozen.
>>
>> This can be reproduced as bellow step:
>> cd /sys/fs/cgroup/freezer/
>> mkdir test
>> sleep 1000 &
>> [1] 739         // task whose stat is 'S'
>> echo 739 > test/cgroup.procs
>> echo FROZEN > test/freezer.state
>> ps -aux | grep 739
>> root     739  0.1  0.0   8376  1812 pts/0    R    10:56   0:00 sleep 1000
>>
>> As shown above, a task whose stat is 'S' was changed to 'R' when it was
>> frozen. To solve this issue, simply maintain the same reported state as
>> before the rewrite.
>>
>> Signed-off-by: Chen Ridong <chenridong@huawei.com>
>> ---
>>  include/linux/sched.h | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/sched.h b/include/linux/sched.h
>> index f0f23efdb245..878acce2f8d6 100644
>> --- a/include/linux/sched.h
>> +++ b/include/linux/sched.h
>> @@ -1630,8 +1630,9 @@ static inline unsigned int __task_state_index(unsigned int tsk_state,
>>  	 * We're lying here, but rather than expose a completely new task state
>>  	 * to userspace, we can make this appear as if the task has gone through
>>  	 * a regular rt_mutex_lock() call.
>> +	 * Report the frozen task uninterruptible.
>>  	 */
>> -	if (tsk_state & TASK_RTLOCK_WAIT)
>> +	if (tsk_state & TASK_RTLOCK_WAIT || tsk_state & TASK_FROZEN)
> 
> Hmph, for RTLOCK this was good enough since !PREEMPT_RT really would be
> TASK_UNINTERRUPTIBLE. 
> 
> For the freezer AFAICT there's more variation, following your example:
> 

Thank you for your reply.
I tried to freeze a task whose stat is 'R', the saved_state is variable.

crash> task -R __state,saved_state 821
PID: 821    TASK: ffff888101df8000  CPU: 6   COMMAND: "test.sh"
  __state = 32768,
  saved_state = 0,

However, if a task is frozen, it will be better to show same stat in
case of confusion. In cgroup v2, it is shown as 'S'. In cgroup v1, the
prior stat shown was 'D'. Therefore, it might be a good choice to
maintain the same reported state as before the rewrite.

Or does anyone have a better idea?

Best regards,
Ridong

>   crash> task -R __state,saved_state 195
>   PID: 195      TASK: ffff888004abab80  CPU: 1    COMMAND: "sh"
>     __state = 32768    -> 0x8000 aka TASK_FROZEN
>     saved_state = 8193 -> 0x2001 aka TASK_INTERRUPTIBLE | TASK_FREEZABLE
> 
> so we ought to read ->saved_state, but as pointed out in [1] this is
> racy...
> 
> [1]: https://lore.kernel.org/lkml/20220120162520.570782-3-valentin.schneider@arm.com/
> 
>>  		state = TASK_UNINTERRUPTIBLE;
>>  
>>  	return fls(state);
>> -- 
>> 2.34.1
> 
> 


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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-11-14  7:47   ` Chen Ridong
@ 2024-11-14 16:44     ` Tejun Heo
  2024-11-15  1:14       ` Chen Ridong
  0 siblings, 1 reply; 10+ messages in thread
From: Tejun Heo @ 2024-11-14 16:44 UTC (permalink / raw)
  To: Chen Ridong
  Cc: Valentin Schneider, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman,
	mkoutny@suse.com >> Michal Koutný,
	linux-kernel, wangweiyang2, cgroups

Hello,

On Thu, Nov 14, 2024 at 03:47:58PM +0800, Chen Ridong wrote:
> On 2024/11/13 22:34, Valentin Schneider wrote:
> > On 11/11/24 13:54, Chen Ridong wrote:
> >> From: Chen Ridong <chenridong@huawei.com>
> >>
> >> Before the commit f5d39b020809 ("freezer,sched: Rewrite core freezer
> >> logic"), the frozen task stat was reported as 'D' in cgroup v1.
> >> However, after rewriting core freezer logic, the frozen task stat is
> >> reported as 'R'. This is confusing, especially when a task with stat of
> >> 'S' is frozen.
> >>
> >> This can be reproduced as bellow step:
> >> cd /sys/fs/cgroup/freezer/
> >> mkdir test
> >> sleep 1000 &
> >> [1] 739         // task whose stat is 'S'
> >> echo 739 > test/cgroup.procs
> >> echo FROZEN > test/freezer.state
> >> ps -aux | grep 739
> >> root     739  0.1  0.0   8376  1812 pts/0    R    10:56   0:00 sleep 1000
> >>
> >> As shown above, a task whose stat is 'S' was changed to 'R' when it was
> >> frozen. To solve this issue, simply maintain the same reported state as
> >> before the rewrite.

The whole point of the freezer rewrite was preventing userspace from causing
arbitrary and indefinite D states which leads to all sorts of problems. The
tasks in cgroup2 freezer are *not* in uninterruptible sleeps. They are in
task stop loops and thus can be killed, ptraced and so on. It *should*
report S.

Thanks.

-- 
tejun

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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-11-14 16:44     ` Tejun Heo
@ 2024-11-15  1:14       ` Chen Ridong
  2024-11-15  1:28         ` Tejun Heo
  0 siblings, 1 reply; 10+ messages in thread
From: Chen Ridong @ 2024-11-15  1:14 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Valentin Schneider, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman,
	mkoutny@suse.com >> Michal Koutný,
	linux-kernel, wangweiyang2, cgroups



On 2024/11/15 0:44, Tejun Heo wrote:
> Hello,
> 
> On Thu, Nov 14, 2024 at 03:47:58PM +0800, Chen Ridong wrote:
>> On 2024/11/13 22:34, Valentin Schneider wrote:
>>> On 11/11/24 13:54, Chen Ridong wrote:
>>>> From: Chen Ridong <chenridong@huawei.com>
>>>>
>>>> Before the commit f5d39b020809 ("freezer,sched: Rewrite core freezer
>>>> logic"), the frozen task stat was reported as 'D' in cgroup v1.
>>>> However, after rewriting core freezer logic, the frozen task stat is
>>>> reported as 'R'. This is confusing, especially when a task with stat of
>>>> 'S' is frozen.
>>>>
>>>> This can be reproduced as bellow step:
>>>> cd /sys/fs/cgroup/freezer/
>>>> mkdir test
>>>> sleep 1000 &
>>>> [1] 739         // task whose stat is 'S'
>>>> echo 739 > test/cgroup.procs
>>>> echo FROZEN > test/freezer.state
>>>> ps -aux | grep 739
>>>> root     739  0.1  0.0   8376  1812 pts/0    R    10:56   0:00 sleep 1000
>>>>
>>>> As shown above, a task whose stat is 'S' was changed to 'R' when it was
>>>> frozen. To solve this issue, simply maintain the same reported state as
>>>> before the rewrite.
> 
> The whole point of the freezer rewrite was preventing userspace from causing
> arbitrary and indefinite D states which leads to all sorts of problems. The
> tasks in cgroup2 freezer are *not* in uninterruptible sleeps. They are in
> task stop loops and thus can be killed, ptraced and so on. It *should*
> report S.
> 
> Thanks.
> 

Hi, Tj, There is no ambiguity what cgroup v2 shows. However, in cgroup
v1, the frozen tasks are reported as 'R'.  Do you think this is reseanable?

Thanks,
Ridong


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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-11-15  1:14       ` Chen Ridong
@ 2024-11-15  1:28         ` Tejun Heo
  2024-11-25  2:14           ` Chen Ridong
  0 siblings, 1 reply; 10+ messages in thread
From: Tejun Heo @ 2024-11-15  1:28 UTC (permalink / raw)
  To: Chen Ridong
  Cc: Valentin Schneider, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman,
	mkoutny@suse.com >> Michal Koutný,
	linux-kernel, wangweiyang2, cgroups

Hello,

On Fri, Nov 15, 2024 at 09:14:32AM +0800, Chen Ridong wrote:
> Hi, Tj, There is no ambiguity what cgroup v2 shows. However, in cgroup
> v1, the frozen tasks are reported as 'R'.  Do you think this is reseanable?

Oh, right, pardon my confusion. I thought this was about cgroup2 freezer.
For cgroup1 freezer, yes, D is the closest state for reporting to userspace.

Thanks.

-- 
tejun

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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-11-15  1:28         ` Tejun Heo
@ 2024-11-25  2:14           ` Chen Ridong
  2024-12-04  1:52             ` Chen Ridong
  0 siblings, 1 reply; 10+ messages in thread
From: Chen Ridong @ 2024-11-25  2:14 UTC (permalink / raw)
  To: Tejun Heo, peterz
  Cc: Valentin Schneider, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman,
	mkoutny@suse.com >> Michal Koutný,
	linux-kernel, wangweiyang2, cgroups



On 2024/11/15 9:28, Tejun Heo wrote:
> Hello,
> 
> On Fri, Nov 15, 2024 at 09:14:32AM +0800, Chen Ridong wrote:
>> Hi, Tj, There is no ambiguity what cgroup v2 shows. However, in cgroup
>> v1, the frozen tasks are reported as 'R'.  Do you think this is reseanable?
> 
> Oh, right, pardon my confusion. I thought this was about cgroup2 freezer.
> For cgroup1 freezer, yes, D is the closest state for reporting to userspace.
> 
> Thanks.
> 

Hello, Peterz, do you have any opinions?

Best regards,
Ridong


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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-11-25  2:14           ` Chen Ridong
@ 2024-12-04  1:52             ` Chen Ridong
  2024-12-11 16:02               ` Michal Koutný
  0 siblings, 1 reply; 10+ messages in thread
From: Chen Ridong @ 2024-12-04  1:52 UTC (permalink / raw)
  To: Tejun Heo, peterz
  Cc: Valentin Schneider, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman,
	mkoutny@suse.com >> Michal Koutný,
	linux-kernel, wangweiyang2, cgroups



On 2024/11/25 10:14, Chen Ridong wrote:
> 
> 
> On 2024/11/15 9:28, Tejun Heo wrote:
>> Hello,
>>
>> On Fri, Nov 15, 2024 at 09:14:32AM +0800, Chen Ridong wrote:
>>> Hi, Tj, There is no ambiguity what cgroup v2 shows. However, in cgroup
>>> v1, the frozen tasks are reported as 'R'.  Do you think this is reseanable?
>>
>> Oh, right, pardon my confusion. I thought this was about cgroup2 freezer.
>> For cgroup1 freezer, yes, D is the closest state for reporting to userspace.
>>
>> Thanks.
>>
> 
> Hello, Peterz, do you have any opinions?
> 
> Best regards,
> Ridong
> 

Friendly ping.

Does anyone have any opinions?


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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-12-04  1:52             ` Chen Ridong
@ 2024-12-11 16:02               ` Michal Koutný
  2024-12-13  1:18                 ` Chen Ridong
  0 siblings, 1 reply; 10+ messages in thread
From: Michal Koutný @ 2024-12-11 16:02 UTC (permalink / raw)
  To: Chen Ridong
  Cc: Tejun Heo, peterz, Valentin Schneider, mingo, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	linux-kernel, wangweiyang2, cgroups

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

Hi.

On Wed, Dec 04, 2024 at 09:52:15AM GMT, Chen Ridong <chenridong@huaweicloud.com> wrote:
> Does anyone have any opinions?

When an 'R' task is frozen (v1) and it's shown as (unchanged) 'R' it's
acceptable.
When an 'S' task is equally frozen and its apparent state switches to
'R', I agree it's confusing.

Showing 'D' state in any case of a frozen task (like before that rework)
makes sense too. Please add Fixes: if you need to restore this behavior.

HTH,
Michal

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

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

* Re: [PATCH] freezer, sched: report the frozen task stat as 'D'
  2024-12-11 16:02               ` Michal Koutný
@ 2024-12-13  1:18                 ` Chen Ridong
  0 siblings, 0 replies; 10+ messages in thread
From: Chen Ridong @ 2024-12-13  1:18 UTC (permalink / raw)
  To: Michal Koutný
  Cc: Tejun Heo, peterz, Valentin Schneider, mingo, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	linux-kernel, wangweiyang2, cgroups



On 2024/12/12 0:02, Michal Koutný wrote:
> Hi.
> 
> On Wed, Dec 04, 2024 at 09:52:15AM GMT, Chen Ridong <chenridong@huaweicloud.com> wrote:
>> Does anyone have any opinions?
> 
> When an 'R' task is frozen (v1) and it's shown as (unchanged) 'R' it's
> acceptable.
> When an 'S' task is equally frozen and its apparent state switches to
> 'R', I agree it's confusing.
> 
> Showing 'D' state in any case of a frozen task (like before that rework)
> makes sense too. Please add Fixes: if you need to restore this behavior.
> 
> HTH,
> Michal

Thank you, Michal. I will update.

Thanks,
Ridong


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

end of thread, other threads:[~2024-12-13  1:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-11 13:54 [PATCH] freezer, sched: report the frozen task stat as 'D' Chen Ridong
2024-11-13 14:34 ` Valentin Schneider
2024-11-14  7:47   ` Chen Ridong
2024-11-14 16:44     ` Tejun Heo
2024-11-15  1:14       ` Chen Ridong
2024-11-15  1:28         ` Tejun Heo
2024-11-25  2:14           ` Chen Ridong
2024-12-04  1:52             ` Chen Ridong
2024-12-11 16:02               ` Michal Koutný
2024-12-13  1:18                 ` Chen Ridong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®