/*
* CalculateShmemSize
- * Calculates the amount of shared memory and number of semaphores needed.
- *
- * If num_semaphores is not NULL, it will be set to the number of semaphores
- * required.
+ * Calculates the amount of shared memory needed.
*/
Size
-CalculateShmemSize(int *num_semaphores)
+CalculateShmemSize(void)
{
Size size;
- int numSemas;
-
- /* Compute number of semaphores we'll need */
- numSemas = ProcGlobalSemas();
-
- /* Return the number of semaphores if requested by the caller */
- if (num_semaphores)
- *num_semaphores = numSemas;
/*
* Size of the Postgres shared-memory block is estimated via moderately-
* during the actual allocation phase.
*/
size = 100000;
- size = add_size(size, PGSemaphoreShmemSize(numSemas));
size = add_size(size, hash_estimate_size(SHMEM_INDEX_SIZE,
sizeof(ShmemIndexEnt)));
size = add_size(size, dsm_estimate_size());
PGShmemHeader *shim;
PGShmemHeader *seghdr;
Size size;
- int numSemas;
Assert(!IsUnderPostmaster);
/* Compute the size of the shared-memory block */
- size = CalculateShmemSize(&numSemas);
+ size = CalculateShmemSize();
elog(DEBUG3, "invoking IpcMemoryCreate(size=%zu)", size);
/*
InitShmemAccess(seghdr);
- /*
- * Create semaphores. (This is done here for historical reasons. We used
- * to support emulating spinlocks with semaphores, which required
- * initializing semaphores early.)
- */
- PGReserveSemaphores(numSemas);
-
/*
* Set up shared memory allocation mechanism
*/
Size size_b;
Size size_mb;
Size hp_size;
- int num_semas;
/*
* Calculate the shared memory size and round up to the nearest megabyte.
*/
- size_b = CalculateShmemSize(&num_semas);
+ size_b = CalculateShmemSize();
size_mb = add_size(size_b, (1024 * 1024) - 1) / (1024 * 1024);
sprintf(buf, "%zu", size_mb);
SetConfigOption("shared_memory_size", buf,
PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT);
}
- sprintf(buf, "%d", num_semas);
+ sprintf(buf, "%d", ProcGlobalSemas());
SetConfigOption("num_os_semaphores", buf, PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT);
}
size = add_size(size, sizeof(PROC_HDR));
size = add_size(size, sizeof(slock_t));
+ size = add_size(size, PGSemaphoreShmemSize(ProcGlobalSemas()));
size = add_size(size, PGProcShmemSize());
size = add_size(size, FastPathLockShmemSize());
/* For asserts checking we did not overflow. */
fpEndPtr = fpPtr + requestSize;
+ /* Reserve space for semaphores. */
+ PGReserveSemaphores(ProcGlobalSemas());
+
for (i = 0; i < TotalProcs; i++)
{
PGPROC *proc = &procs[i];
extern void InitShmemAllocation(void);
extern void *ShmemAlloc(Size size);
extern void *ShmemAllocNoError(Size size);
-extern void *ShmemAllocUnlocked(Size size);
extern bool ShmemAddrIsValid(const void *addr);
extern void InitShmemIndex(void);
extern HTAB *ShmemInitHash(const char *name, int64 init_size, int64 max_size,