Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f84280

Browse files
committed
Fix assorted defects in09adc9a.
That commit increased all shared memory allocations to the next highermultiple of PG_CACHE_LINE_SIZE, but it didn't ensure that allocationstarted on a cache line boundary. It also failed to remove a coupleother pieces of now-useless code.BUFFERALIGN() is perhaps obsolete at this point, and likely should beremoved at some point, too, but that seems like it can be left to afuture cleanup.Mistakes all pointed out by Andres Freund. The patch is mine, witha few extra assertions which I adopted from his version of this fix.
1 parent7cb1db1 commit9f84280

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

‎src/backend/storage/buffer/buf_init.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,19 @@ InitBufferPool(void)
7676

7777
/* Align descriptors to a cacheline boundary. */
7878
BufferDescriptors= (BufferDescPadded*)
79-
CACHELINEALIGN(
80-
ShmemInitStruct("Buffer Descriptors",
81-
NBuffers*sizeof(BufferDescPadded)
82-
+PG_CACHE_LINE_SIZE,
83-
&foundDescs));
79+
ShmemInitStruct("Buffer Descriptors",
80+
NBuffers*sizeof(BufferDescPadded),
81+
&foundDescs);
8482

8583
BufferBlocks= (char*)
8684
ShmemInitStruct("Buffer Blocks",
8785
NBuffers* (Size)BLCKSZ,&foundBufs);
8886

8987
/* Align lwlocks to cacheline boundary */
9088
BufferIOLWLockArray= (LWLockMinimallyPadded*)
91-
CACHELINEALIGN(ShmemInitStruct("Buffer IO Locks",
92-
NBuffers* (Size)sizeof(LWLockMinimallyPadded)
93-
+PG_CACHE_LINE_SIZE,
94-
&foundIOLocks));
89+
ShmemInitStruct("Buffer IO Locks",
90+
NBuffers* (Size)sizeof(LWLockMinimallyPadded),
91+
&foundIOLocks);
9592

9693
BufferIOLWLockTranche.name="buffer_io";
9794
BufferIOLWLockTranche.array_base=BufferIOLWLockArray;

‎src/backend/storage/ipc/shmem.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ void
112112
InitShmemAllocation(void)
113113
{
114114
PGShmemHeader*shmhdr=ShmemSegHdr;
115+
char*aligned;
115116

116117
Assert(shmhdr!=NULL);
117118

@@ -139,6 +140,11 @@ InitShmemAllocation(void)
139140
shmhdr->freeoffset+=MAXALIGN(sizeof(slock_t));
140141
Assert(shmhdr->freeoffset <=shmhdr->totalsize);
141142

143+
/* Make sure the first allocation begins on a cache line boundary. */
144+
aligned= (char*)
145+
(CACHELINEALIGN((((char*)shmhdr)+shmhdr->freeoffset)));
146+
shmhdr->freeoffset=aligned- (char*)shmhdr;
147+
142148
SpinLockInit(ShmemLock);
143149

144150
/* ShmemIndex can't be set up yet (need LWLocks first) */
@@ -189,10 +195,6 @@ ShmemAlloc(Size size)
189195

190196
newStart=ShmemSegHdr->freeoffset;
191197

192-
/* extra alignment for large requests, since they are probably buffers */
193-
if (size >=BLCKSZ)
194-
newStart=BUFFERALIGN(newStart);
195-
196198
newFree=newStart+size;
197199
if (newFree <=ShmemSegHdr->totalsize)
198200
{
@@ -209,6 +211,8 @@ ShmemAlloc(Size size)
209211
(errcode(ERRCODE_OUT_OF_MEMORY),
210212
errmsg("out of shared memory")));
211213

214+
Assert(newSpace== (void*)CACHELINEALIGN(newSpace));
215+
212216
returnnewSpace;
213217
}
214218

@@ -425,6 +429,9 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
425429
LWLockRelease(ShmemIndexLock);
426430

427431
Assert(ShmemAddrIsValid(structPtr));
432+
433+
Assert(structPtr== (void*)CACHELINEALIGN(structPtr));
434+
428435
returnstructPtr;
429436
}
430437

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp