Re: Question on alignment

From: Antonin Houska <ah(at)cybertec(dot)at>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Question on alignment
Date: 2019-04-01 09:21:44
Message-ID: 8764.1554110504@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:

> On 01/04/2019 11:01, Antonin Houska wrote:
> > In copydir.c:copy_file() I read
> >
> > /* Use palloc to ensure we get a maxaligned buffer */
> > buffer = palloc(COPY_BUF_SIZE);
> >
> > No data type wider than a single byte is used to access the data in the
> > buffer, and neither read() nor write() should require any specific alignment.
> > Can someone please explain why alignment matters here?
>
> An aligned buffer can allow optimizations in the kernel, when it copies the
> data. So it's not strictly required, but potentially makes the read() and
> write() faster.

Thanks. Your response reminds me of buffer alignment:

/*
* Preferred alignment for disk I/O buffers. On some CPUs, copies between
* user space and kernel space are significantly faster if the user buffer
* is aligned on a larger-than-MAXALIGN boundary. Ideally this should be
* a platform-dependent value, but for now we just hard-wire it.
*/
#define ALIGNOF_BUFFER 32

Is this what you mean? Since palloc() only ensures MAXIMUM_ALIGNOF, that
wouldn't help here anyway.

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2019-04-01 09:23:47 Re: Why does ExecComputeStoredGenerated() form a heap tuple
Previous Message Heikki Linnakangas 2019-04-01 09:09:09 Re: Question on alignment