From nobody Tue Dec 2 01:03:30 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 B0DE12BE7B6 for ; Tue, 25 Nov 2025 06:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764052352; cv=none; b=g2ETBGC/BiJ9B457+HMMhiFL6QKLAdFAd6D5OBfGjvAa0ekchuPFDB8bE+R2CI9XJ/pDRw+XI3zOuLdjldQkpDB4o0nOX7jV25fDKBCydXX3l9lepVIpTwymgRR3EcRt9YBqNMdMFjBkx3wvIw9GS02h4R5Cm28r9t53e6St7ZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764052352; c=relaxed/simple; bh=60w5pS9yBSx1jjubcjS32HjXJo9fhAM3P6pHnvtYbBU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ff8VjN9RpkaArDeY5hxx5LHYWrZKzTiXJyVgl9kkJUfYSDbw8/vZjNxDTs5pp6WTGV5VIH6bwXGf2gkEbrvsD/QARwZhmONKwPXav93ZjP+3sf8NdpuRE+bltXLtR2btt+P7jicFUsZEOcfTbtNTxRGU/rFMOHGTXeID0+uo/hM= 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=FpAzqlRY; arc=none smtp.client-ip=209.85.214.171 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="FpAzqlRY" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2980d9b7df5so63649615ad.3 for ; Mon, 24 Nov 2025 22:32:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764052350; x=1764657150; 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=LPmid93vVx5WXKVpvZGHfLR1iexFd/wtP/8PCZcFv7U=; b=FpAzqlRYzfahPUvd47bashl0TezZdfx3bKqW3dvSH1GZ/7MYrT/gb91tZ6z3EgRLul rFYNbdxFG1V6jkNqX4wWw8TgeUd20/W7sFPPMxKrFnJ6GR0ZnnQkVEiLdw5FgKxUaRio /KGv3o+ir6hX8vkInXiOmTb2ONiZxDxhcap2iJbsaFLW8TyAVqDrfV8JDSvs6O5+5SsC omLeUsqjmPok7dQ0AuwezuS3IXCIQFhm7af6iOa5p6JZC+77U4TjPfJHJKmhy+JojuAe SR5df/VszCEZm2P11XDkxPtPN/iy8qDN3TYaWQTrqX/vjIXYCp0ExoKJa60VX9gqA9Ye xb3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764052350; x=1764657150; 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=LPmid93vVx5WXKVpvZGHfLR1iexFd/wtP/8PCZcFv7U=; b=dGLhGZSRsCm0pT1j6FuOtFG+PMjBkuJfW5jB/AbbIqYHprMMHIzuMfIqtlj4CSpoQA fm3ItQug+02Z8Dz4HelFkVg0WT9QYmCafVENTZB1AT6HGxcRvP/mtyxjOtZdXHS1PPpP ofkO8f6kATZufFVaP5IGTzIdRciUr5cOGQrBXgQXcJGe//QtFZKdZGe12xPkEeO0tZMx 3bErmpWV8j43NMpxOt4uG9HMEsI38cPlqASkDjQp0Z1N5qCqlBUHKmcXTLgdtbaWKX0d c3J98y9ohB1TwvWTCFjP7EhAUD7gtOTO8uSNCKzzzxEn5yq6B9ZxOsrhBZ1LVI8o/+e7 x3xw== X-Gm-Message-State: AOJu0YzpCCox6fSIULauiEsC4eUeA8636wN90ti4WxIsN9rTpS0seryL F7sPQBGYciXLt6p9yxsgkvaJgiB//EDQo5rSuFlHqsfL6jM5lEceqjT2qJxdP9sK X-Gm-Gg: ASbGncvyj2CWPGy4j1ipQ57tPuC1OaHp3L3Wso/T/HhyPizC+LGDgygNPV6c/bRDVUo gqlujG/zQbky7zJz7qFSsH5HZzA/mDtAh3MUG6OykC87SCkDpncdMmdRTgCRuohnDL+pQB6w1SN 2qym+m/4GVV21unfgEKqbMCGTROITeKfaOBeI92sQYnVVkkDWoBwnY7bpmjaldgbdMyGQ/RcKYx G8aF/to5tNr+FbbCDZtQv+zqHDZAb6d+BnZZz2l123hddXs9l8zSNd+MLxsrzhVZ34ISVnvlQpp DZXTLSpB0+E5BwKHHENwJC42+3J5MM7QOChXiHUx80x5WmLtVhHNFnmYad+nJ93aANWO88HeACr 1nOiwIYn+QVug/u7qm11U/tGTw/0vMJSzh86iJEmREwbsDrew2LFsyDpzLkPrdSYgcfSXtKhrKL QhP0wOR5EeHWg/ X-Google-Smtp-Source: AGHT+IGuoDbcZr3RSab9H8RYzJ76vTNB+NbXc1HA7gxF/haRyOSam/ZqrRv+OAet+D+e3V5nB+mIPg== X-Received: by 2002:a17:902:ef07:b0:294:cc1d:e2b6 with SMTP id d9443c01a7336-29b6bf9c727mr159206525ad.59.1764052349890; Mon, 24 Nov 2025 22:32:29 -0800 (PST) Received: from localhost ([240b:4000:bb:1701:388a:b68c:56c7:adeb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b273b06sm153667055ad.74.2025.11.24.22.32.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Nov 2025 22:32:29 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , ying chen , Lai Jiangshan , Lai Jiangshan Subject: [PATCH V4 4/4] workqueue: Process extra works in rescuer when there are no more to rescue Date: Tue, 25 Nov 2025 14:36:17 +0800 Message-Id: <20251125063617.671199-5-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20251125063617.671199-1-jiangshanlai@gmail.com> References: <20251125063617.671199-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. Also throttle the number of extra works. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 7cec9755b4e1..12d7d6503482 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3459,6 +3459,9 @@ static int worker_thread(void *__worker) * If @throttled and other PWQs are in mayday, requeue mayday for this PWQ * and let the rescuer handle other PWQs first. * If this is the only PWQ in mayday, process it regardless of @throttled. + * If this is the last PWQ leaving mayday, but the pool is in semi-mayday + * (idle workers exist while memory pressure is still on), process it unle= ss + * @throttled. */ static bool assign_rescuer_work(struct pool_workqueue *pwq, struct worker = *rescuer, bool throttled) { @@ -3475,10 +3478,38 @@ 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. + * 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 or + * this PWQ is throttled. + */ + if (!(pool->flags & POOL_MANAGER_ACTIVE) || + !list_empty(&pwq->wq->maydays) || throttled) + return false; + } + /* find the next work item 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