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

Commit69ab446

Browse files
committed
Fix SLRU bank selection code
The originally submitted code (using bit masking) was correct when thenumber of slots was restricted to be a power of two -- but thatlimitation was removed during development that led to commit53c2a97, which made the bank selection code incorrect. This led toalways using a smaller number of banks than available. Change said codeto use integer modulo instead, which works correctly with an arbitrarynumber of banks.It's likely that we could improve on this to avoid runtime use ofinteger division. But with this change we're, at least, not wastingmemory on unused banks, and more banks mean less contention, which islikely to have a much higher performance impact than a singleinstruction's latency.Author: Yura Sokolov <y.sokolov@postgrespro.ru>Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>Discussion:https://postgr.es/m/9444dc46-ca47-43ed-9058-89c456316306@postgrespro.ru
1 parent970b97e commit69ab446

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
343343
ctl->shared=shared;
344344
ctl->sync_handler=sync_handler;
345345
ctl->long_segment_names=long_segment_names;
346-
ctl->bank_mask=(nslots /SLRU_BANK_SIZE)-1;
346+
ctl->nbanks=nbanks;
347347
strlcpy(ctl->Dir,subdir,sizeof(ctl->Dir));
348348
}
349349

@@ -606,7 +606,7 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid)
606606
{
607607
SlruSharedshared=ctl->shared;
608608
LWLock*banklock=SimpleLruGetBankLock(ctl,pageno);
609-
intbankno=pageno&ctl->bank_mask;
609+
intbankno=pageno%ctl->nbanks;
610610
intbankstart=bankno*SLRU_BANK_SIZE;
611611
intbankend=bankstart+SLRU_BANK_SIZE;
612612

@@ -1180,7 +1180,7 @@ SlruSelectLRUPage(SlruCtl ctl, int64 pageno)
11801180
intbestinvalidslot=0;/* keep compiler quiet */
11811181
intbest_invalid_delta=-1;
11821182
int64best_invalid_page_number=0;/* keep compiler quiet */
1183-
intbankno=pageno&ctl->bank_mask;
1183+
intbankno=pageno%ctl->nbanks;
11841184
intbankstart=bankno*SLRU_BANK_SIZE;
11851185
intbankend=bankstart+SLRU_BANK_SIZE;
11861186

‎src/include/access/slru.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ typedef struct SlruCtlData
128128
{
129129
SlruSharedshared;
130130

131-
/*
132-
* Bitmask to determine bank number from page number.
133-
*/
134-
bits16bank_mask;
131+
/* Number of banks in this SLRU. */
132+
uint16nbanks;
135133

136134
/*
137135
* If true, use long segment file names. Otherwise, use short file names.
@@ -163,7 +161,6 @@ typedef struct SlruCtlData
163161
* it's always the same, it doesn't need to be in shared memory.
164162
*/
165163
charDir[64];
166-
167164
}SlruCtlData;
168165

169166
typedefSlruCtlData*SlruCtl;
@@ -179,7 +176,7 @@ SimpleLruGetBankLock(SlruCtl ctl, int64 pageno)
179176
{
180177
intbankno;
181178

182-
bankno=pageno&ctl->bank_mask;
179+
bankno=pageno%ctl->nbanks;
183180
return&(ctl->shared->bank_locks[bankno].lock);
184181
}
185182

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp