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

Commitf9baaf9

Browse files
committed
Simplify coding in slru.c
New code in53c2a97 uses direct array access toshared->bank_locks[bankno].lock which can be made a little bit morelegible by using the SimpleLruGetBankLock helper function.Nothing terribly serious, but let's add some clarity.Discussion:https://postgr.es/m/202403041517.3a35jw53os65@alvherre.pgsql
1 parentc8a61e3 commitf9baaf9

File tree

1 file changed

+9
-9
lines changed
  • src/backend/access/transam

1 file changed

+9
-9
lines changed

‎src/backend/access/transam/slru.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -489,14 +489,14 @@ SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok,
489489
TransactionIdxid)
490490
{
491491
SlruSharedshared=ctl->shared;
492+
LWLock*banklock=SimpleLruGetBankLock(ctl,pageno);
492493

493-
Assert(LWLockHeldByMeInMode(SimpleLruGetBankLock(ctl,pageno),LW_EXCLUSIVE));
494+
Assert(LWLockHeldByMeInMode(banklock,LW_EXCLUSIVE));
494495

495496
/* Outer loop handles restart if we must wait for someone else's I/O */
496497
for (;;)
497498
{
498499
intslotno;
499-
intbankno;
500500
boolok;
501501

502502
/* See if page already is in memory; if not, pick victim slot */
@@ -539,10 +539,9 @@ SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok,
539539

540540
/* Acquire per-buffer lock (cannot deadlock, see notes at top) */
541541
LWLockAcquire(&shared->buffer_locks[slotno].lock,LW_EXCLUSIVE);
542-
bankno=SlotGetBankNumber(slotno);
543542

544543
/* Release bank lock while doing I/O */
545-
LWLockRelease(&shared->bank_locks[bankno].lock);
544+
LWLockRelease(banklock);
546545

547546
/* Do the read */
548547
ok=SlruPhysicalReadPage(ctl,pageno,slotno);
@@ -551,7 +550,7 @@ SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok,
551550
SimpleLruZeroLSNs(ctl,slotno);
552551

553552
/* Re-acquire bank control lock and update page state */
554-
LWLockAcquire(&shared->bank_locks[bankno].lock,LW_EXCLUSIVE);
553+
LWLockAcquire(banklock,LW_EXCLUSIVE);
555554

556555
Assert(shared->page_number[slotno]==pageno&&
557556
shared->page_status[slotno]==SLRU_PAGE_READ_IN_PROGRESS&&
@@ -592,12 +591,13 @@ int
592591
SimpleLruReadPage_ReadOnly(SlruCtlctl,int64pageno,TransactionIdxid)
593592
{
594593
SlruSharedshared=ctl->shared;
594+
LWLock*banklock=SimpleLruGetBankLock(ctl,pageno);
595595
intbankno=pageno&ctl->bank_mask;
596596
intbankstart=bankno*SLRU_BANK_SIZE;
597597
intbankend=bankstart+SLRU_BANK_SIZE;
598598

599599
/* Try to find the page while holding only shared lock */
600-
LWLockAcquire(&shared->bank_locks[bankno].lock,LW_SHARED);
600+
LWLockAcquire(banklock,LW_SHARED);
601601

602602
/* See if page is already in a buffer */
603603
for (intslotno=bankstart;slotno<bankend;slotno++)
@@ -617,8 +617,8 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid)
617617
}
618618

619619
/* No luck, so switch to normal exclusive lock and do regular read */
620-
LWLockRelease(&shared->bank_locks[bankno].lock);
621-
LWLockAcquire(&shared->bank_locks[bankno].lock,LW_EXCLUSIVE);
620+
LWLockRelease(banklock);
621+
LWLockAcquire(banklock,LW_EXCLUSIVE);
622622

623623
returnSimpleLruReadPage(ctl,pageno, true,xid);
624624
}
@@ -1167,7 +1167,7 @@ SlruSelectLRUPage(SlruCtl ctl, int64 pageno)
11671167
intbankstart=bankno*SLRU_BANK_SIZE;
11681168
intbankend=bankstart+SLRU_BANK_SIZE;
11691169

1170-
Assert(LWLockHeldByMe(&shared->bank_locks[bankno].lock));
1170+
Assert(LWLockHeldByMe(SimpleLruGetBankLock(ctl,pageno)));
11711171

11721172
/* See if page already has a buffer assigned */
11731173
for (intslotno=0;slotno<shared->num_slots;slotno++)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp