Heikki Linnakangas <heikki.linnakan...@enterprisedb.com> wrote: > LOG: shmemsize 3153112 > LOG: actual 2339864 > > Which is a pretty big overestimate, percentage-wise. Taking > RWConflictPool into account in PredicateLockShmemSize() fixes the > underestimate, but makes the overestimate correspondingly larger. > I've never compared the actual and estimated shmem sizes of other > parts of the backend, so I'm not sure how large discrepancies we > usually have, but that seems quite big. I found two things which probably explain that: (1) When HTABs are created, there is the max_size, which is what the PredicateLockShmemSize function must use in its calculations, and the init_size, which is what will initially be allocated (and so, is probably what you see in the usage at the end of the InitPredLocks function). That's normally set to half the maximum. (2) The predicate lock and lock target initialization code was initially copied and modified from the code for heavyweight locks. The heavyweight lock code adds 10% to the calculated maximum size. So I wound up doing that for PredicateLockTargetHash and PredicateLockHash, but didn't do it for SerializableXidHassh. Should I eliminate this from the first two, add it to the third, or leave it alone? So if the space was all in HTABs, you might expect shmemsize to be 110% of the estimated maximum, and actual (at the end of the init function) to be 50% of the estimated maximum. So the shmemsize would be (2.2 * actual) at that point. The difference isn't that extreme because the list-based pools now used for some structures are allocated at full size without padding.
In addition to the omission of the RWConflictPool (which is a biggie), the OldSerXidControlData estimate was only for a *pointer* to it, not the structure itself. The attached patch should correct the shmemsize numbers. -Kevin
*** a/src/backend/storage/lmgr/predicate.c --- b/src/backend/storage/lmgr/predicate.c *************** *** 1190,1200 **** PredicateLockShmemSize(void) size = add_size(size, hash_estimate_size(max_table_size, sizeof(SERIALIZABLEXID))); /* Head for list of finished serializable transactions. */ size = add_size(size, sizeof(SHM_QUEUE)); /* Shared memory structures for SLRU tracking of old committed xids. */ ! size = add_size(size, sizeof(OldSerXidControl)); size = add_size(size, SimpleLruShmemSize(NUM_OLDSERXID_BUFFERS, 0)); return size; --- 1190,1205 ---- size = add_size(size, hash_estimate_size(max_table_size, sizeof(SERIALIZABLEXID))); + /* rw-conflict pool */ + size = add_size(size, RWConflictPoolHeaderDataSize); + size = add_size(size, mul_size((Size) max_table_size, + RWConflictDataSize)); + /* Head for list of finished serializable transactions. */ size = add_size(size, sizeof(SHM_QUEUE)); /* Shared memory structures for SLRU tracking of old committed xids. */ ! size = add_size(size, sizeof(OldSerXidControlData)); size = add_size(size, SimpleLruShmemSize(NUM_OLDSERXID_BUFFERS, 0)); return size;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers