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

Commit3a246cc

Browse files
committed
Arrange to preallocate all required space for the buffer and FSM hash
tables in shared memory. This ensures that overflow of the lock tablecreates no long-lasting problems. Per discussion with Merlin Moncure.
1 parentd9b68c8 commit3a246cc

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

‎src/backend/storage/freespace/freespace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.34 2004/08/29 05:06:47 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.35 2004/09/28 20:46:27 tgl Exp $
1212
*
1313
*
1414
* NOTES:
@@ -283,8 +283,8 @@ InitFreeSpaceMap(void)
283283
info.hash=tag_hash;
284284

285285
FreeSpaceMapRelHash=ShmemInitHash("Free Space Map Hash",
286-
MaxFSMRelations/10,
287-
MaxFSMRelations,
286+
MaxFSMRelations+1,
287+
MaxFSMRelations+1,
288288
&info,
289289
(HASH_ELEM |HASH_FUNCTION));
290290

‎src/backend/storage/ipc/shmem.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.80 2004/08/29 05:06:48 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.81 2004/09/28 20:46:29 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -262,8 +262,17 @@ InitShmemIndex(void)
262262
*shared memory hash table.
263263
*
264264
* We assume caller is doing some kind of synchronization
265-
* so that two peopledont try to create/initialize the
265+
* so that two peopledon't try to create/initialize the
266266
* table at once.
267+
*
268+
* max_size is the estimated maximum number of hashtable entries. This is
269+
* not a hard limit, but the access efficiency will degrade if it is
270+
* exceeded substantially (since it's used to compute directory size and
271+
* the hash table buckets will get overfull).
272+
*
273+
* init_size is the number of hashtable entries to preallocate. For a table
274+
* whose maximum size is certain, this should be equal to max_size; that
275+
* ensures that no run-time out-of-shared-memory failures can occur.
267276
*/
268277
HTAB*
269278
ShmemInitHash(constchar*name,/* table string name for shmem index */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.140 2004/09/12 18:30:50 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.141 2004/09/28 20:46:32 tgl Exp $
1212
*
1313
* NOTES
1414
* Outside modules can create a lock table and acquire/release
@@ -241,7 +241,7 @@ LockMethodTableInit(const char *tabName,
241241

242242
/* Compute init/max size to request for lock hashtables */
243243
max_table_size=NLOCKENTS(maxBackends);
244-
init_table_size=max_table_size /10;
244+
init_table_size=max_table_size /2;
245245

246246
/* Allocate a string for the shmem index table lookups. */
247247
/* This is just temp space in this routine, so palloc is OK. */

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.53 2004/08/29 05:06:50 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.54 2004/09/28 20:46:34 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -63,7 +63,7 @@
6363
*/
6464
staticvoid*DynaHashAlloc(Sizesize);
6565
staticHASHSEGMENTseg_alloc(HTAB*hashp);
66-
staticboolelement_alloc(HTAB*hashp);
66+
staticboolelement_alloc(HTAB*hashp,intnelem);
6767
staticbooldir_realloc(HTAB*hashp);
6868
staticboolexpand_table(HTAB*hashp);
6969
staticboolhdefault(HTAB*hashp);
@@ -228,11 +228,26 @@ hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
228228
CurrentDynaHashCxt=hashp->hcxt;
229229
}
230230

231+
/* Build the hash directory structure */
231232
if (!init_htab(hashp,nelem))
232233
{
233234
hash_destroy(hashp);
234235
returnNULL;
235236
}
237+
238+
/*
239+
* For a shared hash table, preallocate the requested number of elements.
240+
* This reduces problems with run-time out-of-shared-memory conditions.
241+
*/
242+
if (flags&HASH_SHARED_MEM)
243+
{
244+
if (!element_alloc(hashp, (int)nelem))
245+
{
246+
hash_destroy(hashp);
247+
returnNULL;
248+
}
249+
}
250+
236251
returnhashp;
237252
}
238253

@@ -631,7 +646,7 @@ hash_search(HTAB *hashp,
631646
if (currBucket==NULL)
632647
{
633648
/* no free elements. allocate another chunk of buckets */
634-
if (!element_alloc(hashp))
649+
if (!element_alloc(hashp,HASHELEMENT_ALLOC_INCR))
635650
returnNULL;/* out of memory */
636651
currBucket=hctl->freeList;
637652
Assert(currBucket!=NULL);
@@ -898,7 +913,7 @@ seg_alloc(HTAB *hashp)
898913
* allocate some new elements and link them into the free list
899914
*/
900915
staticbool
901-
element_alloc(HTAB*hashp)
916+
element_alloc(HTAB*hashp,intnelem)
902917
{
903918
HASHHDR*hctl=hashp->hctl;
904919
SizeelementSize;
@@ -910,13 +925,13 @@ element_alloc(HTAB *hashp)
910925

911926
CurrentDynaHashCxt=hashp->hcxt;
912927
tmpElement= (HASHELEMENT*)
913-
hashp->alloc(HASHELEMENT_ALLOC_INCR*elementSize);
928+
hashp->alloc(nelem*elementSize);
914929

915930
if (!tmpElement)
916931
return false;
917932

918933
/* link all the new entries into the freelist */
919-
for (i=0;i<HASHELEMENT_ALLOC_INCR;i++)
934+
for (i=0;i<nelem;i++)
920935
{
921936
tmpElement->link=hctl->freeList;
922937
hctl->freeList=tmpElement;

‎src/include/storage/shmem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.42 2004/08/29 04:13:10 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.43 2004/09/28 20:46:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -73,8 +73,8 @@ extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
7373
/* size constants for the shmem index table */
7474
/* max size of data structure string name */
7575
#defineSHMEM_INDEX_KEYSIZE (48)
76-
/*maximum size of the shmem index table */
77-
#defineSHMEM_INDEX_SIZE (100)
76+
/*max size of the shmem index table (not a hard limit) */
77+
#defineSHMEM_INDEX_SIZE (32)
7878

7979
/* this is a hash bucket in the shmem index table */
8080
typedefstruct

‎src/include/utils/hsearch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.32 2004/08/29 05:06:59 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.33 2004/09/28 20:46:37 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -135,7 +135,7 @@ typedef struct HASHCTL
135135
#defineHASH_FFACTOR0x008/* Set fill factor */
136136
#defineHASH_FUNCTION0x010/* Set user defined hash function */
137137
#defineHASH_ELEM0x020/* Set key/entry size */
138-
#defineHASH_SHARED_MEM 0x040/*Set shared mem const */
138+
#defineHASH_SHARED_MEM 0x040/*Hashtable is in shared memory */
139139
#defineHASH_ATTACH0x080/* Do not initialize hctl */
140140
#defineHASH_ALLOC0x100/* Set memory allocator */
141141
#defineHASH_CONTEXT0x200/* Set explicit memory context */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp