Re: [PATCH v5 3/5] workqueue: Make too_many_workers() return the worker excess

From: Valentin Schneider
Date: Mon Nov 28 2022 - 06:25:40 EST


On 22/11/22 10:17, Tejun Heo wrote:
> 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()?
>

Ack

>> {
>> 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);
>

I'll do that if this survives in the next revision :)

> Thanks.
>
> --
> tejun