pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Yura Sokolov <y.sokolov@postgrespro.ru>
To: Andrey M. Borodin <x4mmm@yandex-team.ru>
Cc: Dilip Kumar <dilipbalaut@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Subject: Re: Fix bank selection logic in SLRU
Date: Thu, 19 Dec 2024 18:48:14 +0300
Message-ID: <2c6c20c0-35a3-400c-80b2-fa995f2dd4d1@postgrespro.ru> (raw )
In-Reply-To: <899F5F09-0C56-4812-BCC2-C36CE36A4F8E@yandex-team.ru >
References: <9444dc46-ca47-43ed-9058-89c456316306@postgrespro.ru >
<4009750D-3EAE-4375-A7A8-3AD9922CDE1F@yandex-team.ru >
<CAFiTN-vwHHrsNdpwoQN-e495TXvGKAScW8XLsdUEqDEk1woGmA@mail.gmail.com >
<a325474f-5fd2-48f1-bdaf-5ded7af8c8b3@postgrespro.ru >
<CA2D0CC8-D2F3-42F8-AF32-8FB30D1FC93A@yandex-team.ru >
<438161d6-6f76-45cf-b8cd-0e756c9973e1@postgrespro.ru >
<899F5F09-0C56-4812-BCC2-C36CE36A4F8E@yandex-team.ru >
19.12.2024 15:10, Andrey M. Borodin wrote:
>
>
>> On 19 Dec 2024, at 15:37, Yura Sokolov <y.sokolov@postgrespro.ru> wrote:
>>
>> So, there's no more than 8192 banks at the moment.
>
> OK, but still current type indicates bitwise usage, while struct member is used as a number.
Ok, I agree. Here's version with type change bits16 -> uint16.
Attachments:
v2-0001-Fix-SLRU-bank-selection.patch (text/x-patch, 2.4K) download
From 4a16d64fe6eba042bfca7ff0b0d73ec8b749e6e0 Mon Sep 17 00:00:00 2001
From: Yura Sokolov <y.sokolov@postgrespro.ru>
Date: Tue, 10 Dec 2024 15:38:02 +0300
Subject: [PATCH v2] Fix SLRU bank selection.
Due to code evolution, nbanks is not power of two any more. But still
binary & were used to obtain bankno.
---
src/backend/access/transam/slru.c | 6 +++---
src/include/access/slru.h | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index e7f73bf4275..afedb5c039f 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -343,7 +343,7 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
ctl->shared = shared;
ctl->sync_handler = sync_handler;
ctl->long_segment_names = long_segment_names;
- ctl->bank_mask = (nslots / SLRU_BANK_SIZE) - 1;
+ ctl->nbanks = nbanks;
strlcpy(ctl->Dir, subdir, sizeof(ctl->Dir));
}
@@ -606,7 +606,7 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid)
{
SlruShared shared = ctl->shared;
LWLock *banklock = SimpleLruGetBankLock(ctl, pageno);
- int bankno = pageno & ctl->bank_mask;
+ int bankno = pageno % ctl->nbanks;
int bankstart = bankno * SLRU_BANK_SIZE;
int bankend = bankstart + SLRU_BANK_SIZE;
@@ -1177,7 +1177,7 @@ SlruSelectLRUPage(SlruCtl ctl, int64 pageno)
int bestinvalidslot = 0; /* keep compiler quiet */
int best_invalid_delta = -1;
int64 best_invalid_page_number = 0; /* keep compiler quiet */
- int bankno = pageno & ctl->bank_mask;
+ int bankno = pageno % ctl->nbanks;
int bankstart = bankno * SLRU_BANK_SIZE;
int bankend = bankstart + SLRU_BANK_SIZE;
diff --git a/src/include/access/slru.h b/src/include/access/slru.h
index 97e612cd100..648e202ff54 100644
--- a/src/include/access/slru.h
+++ b/src/include/access/slru.h
@@ -129,9 +129,9 @@ typedef struct SlruCtlData
SlruShared shared;
/*
- * Bitmask to determine bank number from page number.
+ * Number of banks to determine bank number from page number.
*/
- bits16 bank_mask;
+ uint16 nbanks;
/*
* If true, use long segment file names. Otherwise, use short file names.
@@ -179,7 +179,7 @@ SimpleLruGetBankLock(SlruCtl ctl, int64 pageno)
{
int bankno;
- bankno = pageno & ctl->bank_mask;
+ bankno = pageno % ctl->nbanks;
return &(ctl->shared->bank_locks[bankno].lock);
}
--
2.43.0
view thread (16+ messages) latest in thread
Message-ID: <2c6c20c0-35a3-400c-80b2-fa995f2dd4d1@postgrespro.ru>
Permalink: ../2c6c20c0-35a3-400c-80b2-fa995f2dd4d1@postgrespro.ru/
Also on: postgresql.org/message-id/2c6c20c0-35a3-400c-80b2-fa995f2dd4d1@postgrespro.ru
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: y.sokolov@postgrespro.ru, x4mmm@yandex-team.ru, dilipbalaut@gmail.com, alvherre@alvh.no-ip.org
Subject: Re: Fix bank selection logic in SLRU
In-Reply-To: <2c6c20c0-35a3-400c-80b2-fa995f2dd4d1@postgrespro.ru>
References: <9444dc46-ca47-43ed-9058-89c456316306@postgrespro.ru> <4009750D-3EAE-4375-A7A8-3AD9922CDE1F@yandex-team.ru> <CAFiTN-vwHHrsNdpwoQN-e495TXvGKAScW8XLsdUEqDEk1woGmA@mail.gmail.com> <a325474f-5fd2-48f1-bdaf-5ded7af8c8b3@postgrespro.ru> <CA2D0CC8-D2F3-42F8-AF32-8FB30D1FC93A@yandex-team.ru> <438161d6-6f76-45cf-b8cd-0e756c9973e1@postgrespro.ru> <899F5F09-0C56-4812-BCC2-C36CE36A4F8E@yandex-team.ru> <2c6c20c0-35a3-400c-80b2-fa995f2dd4d1@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox