Skip to content
Snippets Groups Projects
Commit 39715af2 authored by Robert Haas's avatar Robert Haas
Browse files

Fix broken mmap failure-detection code, and improve error message.

Per an observation by Thom Brown that my previous commit made an
overly large shmem allocation crash the server, on Linux.
parent b0fc0df9
No related branches found
No related tags found
No related merge requests found
...@@ -419,10 +419,17 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -419,10 +419,17 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
*/ */
AnonymousShmem = mmap(NULL, size, PROT_READ|PROT_WRITE, PG_MMAP_FLAGS, AnonymousShmem = mmap(NULL, size, PROT_READ|PROT_WRITE, PG_MMAP_FLAGS,
-1, 0); -1, 0);
if (AnonymousShmem == NULL) if (AnonymousShmem == MAP_FAILED)
ereport(FATAL, ereport(FATAL,
(errmsg("could not map %lu bytes of anonymous shared memory: %m", (errmsg("could not map anonymous shared memory: %m"),
(unsigned long) AnonymousShmemSize))); (errno == ENOMEM) ?
errhint("This error usually means that PostgreSQL's request "
"for a shared memory segment exceeded available memory "
"or swap space. To reduce the request size (currently "
"%lu bytes), reduce PostgreSQL's shared memory usage, "
"perhaps by reducing shared_buffers or "
"max_connections.",
(unsigned long) AnonymousShmemSize) : 0));
/* Now we can allocate a minimal SHM block. */ /* Now we can allocate a minimal SHM block. */
allocsize = sizeof(PGShmemHeader); allocsize = sizeof(PGShmemHeader);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment