Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

workqueue: Process extra works in rescuer on memory pressure

Make the rescuer process more work on the last pwq when there are no
more to rescue for the whole workqueue to help the regular workers in
case it is a temporary memory pressure relief and to reduce relapse.

Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Lai Jiangshan and committed by
Tejun Heo
51cd2d2d e5a30c30

+29 -2
+29 -2
kernel/workqueue.c
··· 3461 3461 struct work_struct *cursor = &pwq->mayday_cursor; 3462 3462 struct work_struct *work, *n; 3463 3463 3464 - /* need rescue? */ 3465 - if (!pwq->nr_active || !need_to_create_worker(pool)) 3464 + /* have work items to rescue? */ 3465 + if (!pwq->nr_active) 3466 3466 return false; 3467 + 3468 + /* need rescue? */ 3469 + if (!need_to_create_worker(pool)) { 3470 + /* 3471 + * The pool has idle workers and doesn't need the rescuer, so it 3472 + * could simply return false here. 3473 + * 3474 + * However, the memory pressure might not be fully relieved. 3475 + * In PERCPU pool with concurrency enabled, having idle workers 3476 + * does not necessarily mean memory pressure is gone; it may 3477 + * simply mean regular workers have woken up, completed their 3478 + * work, and gone idle again due to concurrency limits. 3479 + * 3480 + * In this case, those working workers may later sleep again, 3481 + * the pool may run out of idle workers, and it will have to 3482 + * allocate new ones and wait for the timer to send mayday, 3483 + * causing unnecessary delay - especially if memory pressure 3484 + * was never resolved throughout. 3485 + * 3486 + * Do more work if memory pressure is still on to reduce 3487 + * relapse, using (pool->flags & POOL_MANAGER_ACTIVE), though 3488 + * not precisely, unless there are other PWQs needing help. 3489 + */ 3490 + if (!(pool->flags & POOL_MANAGER_ACTIVE) || 3491 + !list_empty(&pwq->wq->maydays)) 3492 + return false; 3493 + } 3467 3494 3468 3495 /* search from the start or cursor if available */ 3469 3496 if (list_empty(&cursor->entry))