mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, Naohiro.Aota@wdc.com,
	Lai Jiangshan <jiangshan.ljs@antgroup.com>,
	Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Subject: Re: [PATCH 6/7] workqueue: Implement system-wide max_active enforcement for unbound workqueues
Date: Thu, 28 Dec 2023 08:06:27 +0900	[thread overview]
Message-ID: <ZYyt821TugsgVx76@mtj.duckdns.org> (raw)
In-Reply-To: <20231227145143.2399-7-jiangshanlai@gmail.com>

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.

-- 
tejun

  reply	other threads:[~2023-12-27 23:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-27 14:51 [PATCH 0/7] workqueue: Share the same PWQ for the CPUs of a pod and distribute max_active across pods Lai Jiangshan
2023-12-27 14:51 ` [PATCH 1/7] workqueue: Reuse the default PWQ as much as possible Lai Jiangshan
2023-12-27 14:51 ` [PATCH 2/7] workqueue: Share the same PWQ for the CPUs of a pod Lai Jiangshan
2024-01-03  2:55   ` kernel test robot
2024-01-03  9:01     ` Lai Jiangshan
2023-12-27 14:51 ` [PATCH 3/7] workqueue: Add pwq_calculate_max_active() Lai Jiangshan
2023-12-27 14:51 ` [PATCH 4/7] workqueue: Wrap common code into wq_adjust_pwqs_max_active() Lai Jiangshan
2023-12-27 14:51 ` [PATCH 5/7] workqueue: Addjust pwq's max_active when CPU online/offine Lai Jiangshan
2023-12-27 14:51 ` [PATCH 6/7] workqueue: Implement system-wide max_active enforcement for unbound workqueues Lai Jiangshan
2023-12-27 23:06   ` Tejun Heo [this message]
2023-12-27 14:51 ` [PATCH 7/7] workqueue: Rename wq->saved_max_active to wq->max_active Lai Jiangshan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZYyt821TugsgVx76@mtj.duckdns.org \
    --to=tj@kernel.org \
    --cc=Naohiro.Aota@wdc.com \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=jiangshan.ljs@antgroup.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®