Re: Misaligned BufferDescriptors causing major performance problems on AMD

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Greg Stark <stark(at)mit(dot)edu>, Peter Geoghegan <pg(at)heroku(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Misaligned BufferDescriptors causing major performance problems on AMD
Date: 2015-01-02 17:25:52
Message-ID: 20150102172552.GD3064@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2014-12-29 16:59:05 -0500, Bruce Momjian wrote:
> diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c
> new file mode 100644
> index ff6c713..c4dce5b
> *** a/src/backend/storage/buffer/buf_init.c
> --- b/src/backend/storage/buffer/buf_init.c
> *************** InitBufferPool(void)
> *** 67,72 ****
> --- 67,73 ----
> bool foundBufs,
> foundDescs;
>
> + fprintf(stderr, "Buffer Descriptors size = %ld\n", sizeof(BufferDesc));
> BufferDescriptors = (BufferDesc *)
> ShmemInitStruct("Buffer Descriptors",
> NBuffers * sizeof(BufferDesc), &foundDescs);
> diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
> new file mode 100644
> index 2ea2216..669c07f
> *** a/src/backend/storage/ipc/shmem.c
> --- b/src/backend/storage/ipc/shmem.c
> *************** ShmemInitStruct(const char *name, Size s
> *** 327,332 ****
> --- 327,335 ----
> ShmemIndexEnt *result;
> void *structPtr;
>
> + if (strcmp(name, "Buffer Descriptors") == 0)
> + size = BUFFERALIGN(size) + 64;
> +
> LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE);
>
> if (!ShmemIndex)
> *************** ShmemInitStruct(const char *name, Size s
> *** 413,418 ****
> --- 416,432 ----
> " \"%s\" (%zu bytes requested)",
> name, size)));
> }
> + if (strcmp(name, "Buffer Descriptors") == 0)
> + {
> + /* align on 32 */
> + if ((int64)structPtr % 32 != 0)
> + structPtr = (void *)((int64)structPtr + 32 - (int64)structPtr % 32);
> + /* align on 32 but not 64 */
> + if ((int64)structPtr % 64 == 0)
> + structPtr = (void *)((int64)structPtr + 32);
> + }
> + fprintf(stderr, "shared memory alignment of %s: %ld-byte\n", name,
> + (int64)structPtr % 64 == 0 ? 64 : (int64)structPtr % 64);
> result->size = size;
> result->location = structPtr;
> }

> diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c
> new file mode 100644
> index ff6c713..c4dce5b
> *** a/src/backend/storage/buffer/buf_init.c
> --- b/src/backend/storage/buffer/buf_init.c
> *************** InitBufferPool(void)
> *** 67,72 ****
> --- 67,73 ----
> bool foundBufs,
> foundDescs;
>
> + fprintf(stderr, "Buffer Descriptors size = %ld\n", sizeof(BufferDesc));
> BufferDescriptors = (BufferDesc *)
> ShmemInitStruct("Buffer Descriptors",
> NBuffers * sizeof(BufferDesc), &foundDescs);
> diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
> new file mode 100644
> index 2ea2216..50f836e
> *** a/src/backend/storage/ipc/shmem.c
> --- b/src/backend/storage/ipc/shmem.c
> *************** ShmemInitStruct(const char *name, Size s
> *** 327,332 ****
> --- 327,335 ----
> ShmemIndexEnt *result;
> void *structPtr;
>
> + if (strcmp(name, "Buffer Descriptors") == 0)
> + size = BUFFERALIGN(size) + 64;
> +
> LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE);
>
> if (!ShmemIndex)
> *************** ShmemInitStruct(const char *name, Size s
> *** 413,418 ****
> --- 416,429 ----
> " \"%s\" (%zu bytes requested)",
> name, size)));
> }
> + if (strcmp(name, "Buffer Descriptors") == 0)
> + {
> + /* align on 64 */
> + if ((int64)structPtr % 64 != 0)
> + structPtr = (void *)((int64)structPtr + 64 - (int64)structPtr % 64);
> + }
> + fprintf(stderr, "shared memory alignment of %s: %ld-byte\n", name,
> + (int64)structPtr % 64 == 0 ? 64 : (int64)structPtr % 64);
> result->size = size;
> result->location = structPtr;
> }

I can't run tests right now...

What exactly do you want to see with these tests? that's essentially
what I've already benchmarked + some fprintfs?

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2015-01-02 18:05:49 Re: Compression of full-page-writes
Previous Message Bruce Momjian 2015-01-02 17:24:58 Re: Compression of full-page-writes