Re: Memory ordering issue in LWLockRelease, WakeupWaiters, WALInsertSlotRelease

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Memory ordering issue in LWLockRelease, WakeupWaiters, WALInsertSlotRelease
Date: 2014-02-18 19:23:26
Message-ID: 5303B32E.5050302@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 02/17/2014 10:36 PM, Andres Freund wrote:
> On 2014-02-17 22:30:54 +0200, Heikki Linnakangas wrote:
>> This is what I came up with. I like it, I didn't have to contort lwlocks as
>> much as I feared. I added one field to LWLock structure, which is used to
>> store the position of how far a WAL inserter has progressed. The LWLock code
>> calls it just "value", without caring what's stored in it, and it's used by
>> new functions LWLockWait and LWLockWakeup to implement the behavior the WAL
>> insertion slots have, to wake up other processes waiting for the slot
>> without releasing it.
>>
>> This passes regression tests, but I'll have to re-run the performance tests
>> with this. One worry is that if the padded size of the LWLock struct is
>> smaller than cache line, neighboring WAL insertion locks will compete for
>> the cache line. Another worry is that since I added a field to LWLock
>> struct, it might now take 64 bytes on platforms where it used to be 32 bytes
>> before. That wastes some memory.
>
> Why don't you allocate them in a separate tranche, from xlog.c? Then you
> can store them inside whatever bigger object you want, guaranteeing
> exactly the alignment you need. possibly you even can have the extra
> value in the enclosing object?

Good idea. New patch attached, doing that.

I'll try to find time on some multi-CPU hardware to performance test
this against current master, to make sure there's no regression.

- Heikki

Attachment Content-Type Size
xlogslot-to-lwlock-2.patch text/x-diff 51.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2014-02-18 19:39:27 Re: [COMMITTERS] pgsql: Add a GUC to report whether data page checksums are enabled.
Previous Message Heikki Linnakangas 2014-02-18 17:12:32 Re: Do you know the reason for increased max latency due to xlog scaling?