Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7c797e7

Browse files
committed
Fix the size of predicate lock manager's shared memory hash tables at creation.
This way they don't compete with the regular lock manager for the slack sharedmemory, making the behavior more predictable.
1 parentf510fc1 commit7c797e7

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

‎src/backend/storage/lmgr/predicate.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -970,17 +970,15 @@ InitPredicateLocks(void)
970970
{
971971
HASHCTLinfo;
972972
inthash_flags;
973-
longinit_table_size,
974-
max_table_size;
973+
longmax_table_size;
975974
SizerequestSize;
976975
boolfound;
977976

978977
/*
979-
* Computeinit/maxsizeto request for predicate lock target hashtable.
978+
* Compute sizeof predicate lock target hashtable.
980979
* Note these calculations must agree with PredicateLockShmemSize!
981980
*/
982981
max_table_size=NPREDICATELOCKTARGETENTS();
983-
init_table_size=max_table_size /2;
984982

985983
/*
986984
* Allocate hash table for PREDICATELOCKTARGET structs. This stores
@@ -991,17 +989,16 @@ InitPredicateLocks(void)
991989
info.entrysize=sizeof(PREDICATELOCKTARGET);
992990
info.hash=tag_hash;
993991
info.num_partitions=NUM_PREDICATELOCK_PARTITIONS;
994-
hash_flags= (HASH_ELEM |HASH_FUNCTION |HASH_PARTITION);
992+
hash_flags= (HASH_ELEM |HASH_FUNCTION |HASH_PARTITION |HASH_FIXED_SIZE);
995993

996994
PredicateLockTargetHash=ShmemInitHash("PREDICATELOCKTARGET hash",
997-
init_table_size,
995+
max_table_size,
998996
max_table_size,
999997
&info,
1000998
hash_flags);
1001999

10021000
/* Assume an average of 2 xacts per target */
10031001
max_table_size *=2;
1004-
init_table_size *=2;
10051002

10061003
/*
10071004
* Reserve an entry in the hash table; we use it to make sure there's
@@ -1022,18 +1019,17 @@ InitPredicateLocks(void)
10221019
info.entrysize=sizeof(PREDICATELOCK);
10231020
info.hash=predicatelock_hash;
10241021
info.num_partitions=NUM_PREDICATELOCK_PARTITIONS;
1025-
hash_flags= (HASH_ELEM |HASH_FUNCTION |HASH_PARTITION);
1022+
hash_flags= (HASH_ELEM |HASH_FUNCTION |HASH_PARTITION |HASH_FIXED_SIZE);
10261023

10271024
PredicateLockHash=ShmemInitHash("PREDICATELOCK hash",
1028-
init_table_size,
1025+
max_table_size,
10291026
max_table_size,
10301027
&info,
10311028
hash_flags);
10321029

10331030
/*
1034-
* Compute init/max size to request for serializable transaction
1035-
* hashtable. Note these calculations must agree with
1036-
* PredicateLockShmemSize!
1031+
* Compute size for serializable transaction hashtable.
1032+
* Note these calculations must agree with PredicateLockShmemSize!
10371033
*/
10381034
max_table_size= (MaxBackends+max_prepared_xacts);
10391035

@@ -1104,7 +1100,7 @@ InitPredicateLocks(void)
11041100
info.keysize=sizeof(SERIALIZABLEXIDTAG);
11051101
info.entrysize=sizeof(SERIALIZABLEXID);
11061102
info.hash=tag_hash;
1107-
hash_flags= (HASH_ELEM |HASH_FUNCTION);
1103+
hash_flags= (HASH_ELEM |HASH_FUNCTION |HASH_FIXED_SIZE);
11081104

11091105
SerializableXidHash=ShmemInitHash("SERIALIZABLEXID hash",
11101106
max_table_size,

‎src/backend/utils/hash/dynahash.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct HTAB
160160
MemoryContexthcxt;/* memory context if default allocator used */
161161
char*tabname;/* table name (for error messages) */
162162
boolisshared;/* true if table is in shared memory */
163+
boolisfixed;/* if true, don't enlarge */
163164

164165
/* freezing a shared table isn't allowed, so we can keep state here */
165166
boolfrozen;/* true = no more inserts allowed */
@@ -435,6 +436,8 @@ hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
435436
errmsg("out of memory")));
436437
}
437438

439+
if (flags&HASH_FIXED_SIZE)
440+
hashp->isfixed= true;
438441
returnhashp;
439442
}
440443

@@ -1334,6 +1337,9 @@ element_alloc(HTAB *hashp, int nelem)
13341337
HASHELEMENT*prevElement;
13351338
inti;
13361339

1340+
if (hashp->isfixed)
1341+
return false;
1342+
13371343
/* Each element has a HASHELEMENT header plus user data. */
13381344
elementSize=MAXALIGN(sizeof(HASHELEMENT))+MAXALIGN(hctlv->entrysize);
13391345

‎src/include/utils/hsearch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ typedef struct HASHCTL
9292
#defineHASH_CONTEXT0x200/* Set memory allocation context */
9393
#defineHASH_COMPARE0x400/* Set user defined comparison function */
9494
#defineHASH_KEYCOPY0x800/* Set user defined key-copying function */
95+
#defineHASH_FIXED_SIZE0x1000/* Initial size is a hard limit */
9596

9697

9798
/* max_dsize value to indicate expansible directory */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp