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

Commit2ecbf94

Browse files
committed
Retrofit hashtable and shared-mem-size-estimation bug fixes
into REL6_4.
1 parent0fda84b commit2ecbf94

File tree

8 files changed

+212
-194
lines changed

8 files changed

+212
-194
lines changed

‎src/backend/storage/buffer/buf_init.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.19 1998/09/01 04:31:39 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.19.2.1 1999/03/07 02:01:08 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -33,7 +33,6 @@
3333
#include"storage/lmgr.h"
3434
#include"miscadmin.h"
3535
#include"utils/builtins.h"
36-
#include"utils/dynahash.h"
3736
#include"utils/hsearch.h"
3837
#include"utils/memutils.h"
3938
#include"executor/execdebug.h"/* for NDirectFileRead */
@@ -270,21 +269,11 @@ int
270269
BufferShmemSize()
271270
{
272271
intsize=0;
273-
intnbuckets;
274-
intnsegs;
275-
inttmp;
276-
277-
nbuckets=1 << (int)my_log2((NBuffers-1) /DEF_FFACTOR+1);
278-
nsegs=1 << (int)my_log2((nbuckets-1) /DEF_SEGSIZE+1);
279-
280-
/* size of shmem index table */
281-
size+=MAXALIGN(my_log2(SHMEM_INDEX_SIZE)*sizeof(void*));/* HTAB->dir */
282-
size+=MAXALIGN(sizeof(HHDR));/* HTAB->hctl */
283-
size+=MAXALIGN(DEF_SEGSIZE*sizeof(SEGMENT));
284-
size+=BUCKET_ALLOC_INCR*
285-
(MAXALIGN(sizeof(BUCKET_INDEX))+
286-
MAXALIGN(SHMEM_INDEX_KEYSIZE)+
287-
MAXALIGN(SHMEM_INDEX_DATASIZE));
272+
273+
/* size of shmem index hash table */
274+
size+=hash_estimate_size(SHMEM_INDEX_SIZE,
275+
SHMEM_INDEX_KEYSIZE,
276+
SHMEM_INDEX_DATASIZE);
288277

289278
/* size of buffer descriptors */
290279
size+=MAXALIGN((NBuffers+1)*sizeof(BufferDesc));
@@ -293,17 +282,13 @@ BufferShmemSize()
293282
size+=NBuffers*MAXALIGN(BLCKSZ);
294283

295284
/* size of buffer hash table */
296-
size+=MAXALIGN(my_log2(NBuffers)*sizeof(void*));/* HTAB->dir */
297-
size+=MAXALIGN(sizeof(HHDR));/* HTAB->hctl */
298-
size+=nsegs*MAXALIGN(DEF_SEGSIZE*sizeof(SEGMENT));
299-
tmp= (int)ceil((double)NBuffers /BUCKET_ALLOC_INCR);
300-
size+=tmp*BUCKET_ALLOC_INCR*
301-
(MAXALIGN(sizeof(BUCKET_INDEX))+
302-
MAXALIGN(sizeof(BufferTag))+
303-
MAXALIGN(sizeof(Buffer)));
285+
size+=hash_estimate_size(NBuffers,
286+
sizeof(BufferTag),
287+
sizeof(Buffer));
304288

305289
#ifdefBMTRACE
306290
size+= (BMT_LIMIT*sizeof(bmtrace))+sizeof(long);
307291
#endif
292+
308293
returnsize;
309294
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.16 1998/09/01 03:25:10 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.16.2.1 1999/03/07 02:00:46 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -71,11 +71,17 @@ CreateSharedMemoryAndSemaphores(IPCKey key)
7171
* ----------------
7272
*/
7373
CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key));
74-
size=BufferShmemSize()+LockShmemSize();
7574

75+
/*
76+
* Size of the primary shared-memory block is estimated via
77+
* moderately-accurate estimates for the big hogs, plus 100K for
78+
* the stuff that's too small to bother with estimating.
79+
*/
80+
size=BufferShmemSize()+LockShmemSize();
7681
#ifdefSTABLE_MEMORY_STORAGE
7782
size+=MMShmemSize();
7883
#endif
84+
size+=100000;
7985

