/* Align descriptors to a cacheline boundary. */
BufferDescriptors = (BufferDescPadded *)
- CACHELINEALIGN(
- ShmemInitStruct("Buffer Descriptors",
- NBuffers * sizeof(BufferDescPadded)
- + PG_CACHE_LINE_SIZE,
- &foundDescs));
+ ShmemInitStruct("Buffer Descriptors",
+ NBuffers * sizeof(BufferDescPadded),
+ &foundDescs);
BufferBlocks = (char *)
ShmemInitStruct("Buffer Blocks",
/* Align lwlocks to cacheline boundary */
BufferIOLWLockArray = (LWLockMinimallyPadded *)
- CACHELINEALIGN(ShmemInitStruct("Buffer IO Locks",
- NBuffers * (Size) sizeof(LWLockMinimallyPadded)
- + PG_CACHE_LINE_SIZE,
- &foundIOLocks));
+ ShmemInitStruct("Buffer IO Locks",
+ NBuffers * (Size) sizeof(LWLockMinimallyPadded),
+ &foundIOLocks);
BufferIOLWLockTranche.name = "buffer_io";
BufferIOLWLockTranche.array_base = BufferIOLWLockArray;
InitShmemAllocation(void)
{
PGShmemHeader *shmhdr = ShmemSegHdr;
+ char *aligned;
Assert(shmhdr != NULL);
shmhdr->freeoffset += MAXALIGN(sizeof(slock_t));
Assert(shmhdr->freeoffset <= shmhdr->totalsize);
+ /* Make sure the first allocation begins on a cache line boundary. */
+ aligned = (char *)
+ (CACHELINEALIGN((((char *) shmhdr) + shmhdr->freeoffset)));
+ shmhdr->freeoffset = aligned - (char *) shmhdr;
+
SpinLockInit(ShmemLock);
/* ShmemIndex can't be set up yet (need LWLocks first) */
newStart = ShmemSegHdr->freeoffset;
- /* extra alignment for large requests, since they are probably buffers */
- if (size >= BLCKSZ)
- newStart = BUFFERALIGN(newStart);
-
newFree = newStart + size;
if (newFree <= ShmemSegHdr->totalsize)
{
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
+ Assert(newSpace == (void *) CACHELINEALIGN(newSpace));
+
return newSpace;
}
LWLockRelease(ShmemIndexLock);
Assert(ShmemAddrIsValid(structPtr));
+
+ Assert(structPtr == (void *) CACHELINEALIGN(structPtr));
+
return structPtr;
}