It seems to me that we're allocating shared memory for SLRU lwlocks twice,
unless I'm missing something.
I think you are right.

Did you check previous versions? i.e. should it be applyed to previous branches?? I suppose yes, to minimize code difference.

Also I'd like an idea to add Assert(offset <= SimpleLruShmemSize(nslots, nlsns)) at the end of SimpleLruInit()

SimpleLruShmemSize() calculates total SLRU shared memory size including lwlocks

SimpleLruInit() starts with line

shared = (SlruShared) ShmemInitStruct(name,
                                      SimpleLruShmemSize(nslots, nlsns),

which allocates SLRU shared memory (LWLocks size is included because
SimpleLruShmemSize() is used for size computation).

Following line allocates shared memory for LWLocks again:
shared->buffer_locks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * 

Attached patch fixes that by removing extra ShmemAlloc for SLRU.

Alexander Korotkov
Postgres Professional:
The Russian Postgres Company

Teodor Sigaev                                   E-mail:

Sent via pgsql-hackers mailing list (
To make changes to your subscription:

Reply via email to