Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp98442rdb; Thu, 25 Jan 2024 09:14:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuyC8U2yLm3LvsBWUTyfVa4TkIAAfxeNDmNj5mC1hBM79hAYCaUnIvCYzoi5SU1sM9vsnl X-Received: by 2002:a05:6e02:f8e:b0:361:a93c:aa8f with SMTP id v14-20020a056e020f8e00b00361a93caa8fmr30110ilo.35.1706202893720; Thu, 25 Jan 2024 09:14:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706202893; cv=pass; d=google.com; s=arc-20160816; b=z983qAkvJWKhQtJxCYbH9rdJQnPC8iYL0sMdLPKSKgL5P5JmPGAC7b5SJur7lcpUr7 lZoUClZir2vLRkINiRUtkjhL2glovK3fUImp19HDoSE0uo88eQNexXLrGVM/dMjwe6J2 tY/Y6ERZJ0f0OeAmaYZsaXb714fVdscZhXm6Fjh5kB2VhPj0xWbHYlf0Xt5zECQyEJQk SkKtzIhp3IZDr68Hei3PQcMTzscvXryB+rmxiplah+0kTC2vxoxlf0nPYhjRkQk7F8QJ L7JXj50r5Wx7vy9LIuP47KvonZ8mDS336tyBs/djxc3Cu7IiGe6pRf8+ExqnR4hxzEBv kHUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:sender:dkim-signature; bh=i22V5Ay/0Z0t7iq3fz0jQVVN6iBSQa9KI6LeZOPw1Yk=; fh=es77rsUC8OixoDFH1oB3/WG5bTQvXv6TAWW5Ou/zXa8=; b=Wd9q6kFlnOEHF0bX3DD7xISPgB7YUj0FmsN1zVkv9d3gQp0ynoYX2nDYKQUCOAjaKV 7Zq8ovY/6+DM7e8lkvrx+C/vr9OlMukzsZyCxplpyPgZYgtRTXL2FS7h1QcG0l9WTNKK r81hrFFDfejkV4V4uyTzaJNJ7lh5kNopaoJTsVIzPNrTXSOyWv2OObFh4FMRe20Hv1nz gh1gSMZcqTfu+eMMCZtKdFH59E1t2O1LJhbI3aGZ002qSeqSivGmO77BSWC+Ie+C2vI2 3ahDae+W1Js8vPjBXRhqVvS2/tVIcyoG+w9GILCKaeuDtAhVWupcuWG9cvjIwqF+N/2G jqRw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SltX3Bu8; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-39002-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39002-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r10-20020a63ce4a000000b005cdffd0ec5esi13424800pgi.477.2024.01.25.09.14.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 09:14:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39002-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SltX3Bu8; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-39002-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39002-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A3842296C9C for ; Thu, 25 Jan 2024 17:13:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A2B113E20A; Thu, 25 Jan 2024 17:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SltX3Bu8" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 E6EC513DB9F for ; Thu, 25 Jan 2024 17:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706202400; cv=none; b=qefLeuBQ9qOYSlyPwQ7fvO7HVtt72k/Ib6yMNnPIZnFlLu1lJJ17mE18ZgYrKGcp9FSdaNZD1BqrWLfej1OuWTy7ELNnqOqo1piywAUc7ndYVYbsLHARJNMFrtnfoHVsiToJhKWYM24KoehoRlX1YX/jKIgm6MoqWVd6i5HtZ/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706202400; c=relaxed/simple; bh=hED5zrI3UrH0UYfMBH7POtW6cuafV983xIchlmTIsO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XbYvtDN5OS/9J/rLT86wVrIxevmO0TZ3zw0W/lk4d6m5RgntyfBz9SJXWf9+mM/YDA1DvmzourRCSsdayeN4JkHmaSblCxtr7FekzSkr7iSrhFYiFS7BBtfxc9nwPy8ZLfqdvZx7r7riBK0C8702Zj+M+0uIiDLVWfsxQhWY2X8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SltX3Bu8; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6ddb1115e82so1358197b3a.0 for ; Thu, 25 Jan 2024 09:06:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706202398; x=1706807198; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=i22V5Ay/0Z0t7iq3fz0jQVVN6iBSQa9KI6LeZOPw1Yk=; b=SltX3Bu8cgBDI42r1yEp65jeLMFenAcma98Vyw7ydX5eZAaZf3kQSv+JO+O+ZIiSK3 Zwv4IYUJdg028thXVIjJ8gHD5N4ap2RED88WKgU14VVPvGrq22JfouIdXCcHWOUDtTu/ gv79tjMMj93WhOrpQ8p9Mh1EGeH2Ccx0kcK0Od8zAPUo0+fTttRW5ATHAIg+O9acWPI8 MF0ffuAVp5MAJfL5UmwrWD8XZeiIhOmPDQwqRiO0wnhGezhLLZZFu5hlOmwr+QkoafaP BFwjx7twU80JWSzRIcp9pKCrR5iOsRYmgrayQmFOra5e3YKo4L8tYxOJh1kRUbb2u4K3 oz7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706202398; x=1706807198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=i22V5Ay/0Z0t7iq3fz0jQVVN6iBSQa9KI6LeZOPw1Yk=; b=YIXfzyCraL4IL9l0OjKzNPtT2kK24NPT1YKpsvNZRsHV6IEdPM7dBcsR/ZoTLMbNes 15una8Fci1eQDYZ31gfYhSeshnKtL5lZt51LXkiWV5xQSS2kxPh0nduasGO6TQIZvNoS 9kkLVYcCz8L82nzLxUGOCCSofqsrlTkzLbXQf6Yp8C5rvrfpc2D1j8X9Wbjs5i7vQW8p ooQ64ueMmlv+RGmavvB6kC8b4nr8kvbo4cW3UGOa/zEcJw2YFWXzZQvU2Zc4OBqFUUK0 PgPval23nfzG3v3kxxBEyToOBhdD+Ew9zOzNaVivYYanzvnbDWGLItL1ZZy7qPXkz26G HvfQ== X-Gm-Message-State: AOJu0YwH3UQgb6v322GDWebPzATB64ERvsrL6IEtzS7Zv4M3C0nIbnNG 5ECxHX38EsHBExzY6BlfO4wMFZLo6+hAUjf6HqXYKfUn9uZsDRdp X-Received: by 2002:a05:6a00:87:b0:6d9:bbac:a34b with SMTP id c7-20020a056a00008700b006d9bbaca34bmr9798pfj.14.1706202398087; Thu, 25 Jan 2024 09:06:38 -0800 (PST) Received: from localhost (dhcp-141-239-144-21.hawaiiantel.net. [141.239.144.21]) by smtp.gmail.com with ESMTPSA id r24-20020a62e418000000b006ddc7de91e9sm1910091pfh.197.2024.01.25.09.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 09:06:37 -0800 (PST) Sender: Tejun Heo From: Tejun Heo To: jiangshanlai@gmail.com Cc: linux-kernel@vger.kernel.org, Naohiro.Aota@wdc.com, kernel-team@meta.com, Tejun Heo Subject: [PATCH 05/10] workqueue: Make wq_adjust_max_active() round-robin pwqs while activating Date: Thu, 25 Jan 2024 07:05:58 -1000 Message-ID: <20240125170628.2017784-6-tj@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240125170628.2017784-1-tj@kernel.org> References: <20240125170628.2017784-1-tj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit wq_adjust_max_active() needs to activate work items after max_active is increased. Previously, it did that by visiting each pwq once activating all that could be activated. While this makes sense with per-pwq nr_active, nr_active will be shared across multiple pwqs for unbound wqs. Then, we'd want to round-robin through pwqs to be fairer. In preparation, this patch makes wq_adjust_max_active() round-robin pwqs while activating. While the activation ordering changes, this shouldn't cause user-noticeable behavior changes. Signed-off-by: Tejun Heo --- kernel/workqueue.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 6a0ce3a3cca2..bfb6e951852a 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4707,7 +4707,7 @@ static int init_rescuer(struct workqueue_struct *wq) */ static void wq_adjust_max_active(struct workqueue_struct *wq) { - struct pool_workqueue *pwq; + bool activated; lockdep_assert_held(&wq->mutex); @@ -4727,19 +4727,26 @@ static void wq_adjust_max_active(struct workqueue_struct *wq) */ WRITE_ONCE(wq->max_active, wq->saved_max_active); - for_each_pwq(pwq, wq) { - unsigned long flags; - - /* this function can be called during early boot w/ irq disabled */ - raw_spin_lock_irqsave(&pwq->pool->lock, flags); - - while (pwq_activate_first_inactive(pwq)) - ; + /* + * Round-robin through pwq's activating the first inactive work item + * until max_active is filled. + */ + do { + struct pool_workqueue *pwq; - kick_pool(pwq->pool); + activated = false; + for_each_pwq(pwq, wq) { + unsigned long flags; - raw_spin_unlock_irqrestore(&pwq->pool->lock, flags); - } + /* can be called during early boot w/ irq disabled */ + raw_spin_lock_irqsave(&pwq->pool->lock, flags); + if (pwq_activate_first_inactive(pwq)) { + activated = true; + kick_pool(pwq->pool); + } + raw_spin_unlock_irqrestore(&pwq->pool->lock, flags); + } + } while (activated); } __printf(1, 4) -- 2.43.0