Fix confusion between "size" and "AnonymousShmemSize".

Noted by Andres Freund.  Also improve a couple of comments.
This commit is contained in:
Tom Lane 2012-06-29 15:12:10 -04:00
parent 7a5c9ca93a
commit 42e2ce6ae3
1 changed files with 7 additions and 5 deletions

View File

@ -408,13 +408,14 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
long pagesize = sysconf(_SC_PAGE_SIZE); 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. * 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 * But just in case it isn't, we do it this way instead of using
* TYPEALIGN(). * TYPEALIGN().
*/ */
AnonymousShmemSize = size; if (pagesize > 0 && size % pagesize != 0)
if (size % pagesize != 0) size += pagesize - (size % pagesize);
AnonymousShmemSize += pagesize - (size % pagesize);
/* /*
* We assume that no one will attempt to run PostgreSQL 9.3 or later * 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, " "%lu bytes), reduce PostgreSQL's shared memory usage, "
"perhaps by reducing shared_buffers or " "perhaps by reducing shared_buffers or "
"max_connections.", "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); allocsize = sizeof(PGShmemHeader);
} }
#endif #endif