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

Commit79a7ff0

Browse files
committed
Code cleanup in the wake of recent LWLock refactoring.
As of commitc1772ad, there's nolonger any way of requesting additional LWLocks in the main tranche,so we don't need NumLWLocks() or LWLockAssign() any more. Also,some of the allocation counters that we had previously aren't neededany more either.Amit Kapila
1 parent019e788 commit79a7ff0

File tree

2 files changed

+17
-74
lines changed

2 files changed

+17
-74
lines changed

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

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#endif
9292

9393

94-
/* We use the ShmemLock spinlock to protectLWLockAssign */
94+
/* We use the ShmemLock spinlock to protectLWLockCounter */
9595
externslock_t*ShmemLock;
9696

9797
#defineLW_FLAG_HAS_WAITERS((uint32) 1 << 30)
@@ -363,30 +363,6 @@ NumLWLocksByNamedTranches(void)
363363
returnnumLocks;
364364
}
365365

366-
/*
367-
* Compute number of LWLocks to allocate in the main array.
368-
*/
369-
staticint
370-
NumLWLocks(void)
371-
{
372-
intnumLocks;
373-
374-
/*
375-
* Many users of LWLocks no longer reserve space in the main array here,
376-
* but instead allocate separate tranches. The latter approach has the
377-
* advantage of allowing LWLOCK_STATS and LOCK_DEBUG output to produce
378-
* more useful output.
379-
*/
380-
381-
/* Predefined LWLocks */
382-
numLocks=NUM_FIXED_LWLOCKS;
383-
384-
/* Disallow named LWLocks' requests after startup */
385-
lock_named_request_allowed= false;
386-
387-
returnnumLocks;
388-
}
389-
390366
/*
391367
* Compute shmem space needed for LWLocks and named tranches.
392368
*/
@@ -395,15 +371,15 @@ LWLockShmemSize(void)
395371
{
396372
Sizesize;
397373
inti;
398-
intnumLocks=NumLWLocks();
374+
intnumLocks=NUM_FIXED_LWLOCKS;
399375

400376
numLocks+=NumLWLocksByNamedTranches();
401377

402378
/* Space for the LWLock array. */
403379
size=mul_size(numLocks,sizeof(LWLockPadded));
404380

405381
/* Space for dynamic allocation counter, plus room for alignment. */
406-
size=add_size(size,3*sizeof(int)+LWLOCK_PADDED_SIZE);
382+
size=add_size(size,sizeof(int)+LWLOCK_PADDED_SIZE);
407383

408384
/* space for named tranches. */
409385
size=add_size(size,mul_size(NamedLWLockTrancheRequests,sizeof(NamedLWLockTranche)));
@@ -412,6 +388,9 @@ LWLockShmemSize(void)
412388
for (i=0;i<NamedLWLockTrancheRequests;i++)
413389
size=add_size(size,strlen(NamedLWLockTrancheRequestArray[i].tranche_name)+1);
414390

391+
/* Disallow named LWLocks' requests after startup */
392+
lock_named_request_allowed= false;
393+
415394
returnsize;
416395
}
417396

@@ -433,7 +412,7 @@ CreateLWLocks(void)
433412

