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

Commit0fb3152

Browse files
committed
Minor adjustments to improve the accuracy of our computation of required
shared memory size.
1 parent1bb38bb commit0fb3152

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

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

Lines changed: 2 additions & 2 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.35 2004/09/28 20:46:27 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.36 2004/09/29 15:15:54 tgl Exp $
1212
*
1313
*
1414
* NOTES:
@@ -330,7 +330,7 @@ FreeSpaceShmemSize(void)
330330
size=MAXALIGN(sizeof(FSMHeader));
331331

332332
/* hash table, including the FSMRelation objects */
333-
size+=hash_estimate_size(MaxFSMRelations,sizeof(FSMRelation));
333+
size+=hash_estimate_size(MaxFSMRelations+1,sizeof(FSMRelation));
334334

335335
/* page-storage arena */
336336
nchunks= (MaxFSMPages-1) /CHUNKPAGES+1;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.71 2004/08/2905:06:48 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.72 2004/09/2915:15:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -69,6 +69,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
6969
size=hash_estimate_size(SHMEM_INDEX_SIZE,sizeof(ShmemIndexEnt));
7070
size+=BufferShmemSize();
7171
size+=LockShmemSize(maxBackends);
72+
size+=ProcGlobalShmemSize(maxBackends);
7273
size+=XLOGShmemSize();
7374
size+=CLOGShmemSize();
7475
size+=SUBTRANSShmemSize();

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

Lines changed: 9 additions & 4 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.141 2004/09/28 20:46:32 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.142 2004/09/29 15:15:55 tgl Exp $
1212
*
1313
* NOTES
1414
* Outside modules can create a lock table and acquire/release
@@ -1689,15 +1689,17 @@ LockReassignCurrentOwner(void)
16891689
}
16901690

16911691

1692+
/*
1693+
* Estimate shared-memory space used for lock tables
1694+
*/
16921695
int
16931696
LockShmemSize(intmaxBackends)
16941697
{
16951698
intsize=0;
16961699
longmax_table_size=NLOCKENTS(maxBackends);
16971700

1698-
size+=MAXALIGN(sizeof(PROC_HDR));/* ProcGlobal */
1699-
size+=maxBackends*MAXALIGN(sizeof(PGPROC));/* each MyProc */
1700-
size+=MAX_LOCK_METHODS*MAXALIGN(sizeof(LockMethodData));/* each lock method */
1701+
/* lock method headers */
1702+
size+=MAX_LOCK_METHODS*MAXALIGN(sizeof(LockMethodData));
17011703

17021704
/* lockHash table */
17031705
size+=hash_estimate_size(max_table_size,sizeof(LOCK));
@@ -1706,6 +1708,9 @@ LockShmemSize(int maxBackends)
17061708
size+=hash_estimate_size(max_table_size,sizeof(PROCLOCK));
17071709

17081710
/*
1711+
* Note we count only one pair of hash tables, since the userlocks
1712+
* table actually overlays the main one.
1713+
*
17091714
* Since the lockHash entry count above is only an estimate, add 10%
17101715
* safety margin.
17111716
*/

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.153 2004/08/2905:06:48 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.154 2004/09/2915:15:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -89,6 +89,22 @@ static void DummyProcKill(int code, Datum arg);
8989
staticboolCheckStatementTimeout(void);
9090

9191

92+
/*
93+
* Report shared-memory space needed by InitProcGlobal.
94+
*/
95+
int
96+
ProcGlobalShmemSize(intmaxBackends)
97+
{
98+
intsize=0;
99+
100+
size+=MAXALIGN(sizeof(PROC_HDR));/* ProcGlobal */
101+
size+=MAXALIGN(NUM_DUMMY_PROCS*sizeof(PGPROC));/* DummyProcs */
102+
size+=MAXALIGN(maxBackends*sizeof(PGPROC));/* MyProcs */
103+
size+=MAXALIGN(sizeof(slock_t));/* ProcStructLock */
104+
105+
returnsize;
106+
}
107+
92108
/*
93109
* Report number of semaphores needed by InitProcGlobal.
94110
*/
@@ -134,7 +150,7 @@ InitProcGlobal(int maxBackends)
134150
* processes, too.These do not get linked into the freeProcs list.
135151
*/
136152
DummyProcs= (PGPROC*)
137-
ShmemInitStruct("DummyProcs",sizeof(PGPROC)*NUM_DUMMY_PROCS,
153+
ShmemInitStruct("DummyProcs",NUM_DUMMY_PROCS*sizeof(PGPROC),
138154
&foundDummy);
139155

140156
if (foundProcGlobal||foundDummy)
@@ -147,6 +163,7 @@ InitProcGlobal(int maxBackends)
147163
/*
148164
* We're the first - initialize.
149165
*/
166+
PGPROC*procs;
150167
inti;
151168

152169
ProcGlobal->freeProcs=INVALID_OFFSET;
@@ -155,22 +172,20 @@ InitProcGlobal(int maxBackends)
155172
* Pre-create the PGPROC structures and create a semaphore for
156173
* each.
157174
*/
175+
procs= (PGPROC*)ShmemAlloc(maxBackends*sizeof(PGPROC));
176+
if (!procs)
177+
ereport(FATAL,
178+
(errcode(ERRCODE_OUT_OF_MEMORY),
179+
errmsg("out of shared memory")));
180+
MemSet(procs,0,maxBackends*sizeof(PGPROC));
158181
for (i=0;i<maxBackends;i++)
159182
{
160-
PGPROC*proc;
161-
162-
proc= (PGPROC*)ShmemAlloc(sizeof(PGPROC));
163-
if (!proc)
164-
ereport(FATAL,
165-
(errcode(ERRCODE_OUT_OF_MEMORY),
166-
errmsg("out of shared memory")));
167-
MemSet(proc,0,sizeof(PGPROC));
168-
PGSemaphoreCreate(&proc->sem);
169-
proc->links.next=ProcGlobal->freeProcs;
170-
ProcGlobal->freeProcs=MAKE_OFFSET(proc);
183+
PGSemaphoreCreate(&(procs[i].sem));
184+
procs[i].links.next=ProcGlobal->freeProcs;
185+
ProcGlobal->freeProcs=MAKE_OFFSET(&procs[i]);
171186
}
172187

173-
MemSet(DummyProcs,0,sizeof(PGPROC)*NUM_DUMMY_PROCS);
188+
MemSet(DummyProcs,0,NUM_DUMMY_PROCS*sizeof(PGPROC));
174189
for (i=0;i<NUM_DUMMY_PROCS;i++)
175190
{
176191
DummyProcs[i].pid=0;/* marks dummy proc as not in use */

‎src/include/storage/proc.h

Lines changed: 2 additions & 1 deletion
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/proc.h,v 1.75 2004/08/2905:06:58 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.76 2004/09/2915:15:56 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -122,6 +122,7 @@ extern intStatementTimeout;
122122
* Function Prototypes
123123
*/
124124
externintProcGlobalSemas(intmaxBackends);
125+
externintProcGlobalShmemSize(intmaxBackends);
125126
externvoidInitProcGlobal(intmaxBackends);
126127
externvoidInitProcess(void);
127128
externvoidInitDummyProcess(intproctype);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp