pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
5+ messages / 3 participants
[nested] [flat]

* BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
@ 2015-06-08 13:24  stadtkind2@gmx.de
  0 siblings, 0 replies; 5+ messages in thread

From: stadtkind2@gmx.de @ 2015-06-08 13:24 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      13416
Logged by:          Stefan Krüger
Email address:      stadtkind2@gmx.de
PostgreSQL version: 9.4.1
Operating system:   Solaris 11.2
Description:        

Hi,

starting with Postgres 9.3, there seems to be a bug with SysV Shared Memory
on Solaris. Postgres doesn't seem to use ISM anymore.

http://docs.oracle.com/cd/E23824_01/html/821-1450/chapter2-73.html

"A special kind of shared memory known as intimate shared memory (ISM) is
used by DBMS vendors to maximize performance.
When a shared memory segment is made into an ISM segment, the memory for the
segment is locked.
This feature enables a faster I/O path to be followed and improves memory
usage.
A number of kernel resources describing the segment are then shared between
all processes that attach to the segment in ISM mode"

I'm using Solaris 11.2 on Sparc (T5220) and the "official" solaris11/sparc
binaries from your site.

PostgreSQL 9.4.1:

"dynamic_shared_memory_type" was set to sysv (also tried 'posix' and 'mmap',
same results)

root@solaris:/ # ipcs -mA
IPC status from <running system> as of Wednesday, February 18, 2015 02:04:56
PM CET
T         ID      KEY        MODE        OWNER    GROUP  CREATOR   CGROUP
NATTCH      SEGSZ   CPID  LPID   ATIME    DTIME    CTIME  ISMATTCH        
PROJECT
Shared Memory:
m         49   0x7be9c1bd --rw------- postgres postgres postgres postgres   
  4       2316  1726  2809 13:22:02 16:55:41 13:22:02        4  
user.postgres
m         48   0x52e2c1   --rw------- postgres postgres postgres postgres   
  4         56  1726  2809 13:22:00 16:55:41 13:22:00        4  
user.postgres

root@solaris:/ # pmap -sx 1726
         Address     Kbytes        RSS       Anon     Locked Pgsz Mode  
Mapped File
...
00007FFEFF000000          8          8          -          8   8K rwxsR    [
ism shmid=0x32 ]
00007FFEFF800000          8          8          -          8   8K rwxsR    [
ism shmid=0x33 ]
FFFFFFFB50000000     282624     282624          -          -   4M rw-s-    [
anon ]
FFFFFFFB61400000   16773120    7290880          -          -    - rw-s-    [
anon ]
FFFFFFFF61000000     159744     159744          -          -   4M rw-s-    [
anon ]


Notice that there are 2 ISM's, but they're way too small. All the "fun"
happens in an anonymous memory region
which does not benefit from large(r) page support (anon memory seems to be
limited to 4MB pages,
whereas ISM can use up to 2 GB pages on certain SPARC CPUs).

PostgreSQL 9.2.10 is fine though:

root@solaris:/ # ipcs -mA
IPC status from <running system> as of Wednesday, February 18, 2015 02:08:49
PM CET
T         ID      KEY        MODE        OWNER    GROUP  CREATOR   CGROUP
NATTCH      SEGSZ   CPID  LPID   ATIME    DTIME    CTIME  ISMATTCH        
PROJECT
Shared Memory:
m         50   0x52e2c1   --rw------- postgres postgres postgres postgres   
  4 17605672960 18225 18232 14:08:42 14:08:43 14:08:40        4  
user.postgres

Notice the huge SEGSZ!

root@solaris:/ # pmap -sx 18225 | grep ism
         Address     Kbytes        RSS       Anon     Locked Pgsz Mode  
Mapped File
...
00007FFAE0000000   17039360   17039360          -   17039360 256M rwxsR    [
ism shmid=0x32 ]
00007FFEF0000000     151552     151552          -     151552   4M rwxsR    [
ism shmid=0x32 ]
00007FFEF9400000       2112       2112          -       2112  64K rwxsR    [
ism shmid=0x32 ]
00007FFEF9610000         16         16          -         16   8K rwxsR    [
ism shmid=0x32 ]

This looks good.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [PATCH] BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
@ 2017-10-03 23:11  Sean Chittenden <seanc@joyent.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Sean Chittenden @ 2017-10-03 23:11 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org; +Cc: stadtkind2@gmx.de, Sam Gwydir <sam.gwydir@joyent.com>; Sean Chittenden <sean@chittenden.org>; pgsql-bugs

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).

The only real question remaining is: do we want to change the default behavior, as detected by initdb(1), to use ISM on Illumos/Solaris derived systems?  Given the memory bloat experienced when using POSIX shared memory (potentially very significant for systems with larger shared_buffers), we think it's probably prudent to change the default from dynamic_shared_memory_type=posix to sysv.  Unfortunately I think it's not worth changing the default behavior of initdb(1) in the current supported branches, but it should be changed for 10.

Please let us know if there are any questions.  -sc


--
Sean Chittenden
seanc@joyent.com

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

ism.patch (application/octet-stream, 3.3K) download diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index 850eafddc3..0a8e1bb342 100644 --- a/src/backend/port/sysv_shmem.c +++ b/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(SHM_SHARE_MMU) +# define USE_ANONYMOUS_SHMEM #endif diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 27d134e17d..329ed88c8b 100644 --- a/src/bin/initdb/initdb.c +++ b/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 a/src/include/storage/dsm_impl.h b/src/include/storage/dsm_impl.h index ec05e22a6b..af0d32fcb5 100644 --- a/src/include/storage/dsm_impl.h +++ b/src/include/storage/dsm_impl.h @@ -23,20 +23,22 @@ /* * Determine which dynamic shared memory implementations will be supported * on this platform, and which one will be the default. + * Note for systems which feature SHM_SHARE_MMU (e.g. illumos and Solaris) + * we prefer System V Shared Memory instead of POSIX Shared Memory. */ #ifdef WIN32 -#define USE_DSM_WINDOWS -#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_WINDOWS -#else -#ifdef HAVE_SHM_OPEN -#define USE_DSM_POSIX -#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_POSIX -#endif -#define USE_DSM_SYSV -#ifndef DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE -#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV -#endif -#define USE_DSM_MMAP +# define USE_DSM_WINDOWS +# define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_WINDOWS +# else +# ifdef HAVE_SHM_OPEN +# define USE_DSM_POSIX +# define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_POSIX +# endif +# define USE_DSM_SYSV +# if !defined(DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE) || defined(SHM_SHARE_MMU) +# define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV +# endif +# define USE_DSM_MMAP #endif /* GUC. */
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: [PATCH] BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
@ 2017-10-04 17:47  Sean Chittenden <seanc@joyent.com>
  parent: Sean Chittenden <seanc@joyent.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Sean Chittenden @ 2017-10-04 17:47 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org; +Cc: stadtkind2@gmx.de, Sam Gwydir <sam.gwydir@joyent.com>; Sean Chittenden <sean@chittenden.org>; pgsql-bugs

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).

The only real question remaining is: do we want to change the default behavior, as detected by initdb(1), to use ISM on Illumos/Solaris derived systems?  Given the memory bloat experienced when using POSIX shared memory (potentially very significant for systems with larger shared_buffers), we think it's probably prudent to change the default from dynamic_shared_memory_type=posix to sysv.  Unfortunately I think it's not worth changing the default behavior of initdb(1) in the current supported branches, but it should be changed for 10.

Please let us know if there are any questions.  -sc


--
Sean Chittenden
seanc@joyent.com

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Re: [PATCH] BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
@ 2017-10-04 17:56  Andres Freund <andres@anarazel.de>
  parent: Sean Chittenden <seanc@joyent.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Andres Freund @ 2017-10-04 17:56 UTC (permalink / raw)
  To: Sean Chittenden <seanc@joyent.com>; +Cc: pgsql-hackers@postgresql.org, stadtkind2@gmx.de, Sam Gwydir <sam.gwydir@joyent.com>; Sean Chittenden <sean@chittenden.org>; pgsql-bugs

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-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Re: [PATCH] BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore
@ 2017-10-05 21:34  Sean Chittenden <seanc@joyent.com>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 5+ messages in thread

From: Sean Chittenden @ 2017-10-05 21:34 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, stadtkind2@gmx.de, Sam Gwydir <sam.gwydir@joyent.com>; Sean Chittenden <sean@chittenden.org>; pgsql-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-bugs

Attachments:

ism2.patch (application/octet-stream, 6.2K) download diff --git c/src/backend/port/sysv_shmem.c w/src/backend/port/sysv_shmem.c index 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.c index 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.c index 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.sample index 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.c index 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.h index 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);
^ permalink raw reply [nested|flat] 5+ messages in thread


end of thread, other threads:[~2017-10-05 21:34 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-06-08 13:24 BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore stadtkind2@gmx.de
2017-10-03 23:11 Re: [PATCH] BUG #13416: Postgres >= 9.3 doesn't use optimized shared memory on Solaris anymore Sean Chittenden <seanc@joyent.com>
2017-10-04 17:47 ` Sean Chittenden <seanc@joyent.com>
2017-10-04 17:56   ` Andres Freund <andres@anarazel.de>
2017-10-05 21:34     ` Sean Chittenden <seanc@joyent.com>

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