From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@postgresql.org
Subject: Re: OK, so culicidae is *still* broken
Date: Sat, 15 Apr 2017 16:48:05 -0400
Message-ID: <1842.1492289285@sss.pgh.pa.us> (raw)
In-Reply-To: <32559.1492278226@sss.pgh.pa.us>
References: <7036.1492231361@sss.pgh.pa.us>
<18D5D7AF-C587-4B63-B2CF-13590849A624@anarazel.de>
<32559.1492278226@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
I wrote:
> I think what may be the most effective way to proceed is to provide
> a way to force the shmem segment to be mapped at a chosen address.
> It looks like, at least on x86_64 Linux, mapping shmem at
> 0x00007E0000000000 would work reliably.
> Since we only care about this for testing purposes, I don't think
> it has to be done in any very clean or even documented way.
> I'm inclined to propose that we put something into sysv_shmem.c
> that will check for an environment variable named, say, PG_SHMEM_ADDR,
> and if it's set will use the value as the address in the initial
> shmat() call. For a bit of extra safety we could do that only in
> EXEC_BACKEND builds.
Concretely, I propose the attached patch. We'd have to put it into
all supported branches, since culicidae is showing intermittent
"could not reattach to shared memory" failures in all the branches.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:allow-control-of-shmem-attach-address.patch (text/x-diff, 1.8K) downloaddiff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.cindex 77cd8f3..15ae672 100644
*** a/src/backend/port/sysv_shmem.c
--- b/src/backend/port/sysv_shmem.c
*************** static void *
*** 102,109 ****
--- 102,129 ----
InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
{
IpcMemoryId shmid;
+ void *requestedAddress = NULL;
void *memAddress;
+ /*+ * Normally we just pass requestedAddress = NULL to shmat(), allowing the+ * system to choose where the segment gets mapped. But in an EXEC_BACKEND+ * build, it's possible for whatever is chosen in the postmaster to not+ * work for backends, due to variations in address space layout. As a+ * rather klugy workaround, allow the user to specify the address to use+ * via setting the environment variable PG_SHMEM_ADDR. (If this were of+ * interest for anything except debugging, we'd probably create a cleaner+ * and better-documented way to set it, such as a GUC.)+ */+ #ifdef EXEC_BACKEND+ {+ char *pg_shmem_addr = getenv("PG_SHMEM_ADDR");+ + if (pg_shmem_addr)+ requestedAddress = (void *) strtoul(pg_shmem_addr, NULL, 0);+ }+ #endif+
shmid = shmget(memKey, size, IPC_CREAT | IPC_EXCL | IPCProtection);
if (shmid < 0)
*************** InternalIpcMemoryCreate(IpcMemoryKey mem
*** 203,209 ****
on_shmem_exit(IpcMemoryDelete, Int32GetDatum(shmid));
/* OK, should be able to attach to the segment */
! memAddress = shmat(shmid, NULL, PG_SHMAT_FLAGS);
if (memAddress == (void *) -1)
elog(FATAL, "shmat(id=%d) failed: %m", shmid);
--- 223,229 ----
on_shmem_exit(IpcMemoryDelete, Int32GetDatum(shmid));
/* OK, should be able to attach to the segment */
! memAddress = shmat(shmid, requestedAddress, PG_SHMAT_FLAGS);
if (memAddress == (void *) -1)
elog(FATAL, "shmat(id=%d) failed: %m", shmid);
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de
Subject: Re: OK, so culicidae is *still* broken
In-Reply-To: <1842.1492289285@sss.pgh.pa.us>
* 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