Use PGAlignedBlock instead of "char buf[BLCKSZ]" in more places

Поиск
Список
Период
Сортировка
От Bharath Rupireddy
Тема Use PGAlignedBlock instead of "char buf[BLCKSZ]" in more places
Дата
Msg-id CALj2ACUHqyGvTWn3+Yt21eyDmu7SrYVOcGZ7SAwsvsBK7dJEMg@mail.gmail.com
обсуждение исходный текст
Ответы Re: Use PGAlignedBlock instead of "char buf[BLCKSZ]" in more places  (Michael Paquier <michael@paquier.xyz>)
Список pgsql-hackers
Hi,

The commit 44cac934 replaced "char buf[BLCKSZ]" with PGAlignedBlock to avoid issues on alignment-picky hardware. While it replaced most of the instances, there are still some more left. How about we use PGAlignedBlock there too, something like the attached patch? A note [2] in the commit 44cac934 says that ensuring proper alignment makes kernel data transfers fasters and the left-over "char buf[BLCKSZ]" either do read() or write() system calls, so it might be worth to align them with PGAlignedBlock.

Thoughts?

PS: FWIW, I verified what difference actually char buf[BLCKSZ] and the union PGAlignedBlock does make with alignment with a sample code like [3] which gives a different alignment requirement, see below:

size of data 8192, alignment of data 1
size of data_aligned 8192, alignment of data_aligned 8

[1]
commit 44cac9346479d4b0cc9195b0267fd13eb4e7442c
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date:   Sat Sep 1 15:27:12 2018 -0400

    Avoid using potentially-under-aligned page buffers.

[2]
   I used these types even for variables where there's no risk of a
    misaligned access, since ensuring proper alignment should make
    kernel data transfers faster.  I also changed some places where
    we had been palloc'ing short-lived buffers, for coding style
    uniformity and to save palloc/pfree overhead.

[3]
#include <stdio.h>

#define BLCKSZ 8192

typedef union PGAlignedBlock
{
    char        data[BLCKSZ];
    double      force_align_d;
    long long int   force_align_i64;
} PGAlignedBlock;

int main(int argc, char **argv)
{
    char data[BLCKSZ];
    PGAlignedBlock data_aligned;

    printf("size of data %ld, alignment of data %ld\n", sizeof(data), _Alignof(data));
    printf("size of data_aligned %ld, alignment of data_aligned %ld\n", sizeof(data_aligned), _Alignof(data_aligned));

    return 0;
}


--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Вложения

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

Предыдущее
От: Davin Shearer
Дата:
Сообщение: Re: Emitting JSON to file using COPY TO
Следующее
От: Tomas Vondra
Дата:
Сообщение: Re: Syncrep and improving latency due to WAL throttling