@@ -408,13 +408,14 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
408408long pagesize = sysconf (_SC_PAGE_SIZE );
409409
410410/*
411+ * Ensure request size is a multiple of pagesize.
412+ *
411413 * pagesize will, for practical purposes, always be a power of two.
412414 * But just in case it isn't, we do it this way instead of using
413415 * TYPEALIGN().
414416 */
415- AnonymousShmemSize = size ;
416- if (size %pagesize != 0 )
417- AnonymousShmemSize += pagesize - (size %pagesize );
417+ if (pagesize > 0 && size %pagesize != 0 )
418+ size += pagesize - (size %pagesize );
418419
419420/*
420421 * We assume that no one will attempt to run PostgreSQL 9.3 or later
@@ -435,9 +436,10 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
435436"%lu bytes), reduce PostgreSQL's shared memory usage, "
436437"perhaps by reducing shared_buffers or "
437438"max_connections." ,
438- (unsigned long )AnonymousShmemSize ) :0 ));
439+ (unsigned long )size ) :0 ));
440+ AnonymousShmemSize = size ;
439441
440- /* Now wecan allocate a minimal SHM block. */
442+ /* Now weneed only allocate a minimal-sized SysV shmem block. */
441443allocsize = sizeof (PGShmemHeader );
442444}
443445#endif