From nobody Tue Dec 2 01:48:38 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 A37C231A578 for ; Fri, 21 Nov 2025 14:53:57 +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=1763736841; cv=none; b=ciDuIrJ9u3Wt2RjUQnFPYqmxPVXvmGwmuMCMp1EChtttCgKSxHrwuCFhFLPqPwGCmHm6io9nROt91l8gkQhKW2LU2YBqX84QbQ7KqMtg6Aj30v87xZXXCORnTn3p++OEQeW0/ljoNzlkhfMMD4hWNGI3rGQ6c19jwPC7N37acR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763736841; c=relaxed/simple; bh=ytmMm38EiE85qgzZR8avey2qDbohVdLk9mQE7f85GDI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=flhQlsZH2ZQk7XTlLKLrlf3SiTZetugy+lSBeCEsD7oWf/q4GTOBcudjeKruXUwhE2bc9gK6JWj29IRXiCyI0bx75ywoT2SmaBqY6t2+sOAvp1xFhO3Nq17d7d9eTULllzSByXsapq8HT6mVrtfEJ/+ykKk9/LVO8PnUirGzDXA= 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=OY0PHOEQ; 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="OY0PHOEQ" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7acd9a03ba9so2369928b3a.1 for ; Fri, 21 Nov 2025 06:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763736836; x=1764341636; 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=P1QGhBuRCqIVwoTMitPXGLd+RJLkpfV0sHccooqbqpc=; b=OY0PHOEQDjA0D8VDlN3aqUNCgZweH7esf6gFySs3s+MT0ajRQZh2F8pFl1XIxa2hsj 8suzskMCmAbKT/Tcf5RfWhZoXDWFcsU4ZpJ9Boura7mLzT4F2kAbFb6vmS1FT/Kk9asp jFo9/qUKQ9av2h9kZ93PgXkyC/mxe/sD9uUCO8eUF6vo8qt5zwp1T8xjabJOB2oqUTB4 NrfKF2wXlGu2DNxAIQbaJ6nbVwENixiYMSPXCA1myV//ejKftEa/8wfGGZz0bGpEW7la z3hQIRI4V58c6aSPgYX3+rgTwx1AxkZEapaEj3UhVhcpkYtxLO69DO9eRBDd+YDYY7ds +0xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763736836; x=1764341636; 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=P1QGhBuRCqIVwoTMitPXGLd+RJLkpfV0sHccooqbqpc=; b=lulXmGzqim72Kw+//VH3HyXBgtcRA6orPxj+ZMjDjPArt2gYNoLacb0Bee8ra3opo0 3CuTMjFoEg6BbEMZYqDA/m9/G1w1+l9jtFawhay++ZnUvEu+PCI2Gyw2+ka6E6w0LY9n Hc2S+reQWAqIRl0FOc/5OBwkOW+SNuaQEoLJn3XtOMRoba9qq7KC8VPoGhbQYBReti89 2TF80eUIqo0xf6WK4P9nbbbIv2qANwnS/CAFfnkgBLj00hh9ZkHp+JsbpMiPe1uh30CP OAzvgTWa6QDEUppx3hqhaFaKRkp5atNvGQFo74AxxEYpB/NAkQU048xDwUUfUyoM12RV BSLg== X-Gm-Message-State: AOJu0Yx3uc/PUtCzg6TqLBOqawp7DOUCy/w+vo1PYtJNineB8qrTzcM4 TT2TTrxlFNd7+G4f/qoK/dAn/gyz3TxCa5Upl0362aaiB+qqdUk0X+kmuBguEiAI X-Gm-Gg: ASbGncvC66Y9ZMfTTAKSxjeBJuQ6ZWv44QUr02C+eeVzuvuMe64OogHtot3mGpk+qmg UkyjsNvsiapPsv4xQj91Oz+KQ92Ny9hzCZfxgn2XI6SpXvVHPzB6dmY0I1DcbbAADC3TYHzS6tp 2g4oKLsZaVh95qX1PGRvtdAyi95hvHU2vSuHGSBdftPS/moHYkgsvpYfLH4wD6x/EgUY7roFt2j 1odb8vCKJNDuQ7chNFBHSz0PNmMyDbErfgIpl4IC5sM9tosZaNFkqgHOlp91Ufzz0YjZFeSyJ00 K7MLVBYtFPjk/31aJBwscIUqaAph1EbNvUKtWPNW74rIN38BUtBkZ44o8Fia1JxobODtNyQ9sCH 6lVTpPYnUkqOhIaq566hnjxsgPf25+H4qpJ8qAMdJO63t+58dImy5yqMLLSTkXu9E+7USkpM2v8 saPxonEmfvZvQ07x6s264+8A== X-Google-Smtp-Source: AGHT+IGk5d52c0FU06wlPaGcL7cijPH3sfsVkPqTVfzjw+NrTNKj3nG1FAE4PaH3bpFHFvVMnZRdSQ== X-Received: by 2002:a05:6a00:94fa:b0:7a2:1b8a:ca22 with SMTP id d2e1a72fcca58-7c58eaff9ebmr2618491b3a.25.1763736835659; Fri, 21 Nov 2025 06:53:55 -0800 (PST) Received: from localhost ([240b:4000:bb:1700:7b36:494d:5625:5a1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7c3f0243b3csm6331930b3a.36.2025.11.21.06.53.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Nov 2025 06:53:55 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , ying chen , Lai Jiangshan , Lai Jiangshan Subject: [PATCH V3 7/7] workqueue: Process extra works in rescuer when there are no more to rescue Date: Fri, 21 Nov 2025 22:57:20 +0800 Message-Id: <20251121145720.342467-8-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20251121145720.342467-1-jiangshanlai@gmail.com> References: <20251121145720.342467-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 relief and to reduce relapse. Also limit the number of extra works. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 9bc155545492..86acf2a9cd41 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3473,10 +3473,30 @@ static bool assign_rescuer_work(struct pool_workque= ue *pwq, struct worker *rescu list_del_init(&cursor->entry); } =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, and if the regular workers later + * go to sleep and the pool runs out of idle workers, mayday + * would be triggered again. + * + * Do more work even if it doesn't need rescue, to help the + * regular workers in case it is a temporary relief and to + * reduce relapse. + * + * Unless the limit is reached or there are other PWQs needing + * help. + */ + if (limited || !list_empty(&pwq->wq->maydays)) + return false; + } + /* try to assign a work to rescue */ list_for_each_entry_safe_from(work, n, &pool->worklist, entry) { if (get_work_pwq(work) !=3D pwq) --=20 2.19.1.6.gb485710b