From: Valentin Schneider <vschneid@redhat.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Lai Jiangshan <jiangshanlai@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <frederic@kernel.org>,
Juri Lelli <juri.lelli@redhat.com>, Phil Auld <pauld@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: Re: [PATCH v6 3/4] workqueue: Convert the idle_timer to a timer + work_struct
Date: Thu, 01 Dec 2022 11:01:24 +0000 [thread overview]
Message-ID: <xhsmh5yevl75n.mognet@vschneid.remote.csb> (raw)
In-Reply-To: <Y4fFzBrjZiOQO9Te@slm.duckdns.org>
On 30/11/22 11:06, Tejun Heo wrote:
> On Mon, Nov 28, 2022 at 06:31:08PM +0000, Valentin Schneider wrote:
>> @@ -1806,7 +1808,9 @@ static void worker_enter_idle(struct worker *worker)
>> /* idle_list is LIFO */
>> list_add(&worker->entry, &pool->idle_list);
>>
>> - if (too_many_workers(pool) && !timer_pending(&pool->idle_timer))
>> + if (too_many_workers(pool) &&
>> + !timer_pending(&pool->idle_timer) &&
>> + !work_pending(&pool->idle_cull_work))
>
> Just checking the timer should be enough here, I think.
>
That would let the timer be re-armed when the cull work is pending, which
itself will re-arm the timer to the next non-culled idle worker expiry (if
there is any remaining).
Not an issue per se, it's just that having the cull work pending is a
"promise" that the timer will be re-armed if and when necessary.
I think in cases where the cull work doesn't get to run for a while, not
having the extra work_pending() check and just arming the timer in
worker_enter_idle() might be cheaper than repeatedly checking both
timer_pending() and work_pending(), but otherwise I would assume not arming
the timer would be preferred.
>> mod_timer(&pool->idle_timer, jiffies + IDLE_WORKER_TIMEOUT);
>>
>> /* Sanity check nr_running. */
>> @@ -2019,17 +2023,56 @@ static void destroy_worker(struct worker *worker)
>> wake_up_process(worker->task);
>> }
>>
>> +/*
>> + * idle_worker_timeout - check if some idle workers can now be deleted.
>
> Might as well turn it into a proper function comment starting w/ "/**" and
> with argument list.
>
Ack.
>> + *
>> + * The timer is armed in worker_enter_idle(). Note that it isn't disarmed in
>> + * worker_leave_idle(), as a worker flicking between idle and active while its
>> + * pool is at the too_many_workers() tipping point would cause too much timer
>> + * housekeeping overhead. Since IDLE_WORKER_TIMEOUT is long enough, we just let
>> + * it expire and re-evaluate things from there.
>> + */
>> static void idle_worker_timeout(struct timer_list *t)
>> {
>> struct worker_pool *pool = from_timer(pool, t, idle_timer);
>> + bool do_cull = false;
>> +
>> + if (work_pending(&pool->idle_cull_work))
>> + return;
>>
>> raw_spin_lock_irq(&pool->lock);
>>
>> - while (too_many_workers(pool)) {
>> + if (too_many_workers(pool)) {
>> struct worker *worker;
>> unsigned long expires;
>>
>> /* idle_list is kept in LIFO order, check the last one */
>> + worker = list_entry(pool->idle_list.prev, struct worker, entry);
>> + expires = worker->last_active + IDLE_WORKER_TIMEOUT;
>> + do_cull = !time_before(jiffies, expires);
>> +
>> + if (!do_cull)
>> + mod_timer(&pool->idle_timer, expires);
>> + }
>> + raw_spin_unlock_irq(&pool->lock);
>> +
>> + if (do_cull)
>> + queue_work(system_unbound_wq, &pool->idle_cull_work);
>> +}
>> +
>> +/*
>> + * idle_cull_fn - cull workers that have been idle for too long.
>> + */
>
> Please turn it into a full function comment or drop the wings (ie. make it
> an one-liner).
>
Patch 4/4 adds the rest of the comment, but I can make the whole thing
appear in patch 4 if you prefer.
next prev parent reply other threads:[~2022-12-01 11:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 18:31 [PATCH v6 0/4] workqueue: destroy_worker() vs isolated CPUs Valentin Schneider
2022-11-28 18:31 ` [PATCH v6 1/4] workqueue: Protects wq_unbound_cpumask with wq_pool_attach_mutex Valentin Schneider
2022-11-28 18:31 ` [PATCH v6 2/4] workqueue: Factorize unbind/rebind_workers() logic Valentin Schneider
2022-11-28 18:31 ` [PATCH v6 3/4] workqueue: Convert the idle_timer to a timer + work_struct Valentin Schneider
2022-11-30 21:06 ` Tejun Heo
2022-12-01 11:01 ` Valentin Schneider [this message]
2022-11-28 18:31 ` [PATCH v6 4/4] workqueue: Unbind kworkers before sending them to exit() Valentin Schneider
2022-12-01 3:01 ` Lai Jiangshan
2022-12-01 10:37 ` Valentin Schneider
2022-11-30 21:06 ` [PATCH v6 0/4] workqueue: destroy_worker() vs isolated CPUs Tejun Heo
2022-12-01 3:05 ` 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=xhsmh5yevl75n.mognet@vschneid.remote.csb \
--to=vschneid@redhat.com \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pauld@redhat.com \
--cc=peterz@infradead.org \
--cc=tj@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®