From: Suren Baghdasaryan <surenb@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Benjamin Segall <bsegall@google.com>,
mgorman@suse.de, Shakeel Butt <shakeelb@google.com>,
linux-mm <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
kernel-team <kernel-team@android.com>
Subject: Re: [PATCH 1/1] psi: eliminate kthread_worker from psi trigger scheduling mechanism
Date: Thu, 4 Jun 2020 12:20:10 -0700 [thread overview]
Message-ID: <CAJuCfpHNfOCRks_Ftbk7tEXsXs7AjPVUuxevKOtQWp9DCE4+8A@mail.gmail.com> (raw)
In-Reply-To: <20200604131215.GB4117@hirez.programming.kicks-ass.net>
On Thu, Jun 4, 2020 at 6:12 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Thu, May 28, 2020 at 12:54:42PM -0700, Suren Baghdasaryan wrote:
> > Each psi group requires a dedicated kthread_delayed_work and
> > kthread_worker. Since no other work can be performed using psi_group's
> > kthread_worker, the same result can be obtained using a task_struct and
> > a timer directly. This makes psi triggering simpler by removing lists
> > and locks involved with kthread_worker usage and eliminates the need for
> > poll_scheduled atomic use in the hot path.
> >
> > Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> > ---
> > This patch is meant to address Peter's request in [1] to pull
> > kthread_queue_delayed_work() out from under rq->lock. This should also address
> > the lockdep warning about possibility of a circular dependency described in [2]
>
> I think you could've just fixed kthread_queue_delayed_work(), that code
> is sub-optimal.
Ok, let me look into it some more. My understanding was that the
worker->lock in kthread_queue_delayed_work() was needed to synchronize
worker->delayed_work_list access. But maybe I'm missing something... I
assume you are talking about optimizing this beyond what
https://lkml.org/lkml/2020/5/4/1148 was doing?
BTW, any objections against taking https://lkml.org/lkml/2020/5/4/1148
? It's not the ultimate fix but it is an improvement since it gets
some of the operations that were unnecessarily under worker->lock out
of it.
>
> But I suppose this works too.
In PSI's case there is always one work for each worker, so the
delayed_work_list and work_list are not needed and therefore I can
replace kthread_worker machinery with a task and a timer.
I think I can simplify this a bit further. For example
group->poll_wakeup doesn't have to be an atomic. Originally I wanted
to avoid a possibility of a race when poll_timer_fn sets it and
psi_poll_worker resets it and as a result misses a wakeup, however if
psi_poll_worker resets it before calling psi_poll_work then there is
no harm in missing a wakeup because we called psi_poll_work and did
the required work anyway.
One question about this patch I'm not sure about and wanted to ask you
Peter is whether it's ok to call mod_timer from within a hotpath
(while holding rq->lock). As I described in the additional comment,
there is a possibility of a race between when I check timer_pending
and the call to mod_timer, so it's possible that mod_timer might be
called both from psi_poll_work (psi poll work handler) and from
psi_task_change (hotpath under rq->lock). I see that mod_timer takes
base->lock spinlock, and IIUC such a race might block the hotpath and
therefore is unacceptable. If this is true I'll need to revive the
poll_scheduled atomic to close this race and then I can change
mod_timer into add_timer.
WDYT? And sorry for my ignorance if this is a trivial question. I'm
not sure about the rules when it comes to rq->locks.
Thanks,
Suren.
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.
>
next prev parent reply other threads:[~2020-06-04 19:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-28 19:54 Suren Baghdasaryan
2020-06-04 13:12 ` Peter Zijlstra
2020-06-04 19:20 ` Suren Baghdasaryan [this message]
2020-06-09 2:56 ` Suren Baghdasaryan
2020-06-16 15:39 ` Suren Baghdasaryan
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=CAJuCfpHNfOCRks_Ftbk7tEXsXs7AjPVUuxevKOtQWp9DCE4+8A@mail.gmail.com \
--to=surenb@google.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shakeelb@google.com \
--cc=vincent.guittot@linaro.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