@@ -408,13 +408,14 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
408
408
long pagesize = sysconf (_SC_PAGE_SIZE );
409
409
410
410
/*
411
+ * Ensure request size is a multiple of pagesize.
412
+ *
411
413
* pagesize will, for practical purposes, always be a power of two.
412
414
* But just in case it isn't, we do it this way instead of using
413
415
* TYPEALIGN().
414
416
*/
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 );
418
419
419
420
/*
420
421
* 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)
435
436
"%lu bytes), reduce PostgreSQL's shared memory usage, "
436
437
"perhaps by reducing shared_buffers or "
437
438
"max_connections." ,
438
- (unsigned long )AnonymousShmemSize ) :0 ));
439
+ (unsigned long )size ) :0 ));
440
+ AnonymousShmemSize = size ;
439
441
440
- /* Now wecan allocate a minimal SHM block. */
442
+ /* Now weneed only allocate a minimal-sized SysV shmem block. */
441
443
allocsize = sizeof (PGShmemHeader );
442
444
}
443
445
#endif