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

Commitc319991

Browse files
committed
Use separate lwlock tranches for buffer, lock, and predicate lock managers.
This finishes the work - spread across many commits over the lastseveral months - of putting each type of lock other than the namedindividual locks into a separate tranche.Amit Kapila
1 parentb11d07b commitc319991

File tree

2 files changed

+106
-43
lines changed

2 files changed

+106
-43
lines changed

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

Lines changed: 103 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ static intLWLockTranchesAllocated = 0;
125125
*/
126126
LWLockPadded*MainLWLockArray=NULL;
127127
staticLWLockTrancheMainLWLockTranche;
128+
staticLWLockTrancheBufMappingLWLockTranche;
129+
staticLWLockTrancheLockManagerLWLockTranche;
130+
staticLWLockTranchePredicateLockManagerLWLockTranche;
128131

129132
/*
130133
* We use this structure to keep track of locked LWLocks for release
@@ -159,6 +162,9 @@ NamedLWLockTranche *NamedLWLockTrancheArray = NULL;
159162

160163
staticboollock_named_request_allowed= true;
161164

165+
staticvoidInitializeLWLocks(void);
166+
staticvoidRegisterLWLockTranches(void);
167+
162168
#ifdefLWLOCK_STATS
163169
typedefstructlwlock_stats_key
164170
{
@@ -395,14 +401,12 @@ LWLockShmemSize(void)
395401
}
396402

397403
/*
398-
* Allocate shmem space for the main LWLock array andnamed tranches and
399-
* initialize it. We also register themain and named tranche here.
404+
* Allocate shmem space for the main LWLock array andall tranches and
405+
* initialize it. We also registeralltheLWLock tranches here.
400406
*/
401407
void
402408
CreateLWLocks(void)
403409
{
404-
inti;
405-
406410
StaticAssertExpr(LW_VAL_EXCLUSIVE> (uint32)MAX_BACKENDS,
407411
"MAX_BACKENDS too big for lwlock.c");
408412

@@ -412,14 +416,9 @@ CreateLWLocks(void)
412416

413417
if (!IsUnderPostmaster)
414418
{
415-
intnumLocks=NUM_FIXED_LWLOCKS;
416-
intnumNamedLocks=NumLWLocksByNamedTranches();
417419
SizespaceLocks=LWLockShmemSize();
418-
LWLockPadded*lock;
419420
int*LWLockCounter;
420421
char*ptr;
421-
intid;
422-
intj;
423422

424423
/* Allocate space */
425424
ptr= (char*)ShmemAlloc(spaceLocks);
@@ -432,55 +431,99 @@ CreateLWLocks(void)
432431

433432
MainLWLockArray= (LWLockPadded*)ptr;
434433

435-
/* Initialize all fixed LWLocks in main array */
436-
for (id=0,lock=MainLWLockArray;id<numLocks;id++,lock++)
437-
LWLockInitialize(&lock->lock,LWTRANCHE_MAIN);
438-
439434
/*
440435
* Initialize the dynamic-allocation counter for tranches, which is
441436
* stored just before the first LWLock.
442437
*/
443438
LWLockCounter= (int*) ((char*)MainLWLockArray-sizeof(int));
444439
*LWLockCounter=LWTRANCHE_FIRST_USER_DEFINED;
445440

446-
/* Initialize named tranches. */
447-
if (NamedLWLockTrancheRequests>0)
448-
{
449-
char*trancheNames;
441+
/* Initialize all LWLocks */
442+
InitializeLWLocks();
443+
}
444+
445+
/* Register all LWLock tranches */
446+
RegisterLWLockTranches();
447+
}
448+
449+
/*
450+
* Initialize LWLocks that are fixed and those belonging to named tranches.
451+
*/
452+
staticvoid
453+
InitializeLWLocks(void)
454+
{
455+
intnumNamedLocks=NumLWLocksByNamedTranches();
456+
intid;
457+
inti;
458+
intj;
459+
LWLockPadded*lock;
460+
461+
/* Initialize all individual LWLocks in main array */
462+
for (id=0,lock=MainLWLockArray;id<NUM_INDIVIDUAL_LWLOCKS;id++,lock++)
463+
LWLockInitialize(&lock->lock,LWTRANCHE_MAIN);
464+
465+
/* Initialize buffer mapping LWLocks in main array */
466+
lock=MainLWLockArray+NUM_INDIVIDUAL_LWLOCKS;
467+
for (id=0;id<NUM_BUFFER_PARTITIONS;id++,lock++)
468+
LWLockInitialize(&lock->lock,LWTRANCHE_BUFFER_MAPPING);
469+
470+
/* Initialize lmgrs' LWLocks in main array */
471+
lock=MainLWLockArray+NUM_INDIVIDUAL_LWLOCKS+NUM_BUFFER_PARTITIONS;
472+
for (id=0;id<NUM_LOCK_PARTITIONS;id++,lock++)
473+
LWLockInitialize(&lock->lock,LWTRANCHE_LOCK_MANAGER);
474+
475+
/* Initialize predicate lmgrs' LWLocks in main array */
476+
lock=MainLWLockArray+NUM_INDIVIDUAL_LWLOCKS+
477+
NUM_BUFFER_PARTITIONS+NUM_LOCK_PARTITIONS;
478+
for (id=0;id<NUM_PREDICATELOCK_PARTITIONS;id++,lock++)
479+
LWLockInitialize(&lock->lock,LWTRANCHE_PREDICATE_LOCK_MANAGER);
480+
481+
/* Initialize named tranches. */
482+
if (NamedLWLockTrancheRequests>0)
483+
{
484+
char*trancheNames;
450485

451-
NamedLWLockTrancheArray= (NamedLWLockTranche*)
452-
&MainLWLockArray[numLocks+numNamedLocks];
486+
NamedLWLockTrancheArray= (NamedLWLockTranche*)
487+
&MainLWLockArray[NUM_FIXED_LWLOCKS+numNamedLocks];
453488

454-
trancheNames= (char*)NamedLWLockTrancheArray+
455-
(NamedLWLockTrancheRequests*sizeof(NamedLWLockTranche));
456-
lock=&MainLWLockArray[numLocks];
489+
trancheNames= (char*)NamedLWLockTrancheArray+
490+
(NamedLWLockTrancheRequests*sizeof(NamedLWLockTranche));
491+
lock=&MainLWLockArray[NUM_FIXED_LWLOCKS];
457492

458-
for (i=0;i<NamedLWLockTrancheRequests;i++)
459-
{
460-
NamedLWLockTrancheRequest*request;
461-
NamedLWLockTranche*tranche;
462-
char*name;
463-
464-
request=&NamedLWLockTrancheRequestArray[i];
465-
tranche=&NamedLWLockTrancheArray[i];
466-
467-
name=trancheNames;
468-
trancheNames+=strlen(request->tranche_name)+1;
469-
strcpy(name,request->tranche_name);
470-
tranche->lwLockTranche.name=name;
471-
tranche->trancheId=LWLockNewTrancheId();
472-
tranche->lwLockTranche.array_base=lock;
473-
tranche->lwLockTranche.array_stride=sizeof(LWLockPadded);
474-
475-
for (j=0;j<request->num_lwlocks;j++,lock++)
476-
LWLockInitialize(&lock->lock,tranche->trancheId);
477-
}
493+
for (i=0;i<NamedLWLockTrancheRequests;i++)
494+
{
495+
NamedLWLockTrancheRequest*request;
496+
NamedLWLockTranche*tranche;
497+
char*name;
498+
499+
request=&NamedLWLockTrancheRequestArray[i];
500+
tranche=&NamedLWLockTrancheArray[i];
501+
502+
name=trancheNames;
503+
trancheNames+=strlen(request->tranche_name)+1;
504+
strcpy(name,request->tranche_name);
505+
tranche->lwLockTranche.name=name;
506+
tranche->trancheId=LWLockNewTrancheId();
507+
tranche->lwLockTranche.array_base=lock;
508+
tranche->lwLockTranche.array_stride=sizeof(LWLockPadded);
509+
510+
for (j=0;j<request->num_lwlocks;j++,lock++)
511+
LWLockInitialize(&lock->lock,tranche->trancheId);
478512
}
479513
}
514+
}
515+
516+
/*
517+
* Register named tranches and tranches for fixed LWLocks.
518+
*/
519+
staticvoid
520+
RegisterLWLockTranches(void)
521+
{
522+
inti;
480523

481524
if (LWLockTrancheArray==NULL)
482525
{
483-
LWLockTranchesAllocated=16;
526+
LWLockTranchesAllocated=32;
484527
LWLockTrancheArray= (LWLockTranche**)
485528
MemoryContextAlloc(TopMemoryContext,
486529
LWLockTranchesAllocated*sizeof(LWLockTranche*));
@@ -492,6 +535,23 @@ CreateLWLocks(void)
492535
MainLWLockTranche.array_stride=sizeof(LWLockPadded);
493536
LWLockRegisterTranche(LWTRANCHE_MAIN,&MainLWLockTranche);
494537

538+
BufMappingLWLockTranche.name="buffer_mapping";
539+
BufMappingLWLockTranche.array_base=MainLWLockArray+NUM_INDIVIDUAL_LWLOCKS;
540+
BufMappingLWLockTranche.array_stride=sizeof(LWLockPadded);
541+
LWLockRegisterTranche(LWTRANCHE_BUFFER_MAPPING,&BufMappingLWLockTranche);
542+
543+
LockManagerLWLockTranche.name="lock_manager";
544+
LockManagerLWLockTranche.array_base=MainLWLockArray+NUM_INDIVIDUAL_LWLOCKS+
545+
NUM_BUFFER_PARTITIONS;
546+
LockManagerLWLockTranche.array_stride=sizeof(LWLockPadded);
547+
LWLockRegisterTranche(LWTRANCHE_LOCK_MANAGER,&LockManagerLWLockTranche);
548+
549+
PredicateLockManagerLWLockTranche.name="predicate_lock_manager";
550+
PredicateLockManagerLWLockTranche.array_base=MainLWLockArray+NUM_INDIVIDUAL_LWLOCKS+
551+
NUM_BUFFER_PARTITIONS+NUM_LOCK_PARTITIONS;
552+
PredicateLockManagerLWLockTranche.array_stride=sizeof(LWLockPadded);
553+
LWLockRegisterTranche(LWTRANCHE_PREDICATE_LOCK_MANAGER,&PredicateLockManagerLWLockTranche);
554+
495555
/* Register named tranches. */
496556
for (i=0;i<NamedLWLockTrancheRequests;i++)
497557
LWLockRegisterTranche(NamedLWLockTrancheArray[i].trancheId,

‎src/include/storage/lwlock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ typedef enum BuiltinTrancheIds
233233
LWTRANCHE_REPLICATION_ORIGIN,
234234
LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS,
235235
LWTRANCHE_PROC,
236+
LWTRANCHE_BUFFER_MAPPING,
237+
LWTRANCHE_LOCK_MANAGER,
238+
LWTRANCHE_PREDICATE_LOCK_MANAGER,
236239
LWTRANCHE_FIRST_USER_DEFINED
237240
}BuiltinTrancheIds;
238241

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp