Skip to contentSkip to conversation

PM: Use WQ_MEM_RECLAIM flag for PM workqueue

PATCH In review [email protected] 2 participants 2 messages Oct 27, 2020 – Nov 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: Use WQ_MEM_RECLAIM flag for PM workqueue

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 +1 -1
index 40f86ec4ab30..ff5f3349e76f 100644
@@ -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;
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · On Tue, Oct 27, 2020 at 11:15 AM <[email protected]> wrote:

Deadlock is seen under below high memory usage scenario.

I'm not sure what the "under below high" means.

Quoted 3 lines

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.

Can you explain in more detail how exactly you end up in that situation?

Quoted 1 line

Use WQ_MEM_RECLAIM flag for PM workqueue to avoid this deadlock.

This works, but this flag doesn't seem to be appropriate here, because pm_wq doesn't actually participate in memory reclaim.

Quoted 21 lines
---
 kernel/power/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/main.c +1 -2
index 40f86ec4ab30..ff5f3349e76f 100644
@@ -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;
 }
--

2.17.1