7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
* NOTES
13
13
* Outside modules can create a lock table and acquire/release
42
42
#include "storage/spin.h"
43
43
#include "storage/proc.h"
44
44
#include "storage/lock.h"
45
- #include "utils/dynahash.h"
46
45
#include "utils/hsearch.h"
47
46
#include "utils/memutils.h"
48
47
#include "utils/palloc.h"
@@ -340,8 +339,8 @@ LockMethodTableInit(char *tabName,
340
339
* to find the different locks.
341
340
* ----------------------
342
341
*/
343
- info .keysize = sizeof ( LOCKTAG ) ;
344
- info .datasize = sizeof ( LOCK ) ;
342
+ info .keysize = SHMEM_LOCKTAB_KEYSIZE ;
343
+ info .datasize = SHMEM_LOCKTAB_DATASIZE ;
345
344
info .hash = tag_hash ;
346
345
hash_flags = (HASH_ELEM | HASH_FUNCTION );
347
346
@@ -362,8 +361,8 @@ LockMethodTableInit(char *tabName,
362
361
* the same lock, additional information must be saved (locks per tx).
363
362
* -------------------------
364
363
*/
365
- info .keysize = XID_TAGSIZE ;
366
- info .datasize = sizeof ( XIDLookupEnt ) ;
364
+ info .keysize = SHMEM_XIDTAB_KEYSIZE ;
365
+ info .datasize = SHMEM_XIDTAB_DATASIZE ;
367
366
info .hash = tag_hash ;
368
367
hash_flags = (HASH_ELEM | HASH_FUNCTION );
369
368
@@ -1491,35 +1490,26 @@ int
1491
1490
LockShmemSize ()
1492
1491
{
1493
1492
int size = 0 ;
1494
- int nLockBuckets ,
1495
- nLockSegs ;
1496
- int nXidBuckets ,
1497
- nXidSegs ;
1498
1493
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 */
1501
1498
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 );
1504
1503
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 );
1509
1508
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 ;
1523
1513
1524
1514
return size ;
1525
1515
}
0 commit comments