77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.38 1998/10/08 18:29:57 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.38.2.1 1999/03/07 02:00:49 tgl Exp $
1111 *
1212 * NOTES
1313 * Outside modules can create a lock table and acquire/release
4242#include "storage/spin.h"
4343#include "storage/proc.h"
4444#include "storage/lock.h"
45- #include "utils/dynahash.h"
4645#include "utils/hsearch.h"
4746#include "utils/memutils.h"
4847#include "utils/palloc.h"
@@ -340,8 +339,8 @@ LockMethodTableInit(char *tabName,
340339 * to find the different locks.
341340 * ----------------------
342341 */
343- info .keysize = sizeof ( LOCKTAG ) ;
344- info .datasize = sizeof ( LOCK ) ;
342+ info .keysize = SHMEM_LOCKTAB_KEYSIZE ;
343+ info .datasize = SHMEM_LOCKTAB_DATASIZE ;
345344 info .hash = tag_hash ;
346345 hash_flags = (HASH_ELEM | HASH_FUNCTION );
347346
@@ -362,8 +361,8 @@ LockMethodTableInit(char *tabName,
362361 * the same lock, additional information must be saved (locks per tx).
363362 * -------------------------
364363 */
365- info .keysize = XID_TAGSIZE ;
366- info .datasize = sizeof ( XIDLookupEnt ) ;
364+ info .keysize = SHMEM_XIDTAB_KEYSIZE ;
365+ info .datasize = SHMEM_XIDTAB_DATASIZE ;
367366 info .hash = tag_hash ;
368367 hash_flags = (HASH_ELEM | HASH_FUNCTION );
369368
@@ -1491,35 +1490,26 @@ int
14911490LockShmemSize ()
14921491{
14931492 int size = 0 ;
1494- int nLockBuckets ,
1495- nLockSegs ;
1496- int nXidBuckets ,
1497- nXidSegs ;
14981493
1499- nLockBuckets = 1 << (int ) my_log2 ((NLOCKENTS - 1 ) / DEF_FFACTOR + 1 );
1500- nLockSegs = 1 << (int ) my_log2 ((nLockBuckets - 1 ) / DEF_SEGSIZE + 1 );
1494+ size += MAXALIGN (sizeof (PROC_HDR )); /* ProcGlobal */
1495+ size += MAXALIGN (MaxBackendId * sizeof (PROC )); /* each MyProc */
1496+ size += MAXALIGN (MaxBackendId * sizeof (LOCKMETHODCTL )); /* each
1497+ * lockMethodTable->ctl */
15011498
1502- nXidBuckets = 1 << (int ) my_log2 ((NLOCKS_PER_XACT - 1 ) / DEF_FFACTOR + 1 );
1503- nXidSegs = 1 << (int ) my_log2 ((nLockBuckets - 1 ) / DEF_SEGSIZE + 1 );
1499+ /* lockHash table */
1500+ size += hash_estimate_size (NLOCKENTS ,
1501+ SHMEM_LOCKTAB_KEYSIZE ,
1502+ SHMEM_LOCKTAB_DATASIZE );
15041503
1505- size += MAXALIGN ( NBACKENDS * sizeof ( PROC )); /* each MyProc */
1506- size += MAXALIGN ( NBACKENDS * sizeof ( LOCKMETHODCTL )); /* each
1507- * lockMethodTable->ctl */
1508- size += MAXALIGN ( sizeof ( PROC_HDR )); /* ProcGlobal */
1504+ /* xidHash table */
1505+ size += hash_estimate_size ( MaxBackendId ,
1506+ SHMEM_XIDTAB_KEYSIZE ,
1507+ SHMEM_XIDTAB_DATASIZE );
15091508
1510- size += MAXALIGN (my_log2 (NLOCKENTS ) * sizeof (void * ));
1511- size += MAXALIGN (sizeof (HHDR ));
1512- size += nLockSegs * MAXALIGN (DEF_SEGSIZE * sizeof (SEGMENT ));
1513- size += NLOCKENTS * /* XXX not multiple of BUCKET_ALLOC_INCR? */
1514- (MAXALIGN (sizeof (BUCKET_INDEX )) +
1515- MAXALIGN (sizeof (LOCK ))); /* contains hash key */
1516-
1517- size += MAXALIGN (my_log2 (NBACKENDS ) * sizeof (void * ));
1518- size += MAXALIGN (sizeof (HHDR ));
1519- size += nXidSegs * MAXALIGN (DEF_SEGSIZE * sizeof (SEGMENT ));
1520- size += NBACKENDS * /* XXX not multiple of BUCKET_ALLOC_INCR? */
1521- (MAXALIGN (sizeof (BUCKET_INDEX )) +
1522- MAXALIGN (sizeof (XIDLookupEnt ))); /* contains hash key */
1509+ /* Since the lockHash entry count above is only an estimate,
1510+ * add 10% safety margin.
1511+ */
1512+ size += size / 10 ;
15231513
15241514 return size ;
15251515}
0 commit comments