lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 22 Sep 2021 13:37:36 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     nsaenzju@...hat.com
Cc:     akpm@...ux-foundation.org, frederic@...nel.org,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        tglx@...utronix.de, cl@...ux.com, juri.lelli@...hat.com,
        mingo@...hat.com, mtosatti@...hat.com, nilal@...hat.com,
        mgorman@...e.de, ppandit@...hat.com, williams@...hat.com,
        bigeasy@...utronix.de, anna-maria@...utronix.de,
        linux-rt-users@...r.kernel.org
Subject: Re: [PATCH 2/6] mm/swap: Introduce alternative per-cpu LRU cache
 locking

On Wed, Sep 22, 2021 at 10:47:07AM +0200, nsaenzju@...hat.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