8086
if (DebugLvl>1)
8187
{
@@ -113,8 +119,6 @@ CreateSharedMemoryAndSemaphores(IPCKey key)
113119
void
114120
AttachSharedMemoryAndSemaphores(IPCKeykey)
115121
{
116-
intsize;
117-
118122
/* ----------------
119123
*create rather than attach if using private key
120124
* ----------------
@@ -136,8 +140,7 @@ AttachSharedMemoryAndSemaphores(IPCKey key)
136140
*attach the buffer manager buffer pool (and semaphore)
137141
* ----------------
138142
*/
139-
size=BufferShmemSize()+LockShmemSize();
140-
InitShmem(key,size);
143+
InitShmem(key,0);
141144
InitBufferPool(key);
142145

143146
/* ----------------

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.31 1998/09/01 04:31:49 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.31.2.1 1999/03/07 02:00:46 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -215,7 +215,7 @@ InitShmem(unsigned int key, unsigned int size)
215215
/* create OR attach to the shared memory shmem index */
216216
info.keysize=SHMEM_INDEX_KEYSIZE;
217217
info.datasize=SHMEM_INDEX_DATASIZE;
218-
hash_flags=(HASH_ELEM);
218+
hash_flags=HASH_ELEM;
219219

220220
/* This will acquire the shmem index lock, but not release it. */
221221
ShmemIndex=ShmemInitHash("ShmemIndex",
@@ -340,27 +340,29 @@ ShmemIsValid(unsigned long addr)
340340
*/
341341
HTAB*
342342
ShmemInitHash(char*name,/* table string name for shmem index */
343-
longinit_size,/* initial size */
344-
longmax_size,/* max size of the table */
343+
longinit_size,/* initialtablesize */
344+
longmax_size,/* max size of the table(NOT USED)*/
345345
HASHCTL*infoP,/* info about key and bucket size */
346346
inthash_flags)/* info about infoP */
347347
{
348348
boolfound;
349349
long*location;
350350

351351
/*
352-
* shared memory hash tables have a fixed max size so that the control
353-
* structures don't try to grow. The segbase is for calculating
354-
* pointer values.The shared memory allocator must be specified.
352+
* Hash tables allocated in shared memory have a fixed directory;
353+
* it can't grow or other backends wouldn't be able to find it.
354+
* The segbase is for calculating pointer values.
355+
* The shared memory allocator must be specified too.
355356
*/
357+
infoP->dsize=infoP->max_dsize=DEF_DIRSIZE;
356358
infoP->segbase= (long*)ShmemBase;
357359
infoP->alloc=ShmemAlloc;
358-
infoP->max_size=max_size;
359-
hash_flags |=HASH_SHARED_MEM;
360+
hash_flags |=HASH_SHARED_MEM |HASH_DIRSIZE;
360361

361362
/* look it up in the shmem index */
362-
location=
363-
ShmemInitStruct(name,my_log2(max_size)+sizeof(HHDR),&found);
363+
location=ShmemInitStruct(name,
364+
sizeof(HHDR)+DEF_DIRSIZE*sizeof(SEG_OFFSET),
365+
&found);
364366

365367
/*
366368
* shmem index is corrupted.Let someone else give the error
@@ -376,13 +378,11 @@ ShmemInitHash(char *name,/* table string name for shmem index */
376378
if (found)
377379
hash_flags |=HASH_ATTACH;
378380

379-
/* these structures were allocated or bound in ShmemInitStruct */
380-
/* control information and parameters */
381+
/* Now provide the header and directory pointers */
381382
infoP->hctl= (long*)location;
382-
/* directory for hash lookup */
383-
infoP->dir= (long*) (location+sizeof(HHDR));
383+
infoP->dir= (long*) (((char*)location)+sizeof(HHDR));
384384

385-
returnhash_create(init_size,infoP,hash_flags);;
385+
returnhash_create(init_size,infoP,hash_flags);
386386
}
387387

388388
/*

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

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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
@@ -42,7 +42,6 @@
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
14911490
LockShmemSize()
14921491
{
14931492
intsize=0;
1494-
intnLockBuckets,
1495-
nLockSegs;
1496-
intnXidBuckets,
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
returnsize;
15251515
}

‎src/backend/storage/smgr/mm.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.12 1998/09/01 04:32:07 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.12.2.1 1999/03/07 02:00:52 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -25,7 +25,6 @@
2525
#include"storage/shmem.h"
2626
#include"storage/spin.h"
2727

28-
#include"utils/dynahash.h"
2928
#include"utils/hsearch.h"
3029
#include"utils/rel.h"
3130
#include"utils/memutils.h"
@@ -111,7 +110,7 @@ mminit()
111110
}
112111

113112
info.keysize=sizeof(MMCacheTag);
114-
info.datasize=sizeof(int);
113+
info.datasize=sizeof(MMHashEntry)-sizeof(MMCacheTag);
115114
info.hash=tag_hash;
116115

117116
MMCacheHT= (HTAB*)ShmemInitHash("Main memory store HT",
@@ -125,7 +124,7 @@ mminit()
125124
}
126125

127126
info.keysize=sizeof(MMRelTag);
128-
info.datasize=sizeof(int);
127+
info.datasize=sizeof(MMRelHashEntry)-sizeof(MMRelTag);
129128
info.hash=tag_hash;
130129

131130
MMRelCacheHT= (HTAB*)ShmemInitHash("Main memory rel HT",
@@ -565,36 +564,20 @@ int
565564
MMShmemSize()
566565
{
567566
intsize=0;
568-
intnbuckets;
569-
intnsegs;
570-
inttmp;
571567

572568
/*
573569
* first compute space occupied by the (dbid,relid,blkno) hash table
574570
*/
575-
576-
nbuckets=1 << (int)my_log2((MMNBUFFERS-1) /DEF_FFACTOR+1);
577-
nsegs=1 << (int)my_log2((nbuckets-1) /DEF_SEGSIZE+1);
578-
579-
size+=MAXALIGN(my_log2(MMNBUFFERS)*sizeof(void*));
580-
size+=MAXALIGN(sizeof(HHDR));
581-
size+=nsegs*MAXALIGN(DEF_SEGSIZE*sizeof(SEGMENT));
582-
tmp= (int)ceil((double)MMNBUFFERS /BUCKET_ALLOC_INCR);
583-
size+=tmp*BUCKET_ALLOC_INCR*
584-
(MAXALIGN(sizeof(BUCKET_INDEX))+
585-
MAXALIGN(sizeof(MMHashEntry)));/* contains hash key */
571+
size+=hash_estimate_size(MMNBUFFERS,
572+
0,/* MMHashEntry includes key */
573+
sizeof(MMHashEntry));
586574

587575
/*
588576
* now do the same for the rel hash table
589577
*/
590-
591-
size+=MAXALIGN(my_log2(MMNRELATIONS)*sizeof(void*));
592-
size+=MAXALIGN(sizeof(HHDR));
593-
size+=nsegs*MAXALIGN(DEF_SEGSIZE*sizeof(SEGMENT));
594-
tmp= (int)ceil((double)MMNRELATIONS /BUCKET_ALLOC_INCR);
595-
size+=tmp*BUCKET_ALLOC_INCR*
596-
(MAXALIGN(sizeof(BUCKET_INDEX))+
597-
MAXALIGN(sizeof(MMRelHashEntry)));/* contains hash key */
578+
size+=hash_estimate_size(MMNRELATIONS,
579+
0,/* MMRelHashEntry includes key */
580+
sizeof(MMRelHashEntry));
598581

599582
/*
600583
* finally, add in the memory block we use directly

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp