Re: s_lock() seems too aggressive for machines with many sockets

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Nils Goroll <slink(at)schokola(dot)de>, Jan Wieck <jan(at)wi3ck(dot)info>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: s_lock() seems too aggressive for machines with many sockets
Date: 2015-06-10 14:56:06
Message-ID: 20150610145606.GB10551@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2015-06-10 10:25:32 -0400, Tom Lane wrote:
> Andres Freund <andres(at)anarazel(dot)de> writes:
> > Unfortunately there's no portable futex support. That's what stopped us
> > from adopting them so far. And even futexes can be significantly more
> > heavyweight under moderate contention than our spinlocks - It's rather
> > easy to reproduce scenarios where futexes cause significant slowdown in
> > comparison to spinning in userspace (just reproduce contention on a
> > spinlock where the protected area will be *very* short - i.e. no cache
> > misses, no branches or such).
>
> Which, you'll note, is the ONLY case that's allowed by our coding rules
> for spinlock use. If there are any locking sections that are not very
> short straight-line code, or at least code with easily predicted branches,
> we need to fix those before we worry about the spinlock mechanism per
> se.

We haven't followed that all that strictly imo. While lwlocks are a bit
less problematic in 9.5 (as they take far fewer spinlocks), they're
still far from perfect as we manipulate linked lists while holding a
lock. We malso do lots of hard to predict stuff while the buffer header
spinlock is held...

> Optimizing for misuse of the mechanism is not the way.

Agreed. I'm not particularly interested in optimizing spinlocks. We
should get rid of most.

Greetings,

Andres Freund

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2015-06-10 14:59:33 Re: s_lock() seems too aggressive for machines with many sockets
Previous Message Nils Goroll 2015-06-10 14:55:31 Re: s_lock() seems too aggressive for machines with many sockets