Commit 7c797e71 authored by Heikki Linnakangas's avatar Heikki Linnakangas

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 shared
memory, making the behavior more predictable.
parent f510fc1d
...@@ -970,17 +970,15 @@ InitPredicateLocks(void) ...@@ -970,17 +970,15 @@ InitPredicateLocks(void)
{ {
HASHCTL info; HASHCTL info;
int hash_flags; int hash_flags;
long init_table_size, long max_table_size;
max_table_size;
Size requestSize; Size requestSize;
bool found; bool found;
/* /*
* Compute init/max size to request for predicate lock target hashtable. * Compute size of predicate lock target hashtable.
* Note these calculations must agree with PredicateLockShmemSize! * Note these calculations must agree with PredicateLockShmemSize!
*/ */
max_table_size = NPREDICATELOCKTARGETENTS(); max_table_size = NPREDICATELOCKTARGETENTS();
init_table_size = max_table_size / 2;
/* /*
* Allocate hash table for PREDICATELOCKTARGET structs. This stores * Allocate hash table for PREDICATELOCKTARGET structs. This stores
...@@ -991,17 +989,16 @@ InitPredicateLocks(void) ...@@ -991,17 +989,16 @@ InitPredicateLocks(void)
info.entrysize = sizeof(PREDICATELOCKTARGET); info.entrysize = sizeof(PREDICATELOCKTARGET);
info.hash = tag_hash; info.hash = tag_hash;
info.num_partitions = NUM_PREDICATELOCK_PARTITIONS; info.num_partitions = NUM_PREDICATELOCK_PARTITIONS;
hash_flags = (HASH_ELEM | HASH_FUNCTION | HASH_PARTITION); hash_flags = (HASH_ELEM | HASH_FUNCTION | HASH_PARTITION | HASH_FIXED_SIZE);
PredicateLockTargetHash = ShmemInitHash("PREDICATELOCKTARGET hash", PredicateLockTargetHash = ShmemInitHash("PREDICATELOCKTARGET hash",
init_table_size, max_table_size,
max_table_size, max_table_size,
&info, &info,
hash_flags); hash_flags);
/* Assume an average of 2 xacts per target */ /* Assume an average of 2 xacts per target */
max_table_size *= 2; max_table_size *= 2;
init_table_size *= 2;
/* /*
* Reserve an entry in the hash table; we use it to make sure there's * Reserve an entry in the hash table; we use it to make sure there's
...@@ -1022,18 +1019,17 @@ InitPredicateLocks(void) ...@@ -1022,18 +1019,17 @@ InitPredicateLocks(void)
info.entrysize = sizeof(PREDICATELOCK); info.entrysize = sizeof(PREDICATELOCK);
info.hash = predicatelock_hash; info.hash = predicatelock_hash;
info.num_partitions = NUM_PREDICATELOCK_PARTITIONS; info.num_partitions = NUM_PREDICATELOCK_PARTITIONS;
hash_flags = (HASH_ELEM | HASH_FUNCTION | HASH_PARTITION); hash_flags = (HASH_ELEM | HASH_FUNCTION | HASH_PARTITION | HASH_FIXED_SIZE);
PredicateLockHash = ShmemInitHash("PREDICATELOCK hash", PredicateLockHash = ShmemInitHash("PREDICATELOCK hash",
init_table_size, max_table_size,
max_table_size, max_table_size,
&info, &info,
hash_flags); hash_flags);
/* /*
* Compute init/max size to request for serializable transaction * Compute size for serializable transaction hashtable.
* hashtable. Note these calculations must agree with * Note these calculations must agree with PredicateLockShmemSize!
* PredicateLockShmemSize!
*/ */
max_table_size = (MaxBackends + max_prepared_xacts); max_table_size = (MaxBackends + max_prepared_xacts);
...@@ -1104,7 +1100,7 @@ InitPredicateLocks(void) ...@@ -1104,7 +1100,7 @@ InitPredicateLocks(void)
info.keysize = sizeof(SERIALIZABLEXIDTAG); info.keysize = sizeof(SERIALIZABLEXIDTAG);
info.entrysize = sizeof(SERIALIZABLEXID); info.entrysize = sizeof(SERIALIZABLEXID);
info.hash = tag_hash; info.hash = tag_hash;
hash_flags = (HASH_ELEM | HASH_FUNCTION); hash_flags = (HASH_ELEM | HASH_FUNCTION | HASH_FIXED_SIZE);
SerializableXidHash = ShmemInitHash("SERIALIZABLEXID hash", SerializableXidHash = ShmemInitHash("SERIALIZABLEXID hash",
max_table_size, max_table_size,
......
...@@ -160,6 +160,7 @@ struct HTAB ...@@ -160,6 +160,7 @@ struct HTAB
MemoryContext hcxt; /* memory context if default allocator used */ MemoryContext hcxt; /* memory context if default allocator used */
char *tabname; /* table name (for error messages) */ char *tabname; /* table name (for error messages) */
bool isshared; /* true if table is in shared memory */ bool isshared; /* true if table is in shared memory */
bool isfixed; /* if true, don't enlarge */
/* freezing a shared table isn't allowed, so we can keep state here */ /* freezing a shared table isn't allowed, so we can keep state here */
bool frozen; /* true = no more inserts allowed */ bool frozen; /* true = no more inserts allowed */
...@@ -435,6 +436,8 @@ hash_create(const char *tabname, long nelem, HASHCTL *info, int flags) ...@@ -435,6 +436,8 @@ hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
errmsg("out of memory"))); errmsg("out of memory")));
} }
if (flags & HASH_FIXED_SIZE)
hashp->isfixed = true;
return hashp; return hashp;
} }
...@@ -1334,6 +1337,9 @@ element_alloc(HTAB *hashp, int nelem) ...@@ -1334,6 +1337,9 @@ element_alloc(HTAB *hashp, int nelem)
HASHELEMENT *prevElement; HASHELEMENT *prevElement;
int i; int i;
if (hashp->isfixed)
return false;
/* Each element has a HASHELEMENT header plus user data. */ /* Each element has a HASHELEMENT header plus user data. */
elementSize = MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(hctlv->entrysize); elementSize = MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(hctlv->entrysize);
......
...@@ -92,6 +92,7 @@ typedef struct HASHCTL ...@@ -92,6 +92,7 @@ typedef struct HASHCTL
#define HASH_CONTEXT 0x200 /* Set memory allocation context */ #define HASH_CONTEXT 0x200 /* Set memory allocation context */
#define HASH_COMPARE 0x400 /* Set user defined comparison function */ #define HASH_COMPARE 0x400 /* Set user defined comparison function */
#define HASH_KEYCOPY 0x800 /* Set user defined key-copying function */ #define HASH_KEYCOPY 0x800 /* Set user defined key-copying function */
#define HASH_FIXED_SIZE 0x1000 /* Initial size is a hard limit */
/* max_dsize value to indicate expansible directory */ /* max_dsize value to indicate expansible directory */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment