]> granicus.if.org Git - postgresql/commitdiff
Fix confusion between "size" and "AnonymousShmemSize".
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 Jun 2012 19:12:10 +0000 (15:12 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 Jun 2012 19:12:10 +0000 (15:12 -0400)
Noted by Andres Freund.  Also improve a couple of comments.

src/backend/port/sysv_shmem.c

index 8f1da7a7ef4310225972ad53c5e29debd0020965..e040400bb15b124c93be8fcce12e9bed264c61a4 100644 (file)
@@ -408,13 +408,14 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
                long    pagesize = sysconf(_SC_PAGE_SIZE);
 
                /*
+                * Ensure request size is a multiple of pagesize.
+                *
                 * pagesize will, for practical purposes, always be a power of two.
                 * But just in case it isn't, we do it this way instead of using
                 * TYPEALIGN().
                 */
-               AnonymousShmemSize = size;
-               if (size % pagesize != 0)
-                       AnonymousShmemSize += pagesize - (size % pagesize);
+               if (pagesize > 0 && size % pagesize != 0)
+                       size += pagesize - (size % pagesize);
 
                /*
                 * 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)
                                           "%lu bytes), reduce PostgreSQL's shared memory usage, "
                                           "perhaps by reducing shared_buffers or "
                                           "max_connections.",
-                                       (unsigned long) AnonymousShmemSize) : 0));
+                                          (unsigned long) size) : 0));
+               AnonymousShmemSize = size;
 
-               /* Now we can allocate a minimal SHM block. */
+               /* Now we need only allocate a minimal-sized SysV shmem block. */
                allocsize = sizeof(PGShmemHeader);
        }
 #endif