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

Commitc878de1

Browse files
committed
Make FP_LOCK_SLOTS_PER_BACKEND look like a function
The FP_LOCK_SLOTS_PER_BACKEND macro looks like a constant, but itdepends on the max_locks_per_transaction GUC, and thus can change. Thisis non-obvious and confusing, so make it look more like a function byrenaming it to FastPathLockSlotsPerBackend().While at it, use the macro when initializing fast-path shared memory,instead of using the formula.Reported-by: Andres FreundDiscussion:https://postgr.es/m/ffiwtzc6vedo6wb4gbwelon5nefqg675t5c7an2ta7pcz646cg%40qwmkdb3l4ett
1 parent91ecb5e commitc878de1

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ intFastPathLockGroupsPerBackend = 0;
226226
* the FAST_PATH_SLOT macro, split it into group and index (in the group).
227227
*/
228228
#defineFAST_PATH_GROUP(index)\
229-
(AssertMacro((uint32) (index) <FP_LOCK_SLOTS_PER_BACKEND), \
229+
(AssertMacro((uint32) (index) <FastPathLockSlotsPerBackend()), \
230230
((index) / FP_LOCK_SLOTS_PER_GROUP))
231231
#defineFAST_PATH_INDEX(index)\
232-
(AssertMacro((uint32) (index) <FP_LOCK_SLOTS_PER_BACKEND), \
232+
(AssertMacro((uint32) (index) <FastPathLockSlotsPerBackend()), \
233233
((index) % FP_LOCK_SLOTS_PER_GROUP))
234234

235235
/* Macros for manipulating proc->fpLockBits */
@@ -242,7 +242,7 @@ intFastPathLockGroupsPerBackend = 0;
242242
#defineFAST_PATH_BIT_POSITION(n,l) \
243243
(AssertMacro((l) >= FAST_PATH_LOCKNUMBER_OFFSET), \
244244
AssertMacro((l) < FAST_PATH_BITS_PER_SLOT+FAST_PATH_LOCKNUMBER_OFFSET), \
245-
AssertMacro((n) <FP_LOCK_SLOTS_PER_BACKEND), \
245+
AssertMacro((n) <FastPathLockSlotsPerBackend()), \
246246
((l) - FAST_PATH_LOCKNUMBER_OFFSET + FAST_PATH_BITS_PER_SLOT * (FAST_PATH_INDEX(n))))
247247
#defineFAST_PATH_SET_LOCKMODE(proc,n,l) \
248248
FAST_PATH_BITS(proc, n) |= UINT64CONST(1) << FAST_PATH_BIT_POSITION(n, l)
@@ -2691,7 +2691,7 @@ static bool
26912691
FastPathGrantRelationLock(Oidrelid,LOCKMODElockmode)
26922692
{
26932693
uint32i;
2694-
uint32unused_slot=FP_LOCK_SLOTS_PER_BACKEND;
2694+
uint32unused_slot=FastPathLockSlotsPerBackend();
26952695

26962696
/* fast-path group the lock belongs to */
26972697
uint32group=FAST_PATH_REL_GROUP(relid);
@@ -2713,7 +2713,7 @@ FastPathGrantRelationLock(Oid relid, LOCKMODE lockmode)
27132713
}
27142714

27152715
/* If no existing entry, use any empty slot. */
2716-
if (unused_slot<FP_LOCK_SLOTS_PER_BACKEND)
2716+
if (unused_slot<FastPathLockSlotsPerBackend())
27172717
{
27182718
MyProc->fpRelId[unused_slot]=relid;
27192719
FAST_PATH_SET_LOCKMODE(MyProc,unused_slot,lockmode);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ ProcGlobalShmemSize(void)
116116
* nicely aligned in each backend.
117117
*/
118118
fpLockBitsSize=MAXALIGN(FastPathLockGroupsPerBackend*sizeof(uint64));
119-
fpRelIdSize=MAXALIGN(FastPathLockGroupsPerBackend*sizeof(Oid)*FP_LOCK_SLOTS_PER_GROUP);
119+
fpRelIdSize=MAXALIGN(FastPathLockSlotsPerBackend()*sizeof(Oid));
120120

121121
size=add_size(size,mul_size(TotalProcs, (fpLockBitsSize+fpRelIdSize)));
122122

@@ -231,7 +231,7 @@ InitProcGlobal(void)
231231
* shared memory and then divide that between backends.
232232
*/
233233
fpLockBitsSize=MAXALIGN(FastPathLockGroupsPerBackend*sizeof(uint64));
234-
fpRelIdSize=MAXALIGN(FastPathLockGroupsPerBackend*sizeof(Oid)*FP_LOCK_SLOTS_PER_GROUP);
234+
fpRelIdSize=MAXALIGN(FastPathLockSlotsPerBackend()*sizeof(Oid));
235235

236236
fpPtr=ShmemAlloc(TotalProcs* (fpLockBitsSize+fpRelIdSize));
237237
MemSet(fpPtr,0,TotalProcs* (fpLockBitsSize+fpRelIdSize));

‎src/backend/utils/init/postinit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ InitializeFastPathLocks(void)
587587
while (FastPathLockGroupsPerBackend<FP_LOCK_GROUPS_PER_BACKEND_MAX)
588588
{
589589
/* stop once we exceed max_locks_per_xact */
590-
if (FastPathLockGroupsPerBackend*FP_LOCK_SLOTS_PER_GROUP >=max_locks_per_xact)
590+
if (FastPathLockSlotsPerBackend() >=max_locks_per_xact)
591591
break;
592592

593593
FastPathLockGroupsPerBackend *=2;

‎src/include/storage/proc.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ extern PGDLLIMPORT int FastPathLockGroupsPerBackend;
8888

8989
#defineFP_LOCK_GROUPS_PER_BACKEND_MAX1024
9090
#defineFP_LOCK_SLOTS_PER_GROUP16/* don't change */
91-
#defineFP_LOCK_SLOTS_PER_BACKEND(FP_LOCK_SLOTS_PER_GROUP * FastPathLockGroupsPerBackend)
91+
#defineFastPathLockSlotsPerBackend() \
92+
(FP_LOCK_SLOTS_PER_GROUP * FastPathLockGroupsPerBackend)
9293

9394
/*
9495
* Flags for PGPROC.delayChkptFlags

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp