Double shared memory allocation for SLRU LWLocks

From: Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Double shared memory allocation for SLRU LWLocks
Date: 2017-07-10 12:08:13
Message-ID: CAPpHfdvd3cBpY4wEPZdUyY4bgRn0W6+8M3vtesX=M3goni2GDQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, all!

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

SimpleLruShmemSize() calculates total SLRU shared memory size including
lwlocks size.

SimpleLruInit() starts with line

shared = (SlruShared) ShmemInitStruct(name,
SimpleLruShmemSize(nslots, nlsns),
&found);

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) *
nslots);

Attached patch fixes that by removing extra ShmemAlloc for SLRU.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachment Content-Type Size
fix-slru-lwlock-shmem-double-allocation.patch application/octet-stream 1.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2017-07-10 12:32:37 Re: List of hostaddrs not supported
Previous Message fcs1 2017-07-10 11:39:17 BUG #14738: ALTER SERVER for foregin servers not working