Hi,
On 2016-04-11 07:09:18 -0400, Robert Haas wrote:
> Attached patch does that.
Thanks.
> > Additionally, doesn't this obsolete
> >
> > /*
> > * 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
>
> I didn't go as far as trying to remove this; a few other random things
> are using it.
All of the places using it look like they actually rather should use
CACHELINEALIGN...
> diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
> index 1ad68cd..8e6cbdb 100644
> --- a/src/backend/storage/ipc/shmem.c
> +++ b/src/backend/storage/ipc/shmem.c
> @@ -112,6 +112,7 @@ void
> InitShmemAllocation(void)
> {
> PGShmemHeader *shmhdr = ShmemSegHdr;
> + char *aligned;
>
> Assert(shmhdr != NULL);
>
> @@ -139,6 +140,11 @@ InitShmemAllocation(void)
> shmhdr->freeoffset += MAXALIGN(sizeof(slock_t));
> Assert(shmhdr->freeoffset <= shmhdr->totalsize);
>
> + /* Make sure the first allocation begins on a cache line boundary. */
> + aligned = (char *)
> + (CACHELINEALIGN((((char *) shmhdr) + shmhdr->freeoffset)));
> + shmhdr->freeoffset = aligned - (char *) shmhdr;
> +
> SpinLockInit(ShmemLock);
In the patch attached to http://www.postgresql.org/message-id/20160411051004.yvniqb2pkc7re5k7@alap3.anarazel.de
I did this instead by fixing up the actual shared memory allocation,
which seems a tiny bit cleaner. But the asserts added there seem like a
worthwhile addition to me.
Greetings,
Andres Freund