Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock

Поиск
Список
Период
Сортировка
От tender wang
Тема Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock
Дата
Msg-id CAHewXNmGoGJYiSMxApNtrtHZ-GVQ_QxpOPnOiRnwKRqq3+fQDQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock  ("Andrey M. Borodin" <x4mmm@yandex-team.ru>)
Ответы Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock
Список pgsql-hackers


Andrey M. Borodin <x4mmm@yandex-team.ru> 于2023年12月14日周四 17:35写道:


> On 14 Dec 2023, at 14:28, tender wang <tndrwang@gmail.com> wrote:
>
>   Now that AND is more faster, Can we  replace the '% SLRU_MAX_BANKLOCKS' operation in  SimpleLruGetBankLock()  with '& 127'

unsigned int GetBankno1(unsigned int pageno) {
return pageno & 127;
}

unsigned int GetBankno2(unsigned int pageno) {
return pageno % 128;
}

Generates with -O2

GetBankno1(unsigned int):
mov eax, edi
and eax, 127
ret
GetBankno2(unsigned int):
mov eax, edi
and eax, 127
ret


Compiler is smart enough with constants.

Yeah, that's true.

int GetBankno(long pageno) {
    unsigned short bank_mask = 128;
    int bankno = (pageno & bank_mask) % 128;
    return bankno;
}
enable -O2, only one  instruction:
xor     eax, eax

But if we all use '%',  thing changs as below:
int GetBankno(long pageno) {
    unsigned short bank_mask = 128;
    int bankno = (pageno % bank_mask) % 128;
    return bankno;
}
        mov     rdx, rdi
        sar     rdx, 63
        shr     rdx, 57
        lea     rax, [rdi+rdx]
        and     eax, 127
        sub     eax, edx


Best regards, Andrey Borodin.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Andrey M. Borodin"
Дата:
Сообщение: Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock
Следующее
От: Emre Hasegeli
Дата:
Сообщение: Re: btree_gist into core?