Commit 7e1fb4c5 authored by Teodor Sigaev's avatar Teodor Sigaev

Fix double shared memory allocation.

SLRU buffer lwlocks are allocated twice by oversight in commit
fe702a7b where that locks were moved to
separate tranche. The bug doesn't have user-visible effects except small
overspending of shared memory.

Backpatch to 9.6 where it was introduced.

Alexander Korotkov with small editorization by me.
parent 68f785fd
...@@ -205,15 +205,16 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, ...@@ -205,15 +205,16 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
shared->page_lru_count = (int *) (ptr + offset); shared->page_lru_count = (int *) (ptr + offset);
offset += MAXALIGN(nslots * sizeof(int)); offset += MAXALIGN(nslots * sizeof(int));
/* Initialize LWLocks */
shared->buffer_locks = (LWLockPadded *) (ptr + offset);
offset += MAXALIGN(nslots * sizeof(LWLockPadded));
if (nlsns > 0) if (nlsns > 0)
{ {
shared->group_lsn = (XLogRecPtr *) (ptr + offset); shared->group_lsn = (XLogRecPtr *) (ptr + offset);
offset += MAXALIGN(nslots * nlsns * sizeof(XLogRecPtr)); offset += MAXALIGN(nslots * nlsns * sizeof(XLogRecPtr));
} }
/* Initialize LWLocks */
shared->buffer_locks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * nslots);
Assert(strlen(name) + 1 < SLRU_MAX_NAME_LENGTH); Assert(strlen(name) + 1 < SLRU_MAX_NAME_LENGTH);
strlcpy(shared->lwlock_tranche_name, name, SLRU_MAX_NAME_LENGTH); strlcpy(shared->lwlock_tranche_name, name, SLRU_MAX_NAME_LENGTH);
shared->lwlock_tranche_id = tranche_id; shared->lwlock_tranche_id = tranche_id;
...@@ -230,6 +231,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, ...@@ -230,6 +231,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
shared->page_lru_count[slotno] = 0; shared->page_lru_count[slotno] = 0;
ptr += BLCKSZ; ptr += BLCKSZ;
} }
/* Should fit to estimated shmem size */
Assert(ptr - (char *) shared <= SimpleLruShmemSize(nslots, nlsns));
} }
else else
Assert(found); Assert(found);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment