Skip to contentSkip to conversation

PM: Use WQ_MEM_RECLAIM flag for PM workqueue

PATCH Rafael J. Wysocki 2 participants 2 messages Oct 26, 2020 – Nov 2, 2020 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 18 lines · Ravisankarreddy lingareddy

Deadlock is seen under below high memory usage scenario.

kswapd waiting to reclaim memory is blocked on i/o kworker and pm_wq context which needs to wakeup i/o kworker is waiting for kthread creation which is again blocked in memory reclaim path.

Use WQ_MEM_RECLAIM flag for PM workqueue to avoid this deadlock.

---
  kernel/power/main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/main.c +0 -0
index 40f86ec4ab30..ff5f3349e76f 100644

kernel/power/main.c EXPORT_SYMBOL_GPL(pm_wq); · line 939

Quoted 8 lines
kernel/power/main.c +1 -1
@@ -933,7 +933,7 @@ EXPORT_SYMBOL_GPL(pm_wq);
 
  static int __init pm_start_workqueue(void)
  {
-	pm_wq = alloc_workqueue("pm", WQ_FREEZABLE, 0);
+	pm_wq = alloc_workqueue("pm", WQ_FREEZABLE | WQ_MEM_RECLAIM, 0);
 
  	return pm_wq ? 0 : -ENOMEM;
  }

Please resend this with a CC to [email protected].

Also it would be good to know how to reproduce this issue.

#2 lore raw
Quoted 1 line

Please resend this with a CC to [email protected].

Thank you, I resend with a CC to [email protected].

Quoted 1 line

Also it would be good to know how to reproduce this issue.

Commit message says under high memory scenarios, try a memory pressure test and do repeatedly until the battery is under 20%.

Quoted 3 lines

@Pavel,

Does this need some kind of auditing to make sure we don't allocate memory from the code running in the workqueue, and thus further deadlocks?

I used WQ_MEM_RECLAIM in pm_wq workqueue to fix bug and no further deadlocks are seen and tested on 4.9 and 4.19 kernel.

Best Regards,
Ravi

Quoted 34 lines · Rafael J. Wysocki
Quoted 18 lines · Ravisankarreddy lingareddy

Deadlock is seen under below high memory usage scenario.

kswapd waiting to reclaim memory is blocked on i/o kworker and pm_wq context which needs to wakeup i/o kworker is waiting for kthread creation which is again blocked in memory reclaim path.

Use WQ_MEM_RECLAIM flag for PM workqueue to avoid this deadlock.

---
  kernel/power/main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/main.c +0 -0
index 40f86ec4ab30..ff5f3349e76f 100644

kernel/power/main.c EXPORT_SYMBOL_GPL(pm_wq); · line 939

Quoted 8 lines
kernel/power/main.c +1 -1
@@ -933,7 +933,7 @@ EXPORT_SYMBOL_GPL(pm_wq);
 
  static int __init pm_start_workqueue(void)
  {
-     pm_wq = alloc_workqueue("pm", WQ_FREEZABLE, 0);
+     pm_wq = alloc_workqueue("pm", WQ_FREEZABLE | WQ_MEM_RECLAIM, 0);
 
      return pm_wq ? 0 : -ENOMEM;
  }

Please resend this with a CC to [email protected].

Also it would be good to know how to reproduce this issue.