1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-04 20:11:56 +03:00

Redesign the patch for allocation of shmem space and LWLocks for add-on

modules; the first try was not usable in EXEC_BACKEND builds (e.g.,
Windows).  Instead, just provide some entry points to increase the
allocation requests during postmaster start, and provide a dedicated
LWLock that can be used to synchronize allocation operations performed
by backends.  Per discussion with Marc Munro.
This commit is contained in:
Tom Lane
2006-10-15 22:04:08 +00:00
parent a3dff39c53
commit e0dece127d
6 changed files with 73 additions and 259 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.88 2006/10/04 00:29:57 momjian Exp $
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.89 2006/10/15 22:04:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -32,6 +32,30 @@
#include "storage/spin.h"
static Size total_addin_request = 0;
static bool addin_request_allowed = true;
/*
* RequestAddinShmemSpace
* Request that extra shmem space be allocated for use by
* a loadable module.
*
* This is only useful if called from the _PG_init hook of a library that
* is loaded into the postmaster via shared_preload_libraries. Once
* shared memory has been allocated, calls will be ignored. (We could
* raise an error, but it seems better to make it a no-op, so that
* libraries containing such calls can be reloaded if needed.)
*/
void
RequestAddinShmemSpace(Size size)
{
if (IsUnderPostmaster || !addin_request_allowed)
return; /* too late */
total_addin_request = add_size(total_addin_request, size);
}
/*
* CreateSharedMemoryAndSemaphores
* Creates and initializes shared memory and semaphores.
@@ -57,7 +81,6 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
{
PGShmemHeader *seghdr;
Size size;
Size size_b4addins;
int numSemas;
/*
@@ -91,16 +114,11 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
size = add_size(size, ShmemBackendArraySize());
#endif
/* might as well round it off to a multiple of a typical page size */
size = add_size(size, 8192 - (size % 8192));
/* freeze the addin request size and include it */
addin_request_allowed = false;
size = add_size(size, total_addin_request);
/*
* The shared memory for add-ins is treated as a separate segment, but
* in reality it is not.
*/
size_b4addins = size;
size = add_size(size, AddinShmemSize());
/* round it off again */
/* might as well round it off to a multiple of a typical page size */
size = add_size(size, 8192 - (size % 8192));
elog(DEBUG3, "invoking IpcMemoryCreate(size=%lu)",
@@ -111,16 +129,6 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
*/
seghdr = PGSharedMemoryCreate(size, makePrivate, port);
/*
* Modify hdr to show segment size before add-ins
*/
seghdr->totalsize = size_b4addins;
/*
* Set up segment header sections in each Addin context
*/
InitAddinContexts((void *) ((char *) seghdr + size_b4addins));
InitShmemAccess(seghdr);
/*