[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJhGHyB-8hU7W9HV1ctD67Q9d9o+tmhesYqtBcMEmO1+taF=cw@mail.gmail.com>
Date: Tue, 26 Dec 2023 17:13:40 +0800
From: Lai Jiangshan <jiangshanlai@...il.com>
To: Tejun Heo <tj@...nel.org>
Cc: linux-kernel@...r.kernel.org, Naohiro.Aota@....com, kernel-team@...a.com
Subject: Re: [PATCH 01/10] workqueue: Move pwq->max_active to wq->max_active
On Wed, Dec 20, 2023 at 3:25 PM Tejun Heo <tj@...nel.org> wrote:
> +static void wq_adjust_max_active(struct workqueue_struct *wq)
> +{
> + struct pool_workqueue *pwq;
> +
> + lockdep_assert_held(&wq->mutex);
> +
> + if ((wq->flags & WQ_FREEZABLE) && workqueue_freezing) {
> + wq->max_active = 0;
> + return;
> + }
> +
> + if (wq->max_active == wq->saved_max_active)
> + return;
> +
> + wq->max_active = wq->saved_max_active;
> +
If a work item gets queued now, it will get scheduled earlier than a
previous queued one which is still in the inactive list.
To solve it, I recommend adding wq->queue_max_active which will be
updated after the following code and used only when queue_work().
But it requires round-robin through PWQs the second time after
wq->queue_max_active is updated to catch the new inactivated items.
Or just keep pwq->max_active and will be
updated after activating inactivated items and used only when queue_work().
> + 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 (!list_empty(&pwq->inactive_works) &&
> + pwq->nr_active < wq->max_active)
> + pwq_activate_first_inactive(pwq);
> +
> + kick_pool(pwq->pool);
> +
> + raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
> + }
> +}
> +
Powered by blists - more mailing lists