434413
if (!IsUnderPostmaster)
435414
{
436-
intnumLocks=NumLWLocks();
415+
intnumLocks=NUM_FIXED_LWLOCKS;
437416
intnumNamedLocks=NumLWLocksByNamedTranches();
438417
SizespaceLocks=LWLockShmemSize();
439418
LWLockPadded*lock;
@@ -445,8 +424,8 @@ CreateLWLocks(void)
445424
/* Allocate space */
446425
ptr= (char*)ShmemAlloc(spaceLocks);
447426

448-
/* Leave room for dynamic allocation oflocks andtranches */
449-
ptr+=3*sizeof(int);
427+
/* Leave room for dynamic allocation of tranches */
428+
ptr+=sizeof(int);
450429

451430
/* Ensure desired alignment of LWLock array */
452431
ptr+=LWLOCK_PADDED_SIZE- ((uintptr_t)ptr) %LWLOCK_PADDED_SIZE;
@@ -458,16 +437,11 @@ CreateLWLocks(void)
458437
LWLockInitialize(&lock->lock,LWTRANCHE_MAIN);
459438

460439
/*
461-
* Initialize the dynamic-allocation counters, which are stored just
462-
* before the first LWLock. LWLockCounter[0] is the allocation
463-
* counter for lwlocks, LWLockCounter[1] is the maximum number that
464-
* can be allocated from the main array, and LWLockCounter[2] is the
465-
* allocation counter for tranches.
440+
* Initialize the dynamic-allocation counter for tranches, which is
441+
* stored just before the first LWLock.
466442
*/
467-
LWLockCounter= (int*) ((char*)MainLWLockArray-3*sizeof(int));
468-
LWLockCounter[0]=NUM_FIXED_LWLOCKS;
469-
LWLockCounter[1]=numLocks;
470-
LWLockCounter[2]=LWTRANCHE_FIRST_USER_DEFINED;
443+
LWLockCounter= (int*) ((char*)MainLWLockArray-sizeof(int));
444+
*LWLockCounter=LWTRANCHE_FIRST_USER_DEFINED;
471445

472446
/* Initialize named tranches. */
473447
if (NamedLWLockTrancheRequests>0)
@@ -535,32 +509,6 @@ InitLWLockAccess(void)
535509
#endif
536510
}
537511

538-
/*
539-
* LWLockAssign - assign a dynamically-allocated LWLock number
540-
*
541-
* We interlock this using the same spinlock that is used to protect
542-
* ShmemAlloc(). Interlocking is not really necessary during postmaster
543-
* startup, but it is needed if any user-defined code tries to allocate
544-
* LWLocks after startup.
545-
*/
546-
LWLock*
547-
LWLockAssign(void)
548-
{
549-
LWLock*result;
550-
int*LWLockCounter;
551-
552-
LWLockCounter= (int*) ((char*)MainLWLockArray-3*sizeof(int));
553-
SpinLockAcquire(ShmemLock);
554-
if (LWLockCounter[0] >=LWLockCounter[1])
555-
{
556-
SpinLockRelease(ShmemLock);
557-
elog(ERROR,"no more LWLocks available");
558-
}
559-
result=&MainLWLockArray[LWLockCounter[0]++].lock;
560-
SpinLockRelease(ShmemLock);
561-
returnresult;
562-
}
563-
564512
/*
565513
* GetNamedLWLockTranche - returns the base address of LWLock from the
566514
*specified tranche.
@@ -574,16 +522,13 @@ GetNamedLWLockTranche(const char *tranche_name)
574522
{
575523
intlock_pos;
576524
inti;
577-
int*LWLockCounter;
578-
579-
LWLockCounter= (int*) ((char*)MainLWLockArray-3*sizeof(int));
580525

581526
/*
582527
* Obtain the position of base address of LWLock belonging to requested
583528
* tranche_name in MainLWLockArray. LWLocks for named tranches are placed
584-
* in MainLWLockArray afterLWLocks specified by LWLockCounter[1].
529+
* in MainLWLockArray afterfixed locks.
585530
*/
586-
lock_pos=LWLockCounter[1];
531+
lock_pos=NUM_FIXED_LWLOCKS;
587532
for (i=0;i<NamedLWLockTrancheRequests;i++)
588533
{
589534
if (strcmp(NamedLWLockTrancheRequestArray[i].tranche_name,
@@ -609,9 +554,9 @@ LWLockNewTrancheId(void)
609554
intresult;
610555
int*LWLockCounter;
611556

612-
LWLockCounter= (int*) ((char*)MainLWLockArray-3*sizeof(int));
557+
LWLockCounter= (int*) ((char*)MainLWLockArray-sizeof(int));
613558
SpinLockAcquire(ShmemLock);
614-
result=LWLockCounter[2]++;
559+
result=(*LWLockCounter)++;
615560
SpinLockRelease(ShmemLock);
616561

617562
returnresult;

‎src/include/storage/lwlock.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ extern void InitLWLockAccess(void);
196196
externvoidRequestNamedLWLockTranche(constchar*tranche_name,intnum_lwlocks);
197197
externLWLockPadded*GetNamedLWLockTranche(constchar*tranche_name);
198198

199-
externLWLock*LWLockAssign(void);
200-
201199
/*
202200
* There is another, more flexible method of obtaining lwlocks. First, call
203201
* LWLockNewTrancheId just once to obtain a tranche ID; this allocates from

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp