Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7e1fb4c

Browse files
committed
Fix double shared memory allocation.
SLRU buffer lwlocks are allocated twice by oversight in commit fe702a7 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.
1 parent 68f785f commit 7e1fb4c

File tree

1 file changed

+7
-3
lines changed
  • src/backend/access/transam

1 file changed

+7
-3
lines changed

src/backend/access/transam/slru.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,16 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
205205
shared->page_lru_count = (int *) (ptr + offset);
206206
offset += MAXALIGN(nslots * sizeof(int));
207207

208+
/* Initialize LWLocks */
209+
shared->buffer_locks = (LWLockPadded *) (ptr + offset);
210+
offset += MAXALIGN(nslots * sizeof(LWLockPadded));
211+
208212
if (nlsns > 0)
209213
{
210214
shared->group_lsn = (XLogRecPtr *) (ptr + offset);
211215
offset += MAXALIGN(nslots * nlsns * sizeof(XLogRecPtr));
212216
}
213217

214-
/* Initialize LWLocks */
215-
shared->buffer_locks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * nslots);
216-
217218
Assert(strlen(name) + 1 < SLRU_MAX_NAME_LENGTH);
218219
strlcpy(shared->lwlock_tranche_name, name, SLRU_MAX_NAME_LENGTH);
219220
shared->lwlock_tranche_id = tranche_id;
@@ -230,6 +231,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
230231
shared->page_lru_count[slotno] = 0;
231232
ptr += BLCKSZ;
232233
}
234+
235+
/* Should fit to estimated shmem size */
236+
Assert(ptr - (char *) shared <= SimpleLruShmemSize(nslots, nlsns));
233237
}
234238
else
235239
Assert(found);

0 commit comments

Comments
 (0)