Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 731603a

Browse files
committed
A few further tweaks to shared memory space estimation.
This change brings the default size of the main shmem block back under 1MB, which is a fairly popular value for the kernel's SHMMAX parameter.
1 parent 03842eb commit 731603a

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

src/backend/storage/ipc/ipci.c

Lines changed: 1 addition & 3 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.22 1999/02/22 06:16:49 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.23 1999/03/06 21:17:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -77,14 +77,12 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
7777
* Size of the primary shared-memory block is estimated via
7878
* moderately-accurate estimates for the big hogs, plus 100K for
7979
* the stuff that's too small to bother with estimating.
80-
* Then we add 10% for a safety margin.
8180
*/
8281
size = BufferShmemSize() + LockShmemSize(maxBackends);
8382
#ifdef STABLE_MEMORY_STORAGE
8483
size += MMShmemSize();
8584
#endif
8685
size += 100000;
87-
size += size / 10;
8886

8987
if (DebugLvl > 1)
9088
{

src/backend/storage/lmgr/lock.c

Lines changed: 14 additions & 9 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.45 1999/02/22 06:16:52 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.46 1999/03/06 21:17:44 tgl Exp $
1111
*
1212
* NOTES
1313
* Outside modules can create a lock table and acquire/release
@@ -339,8 +339,8 @@ LockMethodTableInit(char *tabName,
339339
* to find the different locks.
340340
* ----------------------
341341
*/
342-
info.keysize = sizeof(LOCKTAG);
343-
info.datasize = sizeof(LOCK);
342+
info.keysize = SHMEM_LOCKTAB_KEYSIZE;
343+
info.datasize = SHMEM_LOCKTAB_DATASIZE;
344344
info.hash = tag_hash;
345345
hash_flags = (HASH_ELEM | HASH_FUNCTION);
346346

@@ -361,8 +361,8 @@ LockMethodTableInit(char *tabName,
361361
* the same lock, additional information must be saved (locks per tx).
362362
* -------------------------
363363
*/
364-
info.keysize = XID_TAGSIZE;
365-
info.datasize = sizeof(XIDLookupEnt);
364+
info.keysize = SHMEM_XIDTAB_KEYSIZE;
365+
info.datasize = SHMEM_XIDTAB_DATASIZE;
366366
info.hash = tag_hash;
367367
hash_flags = (HASH_ELEM | HASH_FUNCTION);
368368

@@ -1488,13 +1488,18 @@ LockShmemSize(int maxBackends)
14881488

14891489
/* lockHash table */
14901490
size += hash_estimate_size(NLOCKENTS(maxBackends),
1491-
sizeof(LOCKTAG),
1492-
sizeof(LOCK));
1491+
SHMEM_LOCKTAB_KEYSIZE,
1492+
SHMEM_LOCKTAB_DATASIZE);
14931493

14941494
/* xidHash table */
14951495
size += hash_estimate_size(maxBackends,
1496-
XID_TAGSIZE,
1497-
sizeof(XIDLookupEnt));
1496+
SHMEM_XIDTAB_KEYSIZE,
1497+
SHMEM_XIDTAB_DATASIZE);
1498+
1499+
/* Since the lockHash entry count above is only an estimate,
1500+
* add 10% safety margin.
1501+
*/
1502+
size += size / 10;
14981503

14991504
return size;
15001505
}

src/backend/storage/smgr/mm.c

Lines changed: 3 additions & 3 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.14 1999/02/22 06:16:57 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.15 1999/03/06 21:17:50 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -110,7 +110,7 @@ mminit()
110110
}
111111

112112
info.keysize = sizeof(MMCacheTag);
113-
info.datasize = sizeof(int);
113+
info.datasize = sizeof(MMHashEntry) - sizeof(MMCacheTag);
114114
info.hash = tag_hash;
115115

116116
MMCacheHT = (HTAB *) ShmemInitHash("Main memory store HT",
@@ -124,7 +124,7 @@ mminit()
124124
}
125125

126126
info.keysize = sizeof(MMRelTag);
127-
info.datasize = sizeof(int);
127+
info.datasize = sizeof(MMRelHashEntry) - sizeof(MMRelTag);
128128
info.hash = tag_hash;
129129

