From: Sean Chittenden <seanc@joyent.com>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@postgresql.org, stadtkind2@gmx.de, Sam Gwydir <sam.gwydir@joyent.com>
Cc: Sean Chittenden <sean@chittenden.org>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Re: [PATCH] BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
Date: Thu, 5 Oct 2017 14:34:37 -0700
Message-ID: <b0522138-40bb-4775-ad69-eb67fb7e3521@Spark> (raw)
In-Reply-To: <20171004175607.356vuonm5pq7t2vo@alap3.anarazel.de>
References: <f2ba267d-3a6d-4ffb-b842-9d6d1c0b3b1e@Spark>
<6f48fd17-6b73-487f-9467-6e2f6559d07f@Spark>
<20171004175607.356vuonm5pq7t2vo@alap3.anarazel.de>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Fair enough. We observed a ~4x amplification in memory usage so it was rather severe in our case.
The patch you referenced was a much nicer approach and Sam updated it to match that style (thank you Sam!). We debated this internally and feel strongly that this should be exposed as a runtime GUC as suggested. What's your take on the attached patch?
-sc
--
Sean Chittenden
seanc@joyent.com
On Oct 4, 2017, 10:56 AM -0700, Andres Freund <andres@anarazel.de>, wrote:
> Hi,
>
> On 2017-10-04 10:47:06 -0700, Sean Chittenden wrote:
> > Hello. We identified the same problem. Sam Gwydir and Josh Clulow were able to put together the appropriate fix after.
> >
> > The breakage in src/backend/port/sysv_shmem.c and src/include/storage/dsm_impl.h should be back ported to all supported versions (the regression was introduced between the 9.2 and 9.3 branches).
>
> Personally I don't think "breakage" is quite the right work.
>
> I also don't like that we're unconditionally not using
> USE_ANONYMOUS_SHMEM - doesn't that run into similar config limits on
> solaris based stuff as it does on linux etc?
>
> I think if we want to do this, we should rather go with a patch like
> https://www.postgresql.org/message-id/20140422121921.GD4449@awork2.anarazel.de
>
> Greetings,
>
> Andres Freund
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:ism2.patch (application/octet-stream, 6.2K) downloaddiff --git c/src/backend/port/sysv_shmem.c w/src/backend/port/sysv_shmem.cindex 850eafddc3..bbc3cbbd2a 100644--- c/src/backend/port/sysv_shmem.c+++ w/src/backend/port/sysv_shmem.c@@ -55,15 +55,20 @@
* false, we might need to add compile and/or run-time tests here and do this
* only if the running kernel supports it.
*
- * However, we must always disable this logic in the EXEC_BACKEND case, and+ * There are two cases in which we disable this logic. On systems that support+ * intimate shared memory (e.g. illumos and Solaris), we prefer the usage of+ * System V shared memory in order to take advantage of the performance+ * improvements that sharing page tables provides.+ *+ * In addition, we must always disable this logic in the EXEC_BACKEND case, and
* fall back to the old method of allocating the entire segment using System V
* shared memory, because there's no way to attach an anonymous mmap'd segment
* to a process after exec(). Since EXEC_BACKEND is intended only for
* developer use, this shouldn't be a big problem. Because of this, we do
* not worry about supporting anonymous shmem in the EXEC_BACKEND cases below.
*/
-#ifndef EXEC_BACKEND-#define USE_ANONYMOUS_SHMEM+#if !defined(EXEC_BACKEND) && !defined(SHMEM_TYPE_SYSV)+# define USE_ANONYMOUS_SHMEM
#endif
@@ -576,17 +581,23 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
#ifdef USE_ANONYMOUS_SHMEM
- AnonymousShmem = CreateAnonymousSegment(&size);- AnonymousShmemSize = size;+ if (shared_memory_type == SHMEM_TYPE_MMAP)+ {+ AnonymousShmem = CreateAnonymousSegment(&size);+ AnonymousShmemSize = size;- /* Register on-exit routine to unmap the anonymous segment */- on_shmem_exit(AnonymousShmemDetach, (Datum) 0);+ /* Register on-exit routine to unmap the anonymous segment */+ on_shmem_exit(AnonymousShmemDetach, (Datum) 0);- /* Now we need only allocate a minimal-sized SysV shmem block. */- sysvsize = sizeof(PGShmemHeader);-#else- sysvsize = size;+ /* Now we need only allocate a minimal-sized SysV shmem block. */+ sysvsize = sizeof(PGShmemHeader);+ }+ else
#endif
+ {+ Assert(shared_memory_type == SHMEM_TYPE_SYSV);+ sysvsize = size;+ }
/* Make sure PGSharedMemoryAttach doesn't fail without need */
UsedShmemSegAddr = NULL;
diff --git c/src/backend/storage/ipc/ipci.c w/src/backend/storage/ipc/ipci.cindex c04b17fa8e..44c3a28aa2 100644--- c/src/backend/storage/ipc/ipci.c+++ w/src/backend/storage/ipc/ipci.c@@ -45,6 +45,8 @@
#include "storage/spin.h"
#include "utils/snapmgr.h"
+/* GUCs */+int shared_memory_type = DEFAULT_SHARED_MEMORY_TYPE;
shmem_startup_hook_type shmem_startup_hook = NULL;
diff --git c/src/backend/utils/misc/guc.c w/src/backend/utils/misc/guc.cindex 4f1891f844..9527cc028a 100644--- c/src/backend/utils/misc/guc.c+++ w/src/backend/utils/misc/guc.c@@ -393,6 +393,19 @@ static const struct config_enum_entry force_parallel_mode_options[] = {
{NULL, 0, false}
};
+static struct config_enum_entry shared_memory_options[] = {+#ifndef WIN32+ { "sysv", SHMEM_TYPE_SYSV, false},+#endif+#ifndef EXEC_BACKEND+ { "mmap", SHMEM_TYPE_MMAP, false},+#endif+#ifdef WIN32+ { "windows", SHMEM_TYPE_WINDOWS, false},+#endif+ {NULL, 0, false}+};+
/*
* Options for enum values stored in other modules
*/
@@ -3748,6 +3761,16 @@ static struct config_enum ConfigureNamesEnum[] =
},
{
+ {"shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,+ gettext_noop("Selects the shared memory implementation used."),+ NULL+ },+ &shared_memory_type,+ DEFAULT_SHARED_MEMORY_TYPE, shared_memory_options,+ NULL, NULL, NULL+ },++ {
{"dynamic_shared_memory_type", PGC_POSTMASTER, RESOURCES_MEM,
gettext_noop("Selects the dynamic shared memory implementation used."),
NULL
diff --git c/src/backend/utils/misc/postgresql.conf.sample w/src/backend/utils/misc/postgresql.conf.sampleindex fa6c0eaa80..8f59028ea2 100644--- c/src/backend/utils/misc/postgresql.conf.sample+++ w/src/backend/utils/misc/postgresql.conf.sample@@ -124,6 +124,11 @@
#replacement_sort_tuples = 150000 # limits use of replacement selection sort
#autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem
#max_stack_depth = 2MB # min 100kB
+#shared_memory_type = mmap # the default is the first option+ # supported by the operating system:+ # mmap+ # sysv+ # windows
#dynamic_shared_memory_type = posix # the default is the first option
# supported by the operating system:
# posix
diff --git c/src/bin/initdb/initdb.c w/src/bin/initdb/initdb.cindex 27d134e17d..329ed88c8b 100644--- c/src/bin/initdb/initdb.c+++ w/src/bin/initdb/initdb.c@@ -1050,12 +1050,13 @@ set_null_conf(void)
* attempt to reproduce what the postmaster will do when allocating a POSIX
* segment in dsm_impl.c; if it doesn't work, we assume it won't work for
* the postmaster either, and configure the cluster for System V shared
- * memory instead.+ * memory instead. However, on Solaris-derived systems, System V shared+ * memory is preferred.
*/
static char *
choose_dsm_implementation(void)
{
-#ifdef HAVE_SHM_OPEN+#if defined(HAVE_SHM_OPEN) && !defined(__sun)
int ntries = 10;
while (ntries > 0)
diff --git c/src/include/storage/pg_shmem.h w/src/include/storage/pg_shmem.hindex 6bf803ab88..761fd48df0 100644--- c/src/include/storage/pg_shmem.h+++ w/src/include/storage/pg_shmem.h@@ -41,9 +41,18 @@ typedef struct PGShmemHeader /* standard header for all Postgres shmem */
#endif
} PGShmemHeader;
-/* GUC variable */+/* GUC variables */+extern int shared_memory_type;
extern int huge_pages;
+/* Possible values for shared_memory_type */+typedef enum+{+ SHMEM_TYPE_WINDOWS,+ SHMEM_TYPE_SYSV,+ SHMEM_TYPE_MMAP+} PGShmemType;+
/* Possible values for huge_pages */
typedef enum
{
@@ -59,6 +68,14 @@ extern HANDLE UsedShmemSegID;
#endif
extern void *UsedShmemSegAddr;
+#if !defined(WIN32) && !defined(EXEC_BACKEND)+#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP+#elif !defined(WIN32)+#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_SYSV+#else+#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_WINDOWS+#endif+
#ifdef EXEC_BACKEND
extern void PGSharedMemoryReAttach(void);
extern void PGSharedMemoryNoReAttach(void);
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: seanc@joyent.com, andres@anarazel.de, sam.gwydir@joyent.com, sean@chittenden.org
Subject: Re: [PATCH] BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
In-Reply-To: <b0522138-40bb-4775-ad69-eb67fb7e3521@Spark>
References: <f2ba267d-3a6d-4ffb-b842-9d6d1c0b3b1e@Spark> <6f48fd17-6b73-487f-9467-6e2f6559d07f@Spark> <20171004175607.356vuonm5pq7t2vo@alap3.anarazel.de> <b0522138-40bb-4775-ad69-eb67fb7e3521@Spark>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox