Re: slow startup due to LWLockAssign() spinlock

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: slow startup due to LWLockAssign() spinlock
Date: 2014-04-24 16:33:49
Message-ID: 53593CED.4010204@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 04/24/2014 07:24 PM, Andres Freund wrote:
> On 2014-04-24 11:02:44 -0400, Tom Lane wrote:
>> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
>>> On 2014-04-24 15:56:45 +0300, Heikki Linnakangas wrote:
>>>> Another idea is to add an LWLockAssignBatch(int) function that assigns a
>>>> range of locks in one call. That would be very simple, and I think it would
>>>> be less likely to break things than a new global flag. I would be OK with
>>>> sneaking that into 9.4 still.
>>
>>> I don't really see the advantage tbh. Assuming we always can avoid the
>>> spinlock initially seems simple enough - and I have significant doubts
>>> that anything but buffer locks will need enough locks that it matters
>>> for other users.
>>
>> FWIW, I like the LWLockAssignBatch idea a lot better than the currently
>> proposed patch. LWLockAssign is a low-level function that has no business
>> making risky assumptions about the context it's invoked in.
>
> I don't think LWLockAssignBatch() is that easy without introducing
> layering violations. It can't just return a pointer out of the main
> lwlock array that then can be ++ed clientside because MainLWLockArray's
> stride isn't sizeof(LWLock).

Well, it could copy the pointers to an array of pointers that the caller
provides. Or palloc an array and return that. Allocating a large enough
array to hold NBuffers locks might not be nice, but if you do it in
batches of, say, 1k locks, that would make it fast enough. Makes the
caller a bit more complicated, but still might be worth it.

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2014-04-24 16:35:18 Re: 9.4 Proposal: Initdb creates a single table
Previous Message Andres Freund 2014-04-24 16:24:34 Re: slow startup due to LWLockAssign() spinlock