From nobody Thu Dec 18 06:21:56 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B67030FC24 for ; Mon, 8 Dec 2025 13:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765200077; cv=none; b=hJPUOQ5dPLpMVtUDh/QKUnH050FmGs3k52XOcZJWQsQczvxtZh/tznNa3jzbgnvnF+kHO+nsjRQj/8Zfu+lHWvGc/kdnThR4pzMlzQdUSMuiU1IYMfs+k25hOP4kT/OXasBEKyjs5gERT5M6m49+OXAEzfyEfJl5ds6DeNpSYTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765200077; c=relaxed/simple; bh=a1617jDaVg8Z+BV6+fUybXFmenx6yyulPUkfETDWHf0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Eynh8BopN6CgdzHHpbIqccpedUwyDjXk9Ol3lptVkAo2KhDuBNck4/zdtX1yMJWddSoClkdOW1CBSzAkJvbHRl5XGodco0OTCWeNfAL6lHL57aCBTQi+VVyaPTvQhO95aaj+b/82OIGNBmJz2kiFQrPzFUxcFkY1B1FG73tre9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=I7iyhlyw; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I7iyhlyw" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7baf61be569so4900231b3a.3 for ; Mon, 08 Dec 2025 05:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765200075; x=1765804875; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8+H+eaC3nvAexHWqMkugF21S97F/3aybYMcwc3qTTfA=; b=I7iyhlywBuPbvYvKrjajbH5h9KjzEpwW/5/byjIcXOjqQ0rDY7i90eHu9vBoWJ9yDp HKBiT66i1T1iIKLwxK4Kzq2Ai/g+UnLHW56XpNdBo4Da2LKxqmi8/QCfW2z9lGNXPBoD tK6F3jsCS4oXvOjH+/LqQMgJmt5+vfd2IlCyU920aYNoOKkvzxgYUqIKu0EleZZBldSy /okQtM9yLRAY6y6qshwNyDVJLrEYPDssrFTSVceHd0s2f4Lph61DQvd9wnuFFSLsOBeU XUGlGACvcnFHZOeh6mK8obUYBuugddDAipVFVQxxLJDjfV9DGKoBSalZ3dMwdMb/Jbis BCEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765200075; x=1765804875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8+H+eaC3nvAexHWqMkugF21S97F/3aybYMcwc3qTTfA=; b=Gn354KWtLiMhO4idfUQiV4wjpTmbbiNcphFoJ7bqIhwR3Db8+fISVPLW2PqCBS05qc PDX1Jrm+6n8YA1zMPtZRWZc+mhSYKqFuwj/XRRjw52p7voe86pt9Ld07FpP2njfOaDeH fZGO5SY4mbHF6QCvuIKNeb9BUUxoO+Tams+LQkkh78HsundDJ8ktxkm0anQe43zX0CI4 c4IEfuHWhp2sjhleXcBv3IJsFfe0wYAV0ykPxTXpiJGYpUvtTejKGQMaBMBlXkXZeVLX Mc2cQnB3ka90wCA4lv+TViayddKBowDBt40hDcvmUy9Ly6aq4LZsX9dOypy2QCvXwNT9 obpg== X-Gm-Message-State: AOJu0YzhjmsSZZzXSBoi62BCdzSxmwtJW28ECC1LpG7X7l6q/gy3BtXP syONw9a30P7xzW36twy22ud6fdlE9kil4fCXR6OBuemsA2eb8+UNo/bzSftTVuJT X-Gm-Gg: ASbGnct2txLMYOjysYJ94Hs2ley0gvRzHB7p4GL39It2uzXfbzDYhNUifrPQLHor/Ff qOeB2/UbSeJ9bL5d9gvdzRcRFU2xjTDtsOXR84hi18ihQajsOBem14Sv2a51J+36ugHQShQ6++D GhbmvhQwJyeKeYRdezJzVxDw/+mWbHmhXcdeaZv60bMjiJbxHfCQ7l/5Pm2rpTSwSVRgLM1QkwR VAd1DZRmtXQ7FYV1NSHo379rLKx4rTD2VWzPMk5AIvnnIW+GDAk1gkBXLfFNzYscdR1Ra05nAgg 8ZDa9qKI+ttPeW+w3n+b1Rle62BjZPn2v2+zKrMcFz8aeC6NFWgwu0E347DObfnzB0GVStEFnlQ cnhX1vdJP9sTUbHbt/I4TFDWtHW5Ay8LbEn0kTBFDlcR64RrpXBS3eeQ3rrGWlI7+s1Zb2/nVkw zLquhaVPD7S0w= X-Google-Smtp-Source: AGHT+IFkzoouYBq1hy+Sg7fV7f39xk4IumyXXZj76yp6pH6ZXic4dhqqSIbDg3LzsKvIOwrz2WNVaA== X-Received: by 2002:a05:6a00:390d:b0:7b8:8d43:fcd2 with SMTP id d2e1a72fcca58-7e8c1755b45mr5981212b3a.14.1765200075412; Mon, 08 Dec 2025 05:21:15 -0800 (PST) Received: from localhost ([240b:4000:bb:1700:7b36:494d:5625:5a1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7e29f2edf3dsm13338769b3a.6.2025.12.08.05.21.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Dec 2025 05:21:14 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , ying chen , Lai Jiangshan , Lai Jiangshan Subject: [PATCH V5 3/3] workqueue: Process extra works in rescuer on memory pressure Date: Mon, 8 Dec 2025 21:25:19 +0800 Message-Id: <20251208132520.1667697-4-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20251208132520.1667697-1-jiangshanlai@gmail.com> References: <20251208132520.1667697-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lai Jiangshan 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 --- kernel/workqueue.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index add236e0dac4..fe5daa32d55e 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3461,10 +3461,37 @@ static bool assign_rescuer_work(struct pool_workque= ue *pwq, struct worker *rescu struct work_struct *cursor =3D &pwq->mayday_cursor; struct work_struct *work, *n; =20 - /* need rescue? */ - if (!pwq->nr_active || !need_to_create_worker(pool)) + /* have work items to rescue? */ + if (!pwq->nr_active) return false; =20 + /* need rescue? */ + if (!need_to_create_worker(pool)) { + /* + * The pool has idle workers and doesn't need the rescuer, so it + * could simply return false here. + * + * However, the memory pressure might not be fully relieved. + * In PERCPU pool with concurrency enabled, having idle workers + * does not necessarily mean memory pressure is gone; it may + * simply mean regular workers have woken up, completed their + * work, and gone idle again due to concurrency limits. + * + * In this case, those working workers may later sleep again, + * the pool may run out of idle workers, and it will have to + * allocate new ones and wait for the timer to send mayday, + * causing unnecessary delay - especially if memory pressure + * was never resolved throughout. + * + * Do more work if memory pressure is still on to reduce + * relapse, using (pool->flags & POOL_MANAGER_ACTIVE), though + * not precisely, unless there are other PWQs needing help. + */ + if (!(pool->flags & POOL_MANAGER_ACTIVE) || + !list_empty(&pwq->wq->maydays)) + return false; + } + /* search from the start or cursor if available */ if (list_empty(&cursor->entry)) work =3D list_first_entry(&pool->worklist, struct work_struct, entry); --=20 2.19.1.6.gb485710b