From patchwork Fri Feb 9 00:11:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 198710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp546145dyd; Thu, 8 Feb 2024 16:41:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYe9VBwFF90GaH0oWWBZfvMQIHxpLp09N97LQWd1ZRVLsoFgK7Ns2qVCwugojOil34s1xt X-Received: by 2002:a05:6870:164f:b0:219:f5f1:d60 with SMTP id c15-20020a056870164f00b00219f5f10d60mr43095oae.56.1707439316211; Thu, 08 Feb 2024 16:41:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707439316; cv=pass; d=google.com; s=arc-20160816; b=kIiBRUllJPzCmVLduIrcEFfWzJix4z5MmYVKPME03phPoPuuN3gAkeccqszV+8sElO ZdfLxmJcYN/kIAkP0n2CrM5/r7QO+vJEjWj8AqiLuelYSmISkjmkyRyiNJa70xzeWmaC JW5Ld0Cz+FkOwhG9ApcfI+i/5Ezh49wjlNvFQm42akXYgh8cYJuUmVGvs+P9EqWZ8TTQ fMh3PNOlKjLP2THE7d59Crahsqpx3/mdW/vRb5TBSYfQuSSh/Q3fzRfoF0OnkOMh4Qvu dU5aaJ/azEpNEGObu9Po0ByvzyNkZ65TZ9vg76/6c6salmWSYYg9pyTGwAeuFKGw6X/V /ztg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date:sender :dkim-signature; bh=XQZvJgedD8LlLuZzJKiEJoT/ySdzdPZ0zmmi9A45YQg=; fh=dFfGewdC3NCfOqXM3zMXb2x/+EGGLCX8DS8V2ea8ik4=; b=Trz3XnKIofznOuKQD/dvHmbb7GyyJQ2cHmRnRENqpMLx+N0jwW6gPGOFO778G53txU zb55INGrjr3PVWq3VPtWkvPWAxwKQuXnM4BjAcW2qOuXbEnUWiKfwZtIVnkF2bGPJndx qVMg8OVJhXc2jzX+5FPXXj98WTWBjxkdUEhuWNPlcVooRXtGYzJCyE7UOU41IZ21LNpC AiGEdXl1cVqmE2pFziArK2O9qiHDAlNZpSaiaDBnD7GhT77bBfwHwiyalqEE8eWPas+8 B5w6CqK5lPlkXmhTZwz8JggWpc3sS5l05v3xJ9xScevXuArrZwTfNmmWgs1px87kEnKy U1cg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FtVG1Hk1; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-58893-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58893-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWuAkFEkq4aHK5yCtkL1vszQIsQ8lCPgTMRDLAPrU5+7WbJkW+mP9Oijttlc4etzOZ72Iovd10jQlwO3VDKiVny1y3vZQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k63-20020a638442000000b005d92a3f1196si651315pgd.592.2024.02.08.16.41.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 16:41:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58893-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FtVG1Hk1; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-58893-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58893-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 78A92B242EE for ; Fri, 9 Feb 2024 00:12:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED323EBB; Fri, 9 Feb 2024 00:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FtVG1Hk1" 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 9E362364 for ; Fri, 9 Feb 2024 00:11:59 +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=1707437521; cv=none; b=X0INzOEn7H1V8MBLOmbWR7YEKLqOOWcuZloC0fRCqSBX3qtXLbQXJ1mcQvcbsHgh4Yun2wOzOVrIIK/z+g0H5y75WkuRYjOzif0EWE3FLrHC/TX/+WgBpYNj3XHp1MuhjJc1PBd6XUGk/IHmkS70ECmYbkYlPqgEsWlxdDR2lhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707437521; c=relaxed/simple; bh=MrtQG68CQj3jGguwb2kDauw/NcdRMELRTxmQJt6Xpy8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=HwzSgHzdUX/0p32Jl2vg3mdERE8XffGKkNGtHk5Gc/Iv8C/e7lmShv98ADbJ0DKVPIZFzvREzbl9zb49lNaJlSVdjZDHHsxwBvBvlKt4n1+YzZVTjj2vC8koLt6bEzX/kNZ19mvbBvCBK70wl98y6appTDsltr5eBKruZvALxwY= 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=FtVG1Hk1; arc=none smtp.client-ip=209.85.210.170 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-f170.google.com with SMTP id d2e1a72fcca58-6e062fa6e00so266145b3a.1 for ; Thu, 08 Feb 2024 16:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707437519; x=1708042319; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=XQZvJgedD8LlLuZzJKiEJoT/ySdzdPZ0zmmi9A45YQg=; b=FtVG1Hk17IBgMwfvOLZCIEQCeuf8J/qEoJ6rAVoUH+vkR5Heac1N5TRHk9Thwe3W0p gKBErW/pV153rUDZ7HYqBjUoZjMTzwxcHz+aEUngqmz/9v9VF/quI/H8eQBfsojUtP/K wiwA5urRNjrpcWZtxayr8Obk79EVpJoB91+fqlGgY84sZuHzAfIN1nq1rpkCefAyEZCe QTNVRNAs7BS3iUt8vXpBeyASLHl+TlWn56gwmxJkyLmbfMP0vzPXUryT3TVdxZX6H74P 15MSTqIxBdSHX6L2nk/Exx4xCBdN0kc85QGyDjD+hHH0BM2Hgm4X7SG4P8gzAPWSrp6e exuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707437519; x=1708042319; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XQZvJgedD8LlLuZzJKiEJoT/ySdzdPZ0zmmi9A45YQg=; b=fC2EVhRWJt4tGpus1dHPuQ7IGhv9krs7tISVsWIhOJGOPSWM7JnnmKkwkLAJxevsp1 IYqUoTgYE/l/LW0c4yJRBmcn+mVk8rIZnUprck0M9ehD9U8Bse7M1oqXPVMMUt2Q6Mai iLRgInaQHmbtLNnRCAAOywXbeF6Bb8M6UPIRfP4bdAZN5V8YxJpJjN6FUliqau87DGrO lPgal8UmYIpcc0iAntenP12OejqAEvRTsev/Qo0hFvPbqtfrzNuL90TOV5yDwVjHTi8/ rambh2Lj6XZ4Izkjo5L9YeQh7uMeobH1uwwFiVJCl6v9I+5H8lwb3F7G1AzOtXuVgncT ZO0w== X-Gm-Message-State: AOJu0YyXPuCA9iEU3BFFhfNsQZIdCKOORd/gZ42Mu1TdkJy7GpRpffn8 YfluTgwE0zzQG1VG/MWFk4a4RN8MS2Lgy5SBgqC/o3oBcKRgoZrb4pYB0cbshT0= X-Received: by 2002:a05:6a00:1393:b0:6e0:4b09:a9c4 with SMTP id t19-20020a056a00139300b006e04b09a9c4mr136174pfg.2.1707437518757; Thu, 08 Feb 2024 16:11:58 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWk7lyW/tEgtaQBxQGucpaotDVXiVjuNQymjGei6+VSK0+3ar7g8KPGJ7xfOmttyRTSguFKepmdvOmSs+jSiBPkBgbXjpNG6eFpvHKJy4+hYbSFgJQWCCYCoWGGnYbsb3u7OCCFkb3CJ+5Csw7oe2FjC2+YDxJL Received: from localhost ([2620:10d:c090:400::4:3c45]) by smtp.gmail.com with ESMTPSA id fn6-20020a056a002fc600b006e03c2f96fbsm367245pfb.148.2024.02.08.16.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 16:11:58 -0800 (PST) Sender: Tejun Heo Date: Thu, 8 Feb 2024 14:11:56 -1000 From: Tejun Heo To: Marek Szyprowski Cc: "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Lai Jiangshan Subject: [PATCH 1/2 wq/for-6.9] workqueue: Implement workqueue_set_min_active() Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790379888240773769 X-GMAIL-MSGID: 1790379888240773769 Since 5797b1c18919 ("workqueue: Implement system-wide nr_active enforcement for unbound workqueues"), unbound workqueues have separate min_active which sets the number of interdependent work items that can be handled. This value is currently initialized to WQ_DFL_MIN_ACTIVE which is 8. This isn't high enough for some users, let's add an interface to adjust the setting. Signed-off-by: Tejun Heo --- include/linux/workqueue.h | 2 ++ kernel/workqueue.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -553,6 +553,8 @@ extern bool flush_rcu_work(struct rcu_wo extern void workqueue_set_max_active(struct workqueue_struct *wq, int max_active); +extern void workqueue_set_min_active(struct workqueue_struct *wq, + int min_active); extern struct work_struct *current_work(void); extern bool current_is_workqueue_rescuer(void); extern bool workqueue_congested(int cpu, struct workqueue_struct *wq); --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5627,6 +5627,33 @@ void workqueue_set_max_active(struct wor EXPORT_SYMBOL_GPL(workqueue_set_max_active); /** + * workqueue_set_min_active - adjust min_active of an unbound workqueue + * @wq: target unbound workqueue + * @min_active: new min_active value + * + * Set min_active of an unbound workqueue. Unlike other types of workqueues, an + * unbound workqueue is not guaranteed to be able to process max_active + * interdependent work items. Instead, an unbound workqueue is guaranteed to be + * able to process min_active number of interdependent work items which is + * %WQ_DFL_MIN_ACTIVE by default. + * + * Use this function to adjust the min_active value between 0 and the current + * max_active. + */ +void workqueue_set_min_active(struct workqueue_struct *wq, int min_active) +{ + /* min_active is only meaningful for non-ordered unbound workqueues */ + if (WARN_ON((wq->flags & (WQ_BH | WQ_UNBOUND | __WQ_ORDERED)) != + WQ_UNBOUND)) + return; + + mutex_lock(&wq->mutex); + wq->saved_min_active = clamp(min_active, 0, wq->saved_max_active); + wq_adjust_max_active(wq); + mutex_unlock(&wq->mutex); +} + +/** * current_work - retrieve %current task's work struct * * Determine if %current task is a workqueue worker and what it's working on.