From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 F091E2BF3CA for ; Fri, 21 Nov 2025 14:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763736817; cv=none; b=kHqveq+tlxFXRnT79zPSVnuLirm5i0wh1Mn5sYdR0MK/aCxQS4bYrXi3mycZwjEqIHa6JVT2F3Ah1G2aES3/GfIVV1k/LaneZBiDd+AAfL8RC6NvGHxl31Zx6y2D/9qyCDFkmUumBEVHimhNFrW6KVi+rYsOii9+I6qXBKy1iRI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763736817; c=relaxed/simple; bh=TqUK0b3ZkIXzfbg7wduBFvkfJIrRM40VcW0mYKVvKBM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=if9ZsIL4DWGAwhBScJNWiTd+c5pZjvyZGIJ25pjdcynpPXGKRuIXaZNzK5QBZpVXSWPdiJ5JD2U1JMRR/2/XPqoYTcnWE1ZbySQb1J0Z0pm+fqM9V5evDtPnGtneSx5fLEu3i+S2Vo4EYNBZSkxHIxDwj+arFujcapaS6nIr/s4= 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=W90RR5R4; arc=none smtp.client-ip=209.85.214.179 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="W90RR5R4" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-29555b384acso26177285ad.1 for ; Fri, 21 Nov 2025 06:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763736806; x=1764341606; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p6YD4PpXobfKz62Xmu/7uqs/ZS27iFgB2ieigbsb4iw=; b=W90RR5R4vaYQDUqsbmsx3ze66tTXv38d62D/NieaYThNeKa3lKQo2CDEfJfy0+Yrwx r2Z11Bcn8JkL5ybT1ZC2iLxrkBlEArqiHBp0WPoekPNEvl54JhG+/QIZEVi9r5Faa5CE lagv3Loj9NJxkHdJo2o5z73RrLB1CKOKNxkmAT1cRX7OMiDwJnVf7zV/hOVS7LYrr4hv WKRp3tC4+Q0zzWdvQ/TX8i1BH6lHtX3vUAg6y8uuLK8nmnRQWIJPFl+QaJaqkTH1OXj3 4SHNCjofHrFhgeHuI94EsJt8MFGKyjP3GmhM2Vtb61yGKl18fTgDxd7GNKhMQDC43dVF /nUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763736806; x=1764341606; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=p6YD4PpXobfKz62Xmu/7uqs/ZS27iFgB2ieigbsb4iw=; b=BabTLLQE19i8vzNyf+MlNoYMYDjPJMyW+f10WfGFKkYXn3ogCDMcnNwz2TjPWzxQwn 0SJ6aoYR27Mma3TC3bmxqyVwTE6JHsGb4Q+uFVaHC3xeWHlrins8jPtj5I1IcBQKrPjQ j1fgGU9dVbWIB4WWCGOU/MwPmuGQhwHYMccdKe3DuhuGCCFEuk4uC/xum/HgstXGfkDQ H5KWCc0TZqcFNcuhSPBhgHrTVKrJVYCQxPO9JoV83EBf6NWNZxrO28koQ++jh0LOI3sw 7BVfZSeG79Y7UbaKlopLoKi0LMAuhV33o0zQubwvexSoyqccypkf2DYhl5YmH04U7fxw iZkg== X-Gm-Message-State: AOJu0YzkU+uWmELgnLVfnrwnHt2Dam5HdxhTx3nbfJ+TAkQG0jkBdZdz TGJno/tGQXgJKOh1yj9dYnqpWHMcsEOPygnURJtZl/OH/7csOsZCcZB1FjIASzh0 X-Gm-Gg: ASbGncu8O/z0JuqnFiv8r+rg2r9CFppiwKzeqaSZpm6lRoxJEO2MZ8X7Ex3S7Ir1Uqe uxE3aZjly3uG2axvk/RAXC4jO6SKvy762C/0HihWrLTV7Wp4OeDSECqaVXbwBr/ii4mx5gRti9o plknol61kR3xii0nsJ0qSmLEvbprlYlqjoYzzok9Tsl+PDhzBwOcDZdPZoepn94VdWbSqziFkkt b5qfRIElaR6NTJoxy2IqViKqYN6lTglLKeo4zH6/cmF4aUAGPdcKUpXlDYhfEP1UIj89kCcGp+S hHfWAbOBS6604IJhCg8XzPsgmOoMaegoCfud3hs1LQM0LzvnYhP6SLatlpfvfYBBiXGqbLvwf3l dAnhdVmuxsEHh98ktRgsLyK2UPZp1MKe/KZvJD2uQlj52XbI96anveQu+vK/M0mPeKfxBAFzws9 tHBHQCeAKf6ss= X-Google-Smtp-Source: AGHT+IFJNnnwX/K3wbSOKAh7WoBFQ1JsZwlDJG61tSS2aHv6piAhBjCbkB+H/F9w+cxFRPEaxPcwHw== X-Received: by 2002:a17:903:3847:b0:295:24d7:3798 with SMTP id d9443c01a7336-29b6c3e3f31mr34472725ad.14.1763736806165; Fri, 21 Nov 2025 06:53:26 -0800 (PST) Received: from localhost ([240b:4004:a2:7900:ecf3:dec8:8c1e:4f6]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7c3f155d053sm6327145b3a.62.2025.11.21.06.53.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Nov 2025 06:53:25 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , ying chen , Lai Jiangshan Subject: [PATCH V3 0/7] workqueue: Factor the way to assign rescuer work Date: Fri, 21 Nov 2025 22:57:13 +0800 Message-Id: <20251121145720.342467-1-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lai Jiangshan Previously, the rescuer scanned for all matching work items at once and processed them within a single rescuer thread, which could cause one blocking work item to stall all others. Make the rescuer process work items one-by-one instead of slurping all matches in a single pass. Break the rescuer loop after finding and processing the first matching work item, then restart the search to pick up the next. This gives normal worker threads a chance to process other items which gives them the opportinity to be processed instead of waiting on the rescuer's queue and prevents a blocking work item from stalling the rest once memory pressure is relieved. Introduce a dummy cursor work item to avoid potentially O(N^2) rescans of the work list. The marker records the resume position for the next scan, eliminating redundant traversals. Change from v2: Renames. Change WARN_ON_ONCE() conditions in assign_work(). Remove the check whether the cursor is on the list in send_mayday() which has the benefit of enabling the ability to only process a limit number of work items per run and still allow the cursor in worklist between runs. Also remove the insertion of the cursor in send_mayday() and contain the code of handling the cursor in assign[_rescuer]_work(). Split patch. V2: https://lore.kernel.org/lkml/20251118093832.81920-1-jiangshanlai@gmail.com/ Changed from v1: Insert the marker and use it purely as iteration marker as Tejun request. It is hard to maintain the proper state of it, expecially maintaining it only in pool->worklist which also requires an unlikely path in the worker_thread() path. Add an unlikely path in the worker_thread() path(in assign_work()). Add other code in other place to make it not be treated like a work item. I'm sure all the paths have been covered now, but I still feel a bit nevous about it for future changes. Extra the code to assign work in the rescuer_thread() out as assign_rescue_work(). V1: https://lore.kernel.org/lkml/20251113163426.2950-1-jiangshanlai@gmail.com/ Lai Jiangshan (7): workqueue: Factor out assign_rescuer_work() workqueue: Only assign rescuer work when really needed workqueue: Don't rely on wq->rescuer to stop rescuer workqueue: Loop over in rescuer until all its work is done workqueue: Process rescuer work items one-by-one using a cursor workqueue: Limit number of processed works in rescuer per turn workqueue: Process extra works in rescuer when there are no more to rescue kernel/workqueue.c | 146 ++++++++++++++++++++++++++++++++------------- 1 file changed, 103 insertions(+), 43 deletions(-) -- 2.19.1.6.gb485710b