[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y30uY/Y8pffIhrUp@slm.duckdns.org>
Date: Tue, 22 Nov 2022 10:17:39 -1000
From: Tejun Heo <tj@...nel.org>
To: Valentin Schneider <vschneid@...hat.com>
Cc: linux-kernel@...r.kernel.org,
Lai Jiangshan <jiangshanlai@...il.com>,
Peter Zijlstra <peterz@...radead.org>,
Frederic Weisbecker <frederic@...nel.org>,
Juri Lelli <juri.lelli@...hat.com>,
Phil Auld <pauld@...hat.com>,
Marcelo Tosatti <mtosatti@...hat.com>
Subject: Re: [PATCH v5 3/5] workqueue: Make too_many_workers() return the
worker excess
Hello,
On Tue, Nov 22, 2022 at 07:29:35PM +0000, Valentin Schneider wrote:
...
> The function currently returns true when
> (nr_idle - 2) * MAX_IDLE_WORKERS_RATIO >= nr_busy
> thus, the desired number of idle workers is expressed by
> (nr_idle - 2) * MAX_IDLE_WORKERS_RATIO == nr_busy - 1
> IOW
> nr_idle == ((nr_busy - 1) / MAX_IDLE_WORKERS_RATIO) + 2
> +/* How many idle workers should we get rid of, if any? */
> +static unsigned int worker_cull_count(struct worker_pool *pool)
Can we name it nr_workers_to_cull()?
> {
> bool managing = pool->flags & POOL_MANAGER_ACTIVE;
> int nr_idle = pool->nr_idle + managing; /* manager is considered idle */
> int nr_busy = pool->nr_workers - nr_idle;
>
> - return nr_idle > 2 && (nr_idle - 2) * MAX_IDLE_WORKERS_RATIO >= nr_busy;
> + lockdep_assert_held(&pool->lock);
> +
> + /*
> + * We keep at least 2 spare idle workers, but overall aim to keep at
> + * most (1 / MAX_IDLE_WORKERS_RATIO) workers idle.
> + */
> + return max(0, nr_idle - 2 - ((nr_busy - 1) / MAX_IDLE_WORKERS_RATIO));
I think we can do away with the subtraction on nr_busy. I don't think it'd
make any material difference, so maybe we can do:
return max(0, nr_idle - 2 - nr_busy / MAX_IDLE_WORKERS_RATIO);
Thanks.
--
tejun
Powered by blists - more mailing lists