From: Peter Zijlstra <peterz@infradead.org>
To: nsaenzju@redhat.com
Cc: akpm@linux-foundation.org, frederic@kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
tglx@linutronix.de, cl@linux.com, juri.lelli@redhat.com,
mingo@redhat.com, mtosatti@redhat.com, nilal@redhat.com,
mgorman@suse.de, ppandit@redhat.com, williams@redhat.com,
bigeasy@linutronix.de, anna-maria@linutronix.de,
linux-rt-users@vger.kernel.org
Subject: Re: [PATCH 2/6] mm/swap: Introduce alternative per-cpu LRU cache locking
Date: Wed, 22 Sep 2021 13:37:36 +0200 [thread overview]
Message-ID: <20210922113736.GP4323@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <0ec733daf2daaf8a6f5b1fbf56676b9892d5bf73.camel@redhat.com>
On Wed, Sep 22, 2021 at 10:47:07AM +0200, nsaenzju@redhat.com wrote:
> On Wed, 2021-09-22 at 00:03 +0200, Peter Zijlstra wrote:
> > On Tue, Sep 21, 2021 at 06:13:20PM +0200, Nicolas Saenz Julienne wrote:
> > > +static inline void lru_cache_lock(struct lru_cache_locks *locks)
> > > +{
> > > + if (static_branch_unlikely(&remote_pcpu_cache_access)) {
> > > + /* Avoid migration between this_cpu_ptr() and spin_lock() */
> > > + migrate_disable();
> > > + spin_lock(this_cpu_ptr(&locks->spin));
> > > + } else {
> > > + local_lock(&locks->local);
> > > + }
> > > +}
> >
> > > +static inline void lru_cache_unlock(struct lru_cache_locks *locks)
> > > +{
> > > + if (static_branch_unlikely(&remote_pcpu_cache_access)) {
> > > + spin_unlock(this_cpu_ptr(&locks->spin));
> > > + migrate_enable();
> > > + } else {
> > > + local_unlock(&locks->local);
> > > + }
> > > +}
> >
> > *why* use migrate_disable(), that's horrible!
>
> I was trying to be mindful of RT. They don't appreciate people taking spinlocks
> just after having disabled preemption.
>
> I think getting local_lock(&locks->local) is my only option then. But it adds
> an extra redundant spinlock in the RT+NOHZ_FULL case.
That doesn't make it less horrible. The fundamental problem you seem to
have is that you have to do the this_cpu thing multiple times.
If instead you make sure to only ever do the per-cpu deref *once* and
then make sure you use the same lru_rotate.pvec as you used
lru_rotate.locks, it all works out much nicer.
Then you can write things like:
struct lru_rotate *lr = raw_cpu_ptr(&lru_rotate);
frob_lock(&lr->locks);
frob_pvec(&lr->pvec);
frob_unlock(&lr->locks);
and it all no longer matters if you got this or that CPU's instance.
After all, you no longer rely on per-cpu ness for serialization but the
lock.
next prev parent reply other threads:[~2021-09-22 11:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-21 16:13 [PATCH 0/6] mm: Remote LRU per-cpu pagevec cache/per-cpu page list drain support Nicolas Saenz Julienne
2021-09-21 16:13 ` [PATCH 1/6] mm/swap: Introduce lru_cpu_needs_drain() Nicolas Saenz Julienne
2021-09-21 16:13 ` [PATCH 2/6] mm/swap: Introduce alternative per-cpu LRU cache locking Nicolas Saenz Julienne
2021-09-21 22:03 ` Peter Zijlstra
2021-09-22 8:47 ` nsaenzju
2021-09-22 9:20 ` Sebastian Andrzej Siewior
2021-09-22 9:50 ` nsaenzju
2021-09-22 11:37 ` Peter Zijlstra [this message]
2021-09-22 11:43 ` nsaenzju
2021-09-21 16:13 ` [PATCH 3/6] mm/swap: Allow remote LRU cache draining Nicolas Saenz Julienne
2021-09-21 16:13 ` [PATCH 4/6] mm/page_alloc: Introduce alternative per-cpu list locking Nicolas Saenz Julienne
2021-09-21 16:13 ` [PATCH 5/6] mm/page_alloc: Allow remote per-cpu page list draining Nicolas Saenz Julienne
2021-09-21 16:13 ` [PATCH 6/6] sched/isolation: Enable 'remote_pcpu_cache_access' on NOHZ_FULL systems Nicolas Saenz Julienne
2021-09-21 17:51 ` [PATCH 0/6] mm: Remote LRU per-cpu pagevec cache/per-cpu page list drain support Andrew Morton
2021-09-21 17:59 ` Vlastimil Babka
2021-09-22 11:28 ` Peter Zijlstra
2021-09-22 22:09 ` Thomas Gleixner
2021-09-23 7:12 ` Vlastimil Babka
2021-09-23 10:36 ` Thomas Gleixner
2021-09-27 9:30 ` nsaenzju
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=20210922113736.GP4323@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=anna-maria@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=cl@linux.com \
--cc=frederic@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=nilal@redhat.com \
--cc=nsaenzju@redhat.com \
--cc=ppandit@redhat.com \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).