|
57 | 57 | #include "lib/ilist.h"
|
58 | 58 |
|
59 | 59 |
|
| 60 | +#define Slab_BLOCKHDRSZ MAXALIGN(sizeof(SlabBlock)) |
| 61 | + |
60 | 62 | /*
|
61 | 63 | * SlabContext is a specialized implementation of MemoryContext.
|
62 | 64 | */
|
@@ -117,10 +119,10 @@ typedef struct SlabChunk
|
117 | 119 | #define SlabChunkGetPointer(chk) \
|
118 | 120 | ((void *)(((char *)(chk)) + sizeof(SlabChunk)))
|
119 | 121 | #define SlabBlockGetChunk(slab, block, idx) \
|
120 |
| - ((SlabChunk *) ((char *) (block) + sizeof(SlabBlock) \ |
| 122 | + ((SlabChunk *) ((char *) (block) + Slab_BLOCKHDRSZ \ |
121 | 123 | + (idx * slab->fullChunkSize)))
|
122 | 124 | #define SlabBlockStart(block) \
|
123 |
| - ((char *) block + sizeof(SlabBlock)) |
| 125 | + ((char *) block + Slab_BLOCKHDRSZ) |
124 | 126 | #define SlabChunkIndex(slab, block, chunk) \
|
125 | 127 | (((char *) chunk - SlabBlockStart(block)) / slab->fullChunkSize)
|
126 | 128 |
|
@@ -185,7 +187,7 @@ static const MemoryContextMethods SlabMethods = {
|
185 | 187 | * chunkSize: allocation chunk size
|
186 | 188 | *
|
187 | 189 | * The chunkSize may not exceed:
|
188 |
| - * MAXALIGN_DOWN(SIZE_MAX) - MAXALIGN(sizeof(SlabBlock)) - SLAB_CHUNKHDRSZ |
| 190 | + * MAXALIGN_DOWN(SIZE_MAX) - MAXALIGN(Slab_BLOCKHDRSZ) - sizeof(SlabChunk) |
189 | 191 | */
|
190 | 192 | MemoryContext
|
191 | 193 | SlabContextCreate(MemoryContext parent,
|
@@ -215,12 +217,12 @@ SlabContextCreate(MemoryContext parent,
|
215 | 217 | fullChunkSize = sizeof(SlabChunk) + MAXALIGN(chunkSize);
|
216 | 218 |
|
217 | 219 | /* Make sure the block can store at least one chunk. */
|
218 |
| - if (blockSize < fullChunkSize + sizeof(SlabBlock)) |
| 220 | + if (blockSize < fullChunkSize + Slab_BLOCKHDRSZ) |
219 | 221 | elog(ERROR, "block size %zu for slab is too small for %zu chunks",
|
220 | 222 | blockSize, chunkSize);
|
221 | 223 |
|
222 | 224 | /* Compute maximum number of chunks per block */
|
223 |
| - chunksPerBlock = (blockSize - sizeof(SlabBlock)) / fullChunkSize; |
| 225 | + chunksPerBlock = (blockSize - Slab_BLOCKHDRSZ) / fullChunkSize; |
224 | 226 |
|
225 | 227 | /* The freelist starts with 0, ends with chunksPerBlock. */
|
226 | 228 | freelistSize = sizeof(dlist_head) * (chunksPerBlock + 1);
|
@@ -781,7 +783,7 @@ SlabCheck(MemoryContext context)
|
781 | 783 |
|
782 | 784 | /* there might be sentinel (thanks to alignment) */
|
783 | 785 | if (slab->chunkSize < (slab->fullChunkSize - sizeof(SlabChunk)))
|
784 |
| - if (!sentinel_ok(chunk, slab->chunkSize)) |
| 786 | + if (!sentinel_ok(chunk, sizeof(SlabChunk) + slab->chunkSize)) |
785 | 787 | elog(WARNING, "problem in slab %s: detected write past chunk end in block %p, chunk %p",
|
786 | 788 | name, block, chunk);
|
787 | 789 | }
|
|
0 commit comments