130130
MMRelCacheHT = (HTAB *) ShmemInitHash("Main memory rel HT",

src/backend/utils/hash/dynahash.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.19 1999/02/22 06:16:47 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.20 1999/03/06 21:17:56 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -373,18 +373,23 @@ hash_estimate_size(long num_entries, long keysize, long datasize)
373373
long size = 0;
374374
long nBuckets,
375375
nSegments,
376+
nDirEntries,
376377
nRecordAllocs,
377378
recordSize;
378379

379380
/* estimate number of buckets wanted */
380381
nBuckets = 1L << my_log2((num_entries - 1) / DEF_FFACTOR + 1);
381382
/* # of segments needed for nBuckets */
382-
nSegments = (nBuckets - 1) / DEF_SEGSIZE + 1;
383+
nSegments = 1L << my_log2((nBuckets - 1) / DEF_SEGSIZE + 1);
384+
/* directory entries */
385+
nDirEntries = DEF_DIRSIZE;
386+
while (nDirEntries < nSegments)
387+
nDirEntries <<= 1; /* dir_alloc doubles dsize at each call */
383388

384389
/* fixed control info */
385390
size += MAXALIGN(sizeof(HHDR)); /* but not HTAB, per above */
386-
/* directory, assumed to be of size DEF_DIRSIZE */
387-
size += MAXALIGN(DEF_DIRSIZE * sizeof(SEG_OFFSET));
391+
/* directory */
392+
size += MAXALIGN(nDirEntries * sizeof(SEG_OFFSET));
388393
/* segments */
389394
size += nSegments * MAXALIGN(DEF_SEGSIZE * sizeof(BUCKET_INDEX));
390395
/* records --- allocated in groups of BUCKET_ALLOC_INCR */
@@ -408,9 +413,6 @@ hash_estimate_size(long num_entries, long keysize, long datasize)
408413
void
409414
hash_destroy(HTAB *hashp)
410415
{
411-
/* cannot destroy a shared memory hash table */
412-
Assert(!hashp->segbase);
413-
414416
if (hashp != NULL)
415417
{
416418
SEG_OFFSET segNum;
@@ -422,6 +424,13 @@ hash_destroy(HTAB *hashp)
422424
q;
423425
ELEMENT *curr;
424426

427+
/* cannot destroy a shared memory hash table */
428+
Assert(!hashp->segbase);
429+
/* allocation method must be one we know how to free, too */
430+
Assert(hashp->alloc == (dhalloc_ptr) MEM_ALLOC);
431+
432+
hash_stats("destroy", hashp);
433+
425434
for (segNum = 0; nsegs > 0; nsegs--, segNum++)
426435
{
427436

@@ -435,11 +444,10 @@ hash_destroy(HTAB *hashp)
435444
MEM_FREE((char *) curr);
436445
}
437446
}
438-
free((char *) segp);
447+
MEM_FREE((char *) segp);
439448
}
440449
MEM_FREE((char *) hashp->dir);
441450
MEM_FREE((char *) hashp->hctl);
442-
hash_stats("destroy", hashp);
443451
MEM_FREE((char *) hashp);
444452
}
445453
}

src/include/storage/lock.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: lock.h,v 1.23 1999/02/21 01:41:47 tgl Exp $
9+
* $Id: lock.h,v 1.24 1999/03/06 21:17:43 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -57,8 +57,6 @@ typedef int LOCKMETHOD;
5757
#define USER_LOCKMETHOD 2
5858
#define MIN_LOCKMETHOD DEFAULT_LOCKMETHOD
5959

60-
/*typedef struct LOCK LOCK; */
61-
6260

6361
typedef struct LTAG
6462
{
@@ -174,6 +172,9 @@ typedef struct XIDLookupEnt
174172
SHM_QUEUE queue;
175173
} XIDLookupEnt;
176174

175+
#define SHMEM_XIDTAB_KEYSIZE sizeof(XIDTAG)
176+
#define SHMEM_XIDTAB_DATASIZE (sizeof(XIDLookupEnt) - SHMEM_XIDTAB_KEYSIZE)
177+
177178
#define XID_TAGSIZE (sizeof(XIDTAG))
178179
#define XIDENT_LOCKMETHOD(xident) (XIDTAG_LOCKMETHOD((xident).tag))
179180

@@ -210,6 +211,9 @@ typedef struct LOCK
210211
int nActive;
211212
} LOCK;
212213

214+
#define SHMEM_LOCKTAB_KEYSIZE sizeof(LOCKTAG)
215+
#define SHMEM_LOCKTAB_DATASIZE (sizeof(LOCK) - SHMEM_LOCKTAB_KEYSIZE)
216+
213217
#define LOCK_LOCKMETHOD(lock) (LOCKTAG_LOCKMETHOD((lock).tag))
214218

215219
#define LockGetLock_nHolders(l) l->nHolders

0 commit comments

Comments
 (0)