Skip to contentSkip to conversation

kthread: Use TASK_IDLE state for newly created kernel threads

PATCH In review Pavankumar Kondeti 2 participants 6 messages May 20, 2020 – May 21, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kthread: Use TASK_IDLE state for newly created kernel threads

When kernel threads are created for later use, they will be in TASK_UNINTERRUPTIBLE state until they are woken up. This results in increased loadavg and false hung task reports. To fix this, use TASK_IDLE state instead of TASK_UNINTERRUPTIBLE when a kernel thread schedules out for the first time.

---
 kernel/kthread.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kthread.c +3 -3
index bfbfa48..b74ed8e 100644
@@ -250,7 +250,7 @@ static int kthread(void *_create)
 	current->vfork_done = &self->exited;
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
-	__set_current_state(TASK_UNINTERRUPTIBLE);
+	__set_current_state(TASK_IDLE);
 	create->result = current;
 	/*
 	 * Thread is going to call schedule(), do not preempt it,
@@ -428,7 +428,7 @@ static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
 
 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
 {
-	__kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
+	__kthread_bind_mask(p, mask, TASK_IDLE);
 }
 
 /**
@@ -442,7 +442,7 @@ void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
  */
 void kthread_bind(struct task_struct *p, unsigned int cpu)
 {
-	__kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE);
+	__kthread_bind(p, cpu, TASK_IDLE);
 }
 EXPORT_SYMBOL(kthread_bind);
 
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
#1 lore raw
Quoted 34 lines · Pavankumar Kondeti

When kernel threads are created for later use, they will be in TASK_UNINTERRUPTIBLE state until they are woken up. This results in increased loadavg and false hung task reports. To fix this, use TASK_IDLE state instead of TASK_UNINTERRUPTIBLE when a kernel thread schedules out for the first time.

---
 kernel/kthread.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kthread.c +2 -2
index bfbfa48..b74ed8e 100644
@@ -250,7 +250,7 @@ static int kthread(void *_create)
 	current->vfork_done = &self->exited;
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
-	__set_current_state(TASK_UNINTERRUPTIBLE);
+	__set_current_state(TASK_IDLE);
 	create->result = current;
 	/*
 	 * Thread is going to call schedule(), do not preempt it,
@@ -428,7 +428,7 @@ static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
 
 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
 {
-	__kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
+	__kthread_bind_mask(p, mask, TASK_IDLE);
 }
 
 /**

kernel/kthread.c void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask) · line 447

Quoted 7 lines
kernel/kthread.c +1 -1
@@ -442,7 +442,7 @@ void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
  */
 void kthread_bind(struct task_struct *p, unsigned int cpu)
 {
-	__kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE);
+	__kthread_bind(p, cpu, TASK_IDLE);
 }
 EXPORT_SYMBOL(kthread_bind);

It's as if people never read mailing lists:

	https://lore.kernel.org/r/DM6PR11MB3531D3B164357B2DC476102DDFC90@DM6PR11MB3531.namprd11.prod.outlook.com

Given that this is an identical resend of the previous patch, why are you doing so, and what has changed since that original rejection?

greg k-h

#2 lore raw
Quoted 44 lines · Greg Kroah-Hartman
Quoted 34 lines · Pavankumar Kondeti

When kernel threads are created for later use, they will be in TASK_UNINTERRUPTIBLE state until they are woken up. This results in increased loadavg and false hung task reports. To fix this, use TASK_IDLE state instead of TASK_UNINTERRUPTIBLE when a kernel thread schedules out for the first time.

---
 kernel/kthread.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kthread.c +2 -2
index bfbfa48..b74ed8e 100644
@@ -250,7 +250,7 @@ static int kthread(void *_create)
 	current->vfork_done = &self->exited;
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
-	__set_current_state(TASK_UNINTERRUPTIBLE);
+	__set_current_state(TASK_IDLE);
 	create->result = current;
 	/*
 	 * Thread is going to call schedule(), do not preempt it,
@@ -428,7 +428,7 @@ static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
 
 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
 {
-	__kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
+	__kthread_bind_mask(p, mask, TASK_IDLE);
 }
 
 /**

kernel/kthread.c void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask) · line 447

Quoted 7 lines
kernel/kthread.c +1 -1
@@ -442,7 +442,7 @@ void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
  */
 void kthread_bind(struct task_struct *p, unsigned int cpu)
 {
-	__kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE);
+	__kthread_bind(p, cpu, TASK_IDLE);
 }
 EXPORT_SYMBOL(kthread_bind);

It's as if people never read mailing lists:

Quoted 5 lines
	https://lore.kernel.org/r/DM6PR11MB3531D3B164357B2DC476102DDFC90@DM6PR11MB3531.namprd11.prod.outlook.com

Given that this is an identical resend of the previous patch, why are you doing so, and what has changed since that original rejection?

I did not know that it is attempted before. Thanks for pointing to the previous discussion.

We have seen hung task reports from customers and it is due to a downstream change which create bunch of kernel threads for later use. From Peter's reply, I understood that one must wake up the kthread after creation and put it in INTERRUPTIBLE sleep. I will pass on the message.

Thanks,
Pavan

Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
#3 lore raw
Quoted 47 lines · Pavan Kondeti
Quoted 46 lines · Greg Kroah-Hartman
Quoted 34 lines · Pavankumar Kondeti

When kernel threads are created for later use, they will be in TASK_UNINTERRUPTIBLE state until they are woken up. This results in increased loadavg and false hung task reports. To fix this, use TASK_IDLE state instead of TASK_UNINTERRUPTIBLE when a kernel thread schedules out for the first time.

---
 kernel/kthread.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kthread.c +2 -2
index bfbfa48..b74ed8e 100644
@@ -250,7 +250,7 @@ static int kthread(void *_create)
 	current->vfork_done = &self->exited;
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
-	__set_current_state(TASK_UNINTERRUPTIBLE);
+	__set_current_state(TASK_IDLE);
 	create->result = current;
 	/*
 	 * Thread is going to call schedule(), do not preempt it,
@@ -428,7 +428,7 @@ static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
 
 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
 {
-	__kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
+	__kthread_bind_mask(p, mask, TASK_IDLE);
 }
 
 /**

kernel/kthread.c void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask) · line 447

Quoted 7 lines
kernel/kthread.c +1 -1
@@ -442,7 +442,7 @@ void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
  */
 void kthread_bind(struct task_struct *p, unsigned int cpu)
 {
-	__kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE);
+	__kthread_bind(p, cpu, TASK_IDLE);
 }
 EXPORT_SYMBOL(kthread_bind);

It's as if people never read mailing lists:

	https://lore.kernel.org/r/DM6PR11MB3531D3B164357B2DC476102DDFC90@DM6PR11MB3531.namprd11.prod.outlook.com
Quoted 8 lines
Quoted 3 lines

Given that this is an identical resend of the previous patch, why are you doing so, and what has changed since that original rejection?

I did not know that it is attempted before. Thanks for pointing to the previous discussion.

We have seen hung task reports from customers and it is due to a downstream change which create bunch of kernel threads for later use.

Do you have a pointer to that specific change?

Quoted 3 lines

From Peter's reply, I understood that one must wake up the kthread after creation and put it in INTERRUPTIBLE sleep. I will pass on the message.

Just go fix that code, it sounds like it's in your tree already :)

thanks,

greg k-h

#4 lore raw
Quoted 51 lines · Greg Kroah-Hartman
Quoted 50 lines · Pavan Kondeti
Quoted 49 lines · Greg Kroah-Hartman
Quoted 34 lines · Pavankumar Kondeti

When kernel threads are created for later use, they will be in TASK_UNINTERRUPTIBLE state until they are woken up. This results in increased loadavg and false hung task reports. To fix this, use TASK_IDLE state instead of TASK_UNINTERRUPTIBLE when a kernel thread schedules out for the first time.

---
 kernel/kthread.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kthread.c +2 -2
index bfbfa48..b74ed8e 100644
@@ -250,7 +250,7 @@ static int kthread(void *_create)
 	current->vfork_done = &self->exited;
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
-	__set_current_state(TASK_UNINTERRUPTIBLE);
+	__set_current_state(TASK_IDLE);
 	create->result = current;
 	/*
 	 * Thread is going to call schedule(), do not preempt it,
@@ -428,7 +428,7 @@ static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
 
 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
 {
-	__kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
+	__kthread_bind_mask(p, mask, TASK_IDLE);
 }
 
 /**

kernel/kthread.c void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask) · line 447

Quoted 7 lines
kernel/kthread.c +1 -1
@@ -442,7 +442,7 @@ void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
  */
 void kthread_bind(struct task_struct *p, unsigned int cpu)
 {
-	__kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE);
+	__kthread_bind(p, cpu, TASK_IDLE);
 }
 EXPORT_SYMBOL(kthread_bind);

It's as if people never read mailing lists:

	https://lore.kernel.org/r/DM6PR11MB3531D3B164357B2DC476102DDFC90@DM6PR11MB3531.namprd11.prod.outlook.com

Given that this is an identical resend of the previous patch, why are you doing so, and what has changed since that original rejection?

Quoted 8 lines
Quoted 5 lines

I did not know that it is attempted before. Thanks for pointing to the previous discussion.

We have seen hung task reports from customers and it is due to a downstream change which create bunch of kernel threads for later use.

Do you have a pointer to that specific change?

Here it is
https://source.codeaurora.org/quic/la/kernel/msm-4.19/commit/drivers/staging/android/ion/ion_system_heap.c?h=LA.UM.8.12.r1-11300-sm8250.0&id=0734b477f1e77cb9f91f5e5c0d7742d3113f2cd3

Quoted 6 lines
Quoted 3 lines

From Peter's reply, I understood that one must wake up the kthread after creation and put it in INTERRUPTIBLE sleep. I will pass on the message.

Just go fix that code, it sounds like it's in your tree already :)

Yes, we will fix it.

Thanks,
Pavan

Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
#5 lore raw
Quoted 55 lines · Pavan Kondeti
Quoted 54 lines · Greg Kroah-Hartman
Quoted 53 lines · Pavan Kondeti
Quoted 44 lines · Greg Kroah-Hartman
Quoted 34 lines · Pavankumar Kondeti

When kernel threads are created for later use, they will be in TASK_UNINTERRUPTIBLE state until they are woken up. This results in increased loadavg and false hung task reports. To fix this, use TASK_IDLE state instead of TASK_UNINTERRUPTIBLE when a kernel thread schedules out for the first time.

---
 kernel/kthread.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kthread.c +2 -2
index bfbfa48..b74ed8e 100644
@@ -250,7 +250,7 @@ static int kthread(void *_create)
 	current->vfork_done = &self->exited;
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
-	__set_current_state(TASK_UNINTERRUPTIBLE);
+	__set_current_state(TASK_IDLE);
 	create->result = current;
 	/*
 	 * Thread is going to call schedule(), do not preempt it,
@@ -428,7 +428,7 @@ static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
 
 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
 {
-	__kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
+	__kthread_bind_mask(p, mask, TASK_IDLE);
 }
 
 /**

kernel/kthread.c void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask) · line 447

Quoted 7 lines
kernel/kthread.c +1 -1
@@ -442,7 +442,7 @@ void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
  */
 void kthread_bind(struct task_struct *p, unsigned int cpu)
 {
-	__kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE);
+	__kthread_bind(p, cpu, TASK_IDLE);
 }
 EXPORT_SYMBOL(kthread_bind);

It's as if people never read mailing lists:

Quoted 5 lines
	https://lore.kernel.org/r/DM6PR11MB3531D3B164357B2DC476102DDFC90@DM6PR11MB3531.namprd11.prod.outlook.com

Given that this is an identical resend of the previous patch, why are you doing so, and what has changed since that original rejection?

I did not know that it is attempted before. Thanks for pointing to the previous discussion.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

We have seen hung task reports from customers and it is due to a downstream change which create bunch of kernel threads for later use.

Do you have a pointer to that specific change?

Here it is
https://source.codeaurora.org/quic/la/kernel/msm-4.19/commit/drivers/staging/android/ion/ion_system_heap.c?h=LA.UM.8.12.r1-11300-sm8250.0&id=0734b477f1e77cb9f91f5e5c0d7742d3113f2cd3

Ick, ion system heaps :(

Anyway, why not just use a workqueue for this, why a full kernel thread? What does that help with? It also might fix those crazy hacks you have in there for "cpu affinity" as all of that would be taken care of for you automatically with a workqueue, right?

good luck!

greg k-h