diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2017-07-21 13:31:49 +0300 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2017-07-21 13:31:49 +0300 |
commit | 38a4a5349c8f54a8d835675d395365d11628afac (patch) | |
tree | af26c32da6f2b52dfded6b2a8e1280c6ab8a31ec /src | |
parent | 5512427b19e79ac95535e7c942bd479db807f7be (diff) | |
download | postgresql-38a4a5349c8f54a8d835675d395365d11628afac.tar.gz postgresql-38a4a5349c8f54a8d835675d395365d11628afac.zip |
Fix double shared memory allocation.
SLRU buffer lwlocks are allocated twice by oversight in commit
fe702a7b3f9f2bc5bf6d173166d7d55226af82c8 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.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/access/transam/slru.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c index bbae5847f2d..ee111ca5391 100644 --- a/src/backend/access/transam/slru.c +++ b/src/backend/access/transam/slru.c @@ -204,15 +204,16 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, shared->page_lru_count = (int *) (ptr + offset); offset += MAXALIGN(nslots * sizeof(int)); + /* Initialize LWLocks */ + shared->buffer_locks = (LWLockPadded *) (ptr + offset); + offset += MAXALIGN(nslots * sizeof(LWLockPadded)); + if (nlsns > 0) { shared->group_lsn = (XLogRecPtr *) (ptr + offset); offset += MAXALIGN(nslots * nlsns * sizeof(XLogRecPtr)); } - /* Initialize LWLocks */ - shared->buffer_locks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * nslots); - Assert(strlen(name) + 1 < SLRU_MAX_NAME_LENGTH); strlcpy(shared->lwlock_tranche_name, name, SLRU_MAX_NAME_LENGTH); shared->lwlock_tranche_id = tranche_id; @@ -232,6 +233,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, shared->page_lru_count[slotno] = 0; ptr += BLCKSZ; } + + /* Should fit to estimated shmem size */ + Assert(ptr - (char *) shared <= SimpleLruShmemSize(nslots, nlsns)); } else Assert(found); |