[0/7] workqueue: Share the same PWQ for the CPUs of a pod and distribute max_active across pods
Message ID | 20231227145143.2399-1-jiangshanlai@gmail.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-12060-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1474934dyb; Wed, 27 Dec 2023 06:49:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IExwUnquDmUNnbID/nNwT/WWTwavbnunXgTdWqdPsrgsr6RTgDkvufHsZW2XkBBPZ3tYARj X-Received: by 2002:a05:6a00:2d5:b0:6d9:9fa8:a006 with SMTP id b21-20020a056a0002d500b006d99fa8a006mr7239399pft.57.1703688598073; Wed, 27 Dec 2023 06:49:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703688598; cv=none; d=google.com; s=arc-20160816; b=TuikrT46KxmS+Lzlu2jiHtWeXU4DqoC7Jz9iwxmZ5jGu0lzZGjy9CzxFdADRjJbREW MHX9Uvp7SCi5hdM2vJJ18F95+w2d26dsUVuvcWguSueu67y3vPBg5EWHwLND+MTkyNeA LpVSxHXZ2RK3uAy/6yiTVr+vdfmSxWmNZlair2DLjSSVDrS0SUZf80DrXtP1xdEZAdpC Ul9oXk2hP1WeMueHRCRawBMfYiJQV8VXB5OzSvgJFL72spY70z3awgenE7loF5G3kfWJ Xux4rMjLd/e8kI2aVZW9HMQi6aBhj7aMzLA7fy++45Yth4thA8nuLkvSNjwUCnY/WgKb 6qWQ== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=kkGPszZg+bkMDC2+6bc9aA8zr9G0a3W4ZkTQIcxWRD8=; fh=D3tykzs5kfL8or5UFa0pYJXKiDTL/XWMLXvAaUiWgeM=; b=n7sv/8VwIQcdtVThXJAXT0Sks4CpHzinMQnrN+qQIF4DlgQ5IcKhk4AG1glWvrKp4f H4NNf/0CMEfoFzJMH5KNt0u0YRiamKOYQXZCdMzDA3KRSbPUbvhl1JNcsTuexYIs7NW3 JqY+AQeTrGKiKtY3+MrQcg8f7w44iCxjFgRKy8g6lcDw0NujmIUTu5a/5iT1AaER/rt5 KqieIG2AarY/0hYrufikAmEWcVl7Fvrs41cuIzWEv9MAEWpuTtXAhEExNs48hJGRFNOj bKHbjvVoFfQJF2O0R9IlfHkSJUbZmQTFg7gpjIw0icMK8FWAAVEev+jS+FoPkdb9Yo/a ODvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fR2I1hg+; spf=pass (google.com: domain of linux-kernel+bounces-12060-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12060-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id dw5-20020a056a00368500b006d9c191dc57si4295635pfb.129.2023.12.27.06.49.57 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 06:49:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12060-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fR2I1hg+; spf=pass (google.com: domain of linux-kernel+bounces-12060-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12060-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 CE7182823CC for <ouuuleilei@gmail.com>; Wed, 27 Dec 2023 14:49:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6EB24594F; Wed, 27 Dec 2023 14:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fR2I1hg+" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 1A6614502C for <linux-kernel@vger.kernel.org>; Wed, 27 Dec 2023 14:49:41 +0000 (UTC) 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 Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5ca29c131ebso4093476a12.0 for <linux-kernel@vger.kernel.org>; Wed, 27 Dec 2023 06:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703688581; x=1704293381; 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=kkGPszZg+bkMDC2+6bc9aA8zr9G0a3W4ZkTQIcxWRD8=; b=fR2I1hg+ik2Ni0ap0u9BYkdWh8qlshHVFn+VhK+44EGh7r0oxNY5lIhZb86kECnq3b oxafnpnKLgeb/kQjqPMayV08k5/OGhYiilcIJ2y9j6i3+QzvKL2V38FiMpY0AjI8e2JA /qPYzyn1c8EVjgM6TANE2ZAOa5ggoO7vkO+jh0PCiJDsR2QlXbe3toOgwWlf/7/RmpcI 6ytRZqp94+tx6jaYghgNE5AE4+MNIPZaTsvjLzd4g692ptzcKhri7cuOBEphp4C+u6kx rCSteg+zn68C5HcUwrl+PWz7NR8/MSNIpH4tU+S+6ZMRFx/LNHTEWKUZ/oblUEW4GTyA MB/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703688581; x=1704293381; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kkGPszZg+bkMDC2+6bc9aA8zr9G0a3W4ZkTQIcxWRD8=; b=G8V/wrtRT45kIKBIe5B1HAXh99SWU3+b85ezpJq7HQVKpV1ppwHrDnDyDJe5ng4OEf 7QHcsxmIBH5om56LMVxARqmIWzoJnSMbG5NJA5O/awBGDr4ByINb1+Zs0JSJyHqU7oQf tAfPT34tYJAEpVDGwYQergc0LvM3V7daDY3vcOti4zgOP03VsI/q6oTCiSI7MFMaYxnZ T3UF43m0mc6Q3652OfywqdPF5OGvqUd/aHx38xvlXQMW62STpNaO7LFGSrpGbd+A3Cf7 LzRY/J9+wCM4/w1DBqvTxBPx1Ta1B033GXteW8iZ24XF4gjjtnsi1xZti/8XGfgu1q61 yfAw== X-Gm-Message-State: AOJu0Yxo+SShPueNRcgEPVc2QK8JiRu+6zDkbQ0/RSGdQev4PvnX4MRS WBt7y3/cjHKbi/jB1ygI6EOllMz6VKs= X-Received: by 2002:a17:90a:51a6:b0:28c:c31:244e with SMTP id u35-20020a17090a51a600b0028c0c31244emr3775116pjh.59.1703688580844; Wed, 27 Dec 2023 06:49:40 -0800 (PST) Received: from localhost ([47.254.32.37]) by smtp.gmail.com with ESMTPSA id w5-20020a17090a6b8500b0028bd0a43bc9sm13810502pjj.2.2023.12.27.06.49.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2023 06:49:40 -0800 (PST) From: Lai Jiangshan <jiangshanlai@gmail.com> To: linux-kernel@vger.kernel.org Cc: Tejun Heo <tj@kernel.org>, Naohiro.Aota@wdc.com, Lai Jiangshan <jiangshan.ljs@antgroup.com> Subject: [PATCH 0/7] workqueue: Share the same PWQ for the CPUs of a pod and distribute max_active across pods Date: Wed, 27 Dec 2023 22:51:36 +0800 Message-Id: <20231227145143.2399-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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786446975763796451 X-GMAIL-MSGID: 1786446975763796451 |
Series |
workqueue: Share the same PWQ for the CPUs of a pod and distribute max_active across pods
|
|
Message
Lai Jiangshan
Dec. 27, 2023, 2:51 p.m. UTC
From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
A different approach to fix the misbehavior can easily be exposed as reported in
http://lkml.kernel.org/r/dbu6wiwu3sdhmhikb2w6lns7b27gbobfavhjj57kwi2quafgwl@htjcc5oikcr3.
Lai Jiangshan (6):
workqueue: Reuse the default PWQ as much as possible
workqueue: Share the same PWQ for the CPUs of a pod
workqueue: Add pwq_calculate_max_active()
workqueue: Wrap common code into wq_adjust_pwqs_max_active()
workqueue: Addjust pwq's max_active when CPU online/offine
workqueue: Rename wq->saved_max_active to wq->max_active
Tejun Heo (1):
workqueue: Implement system-wide max_active enforcement for unbound
workqueues
include/linux/workqueue.h | 34 +++++-
kernel/workqueue.c | 217 ++++++++++++++++++++++----------------
2 files changed, 157 insertions(+), 94 deletions(-)
Comments
Hello, Lai. On Wed, Dec 27, 2023 at 10:51:42PM +0800, Lai Jiangshan wrote: > static int pwq_calculate_max_active(struct pool_workqueue *pwq) > { > + int pwq_nr_online_cpus; > + int max_active; > + > /* > * During [un]freezing, the caller is responsible for ensuring > * that pwq_adjust_max_active() is called at least once after > @@ -4152,7 +4158,18 @@ static int pwq_calculate_max_active(struct pool_workqueue *pwq) > if ((pwq->wq->flags & WQ_FREEZABLE) && workqueue_freezing) > return 0; > > - return pwq->wq->saved_max_active; > + if (!(pwq->wq->flags & WQ_UNBOUND)) > + return pwq->wq->saved_max_active; > + > + pwq_nr_online_cpus = cpumask_weight_and(pwq->pool->attrs->__pod_cpumask, cpu_online_mask); > + max_active = DIV_ROUND_UP(pwq->wq->saved_max_active * pwq_nr_online_cpus, num_online_cpus()); So, the problem with this approach is that we can end up segmenting max_active to too many too small pieces. Imagine a system with an AMD EPYC 9754 - 256 threads spread across 16 L3 caches. Let's say there's a workqueue used for IO (e.g. encryption) with the default CACHE affinity_scope ans max_active of 2 * nr_cpus, which isn't uncommon for this type of workqueues. The above code would limit each L3 domain to 32 concurent work items. Let's say a thread which is pinned to a CPU is issuing a lot of concurrent writes with the expectation of being able to saturate all the CPUs. It won't be able to even get close. The expected behavior is saturating all 256 CPUs on the system. The resulting behavior would be saturating an eight of them. The crux of the problem is that the desired worker pool domain and max_active enforcement domain don't match. We want to be fine grained with the former but pretty close to the whole system for the latter. Thanks.